Skip to content

Commit

Permalink
Added buttons for screenshot and outline
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijuice56 committed Feb 1, 2024
1 parent e361c8e commit b43e5fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
7 changes: 4 additions & 3 deletions gui/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

class Button(pyglet.gui.WidgetBase):
BACKGROUND_COLOR = (0, 0, 0, 140)
HOVER_COLOR = (64, 64, 64, 140)
HOVER_COLOR = (48, 48, 48, 140)

def __init__(self, bounding_box, text, index, window, batch, bg_batch, text_width=21):
def __init__(self, bounding_box, text, index, window, batch, bg_batch):
pyglet.gui.WidgetBase.__init__(self, *bounding_box)
self.batch = batch
self.window = window
Expand All @@ -22,7 +22,7 @@ def __init__(self, bounding_box, text, index, window, batch, bg_batch, text_widt
text=self.text, font_name="Consolas", multiline=True,
font_size=16, x=self.x, y=self.y + 28, width=self.width,
anchor_x="left", anchor_y="top", batch=self.batch)
self.visible = False
self.visible = True
self.pressed = False
self.hovered = False

Expand Down Expand Up @@ -72,6 +72,7 @@ def __init__(self, bounding_box, title, options, window, batch, bg_batch, text_w
for i, option in enumerate(self.options):
button = Button([self.x, self.y - 32 * (i + 1), self.width, 32], self.options[i], i, self.window, self.batch, bg_batch)
self.buttons.append(button)
button.hide()

self.title = pyglet.text.Label(
text=title, font_name="Consolas", multiline=True,
Expand Down
29 changes: 20 additions & 9 deletions gui/user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def __init__(self, protein, window, pdb_renderer, embedding_renderer):
self.res_doc = pyglet.text.document.FormattedDocument()
self.res_layout = None

self.color_mode = DropDown(bounding_box=[16, -80, 280, 32], title="Coloring Mode",
self.color_mode = DropDown(bounding_box=[16, -80 - 48, 280, 32], title="Coloring Mode",
options=["Functional Similarity", "Amino Acid Order", "Atom Type", "Residue Type"],
window=window, batch=self.batch, bg_batch=self.bg_batch)
self.color_palette = DropDown(bounding_box=[312, -80, 280, 32], title="Color Palette",
options=["Rainbow", "Monocolor", "Nature", "Penguin", "Grape", "Lemon", "Mulberry"],
self.color_palette = DropDown(bounding_box=[312, -80 - 48, 280, 32], title="Color Palette",
options=["Rainbow", "Monocolor", "Nature", "Penguin", "Grape", "Lemon",
"Mulberry"],
window=window, batch=self.batch, bg_batch=self.bg_batch)
go_titles = []
for i in range(len(self.protein.go_ids)):
Expand All @@ -49,21 +50,23 @@ def __init__(self, protein, window, pdb_renderer, embedding_renderer):
go_title = go_title[0: 32]
go_titles.append(go_title)

self.go_annotation = DropDown(bounding_box=[608, -80, 416, 32], title="GO Annotation",
self.go_annotation = DropDown(bounding_box=[608, -80 - 48, 416, 32], title="GO Annotation",
options=go_titles, text_width=32,
window=window, batch=self.batch, bg_batch=self.bg_batch)

self.screenshot = Button(bounding_box=[16, -48, 180, 32], text="Save Image",
window=window, batch=self.batch, bg_batch=self.batch, index=0)

self.outline = Button(bounding_box=[16 + 180 + 16, -48, 180, 32], text="Toggle Outline",
window=window, batch=self.batch, bg_batch=self.batch, index=0)

self.update_residue_label()

def on_key_press(self, symbol, _modifiers):
if symbol == pyglet.window.key.UP:
self.pdb_renderer.set_point_size(self.pdb_renderer.point_size + 1)
if symbol == pyglet.window.key.DOWN:
self.pdb_renderer.set_point_size(self.pdb_renderer.point_size - 1)
if symbol == pyglet.window.key.O:
self.pdb_renderer.outline = not self.pdb_renderer.outline
if symbol == pyglet.window.key.S:
self.pdb_renderer.transparent_save_image = True

def on_mouse_scroll(self, x, y, _scroll_x, _scroll_y):
self.on_mouse_motion(x, y, 0, 0)
Expand Down Expand Up @@ -179,10 +182,18 @@ def draw(self):
self.pdb_renderer.update_colors()
self.embedding_renderer.update_colors()

if self.screenshot.pressed:
self.screenshot.pressed = False
self.pdb_renderer.transparent_save_image = True
self.pdb_renderer.outline = not self.pdb_renderer.outline
if self.outline.pressed:
self.outline.pressed = False
self.pdb_renderer.outline = not self.pdb_renderer.outline

go_doc = pyglet.text.Label(
text=f"{self.protein.go_ids[self.go_idx]}: {self.protein.go_names[self.go_idx]}\n{'%.2f' % (self.protein.scores[self.go_idx] * 100)}% confidence",
font_name="Consolas", multiline=True,
font_size=16, x=1040, y=-16, width=self.window.width,
font_size=16, x=1040, y=-16 - 48, width=self.window.width,
anchor_x="left", anchor_y="top")
go_doc.draw()

Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b43e5fd

Please sign in to comment.