Skip to content

Commit

Permalink
Added screenshot feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijuice56 committed Jan 31, 2024
1 parent 38b1ea8 commit 00896c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions gui/user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def on_key_press(self, symbol, _modifiers):
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
1 change: 1 addition & 0 deletions protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def get_color_from_palette(palette):

luminance = residue.go_map[self.current_go_id]
luminance *= luminance
luminance = min(1.0, luminance + 0.1)

residue.outline_color = [int(luminance * self.MAX_OUTLINE_BRIGHTNESS)] * 3

Expand Down
21 changes: 15 additions & 6 deletions renderers/pdb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class PDBRenderer:
GRID_LINE_COUNT = 16
BACKGROUND_COLOR = (0, 0, 0, 0)

SKY_COLOR1 = (114, 136, 142)
SKY_COLOR2 = (149, 169, 176)
GROUND_COLOR1 = (40, 50, 55)
GROUND_COLOR2 = (51, 64, 69)
SKY_COLOR1 = (64, 64, 64)
SKY_COLOR2 = (92, 92, 92)
GROUND_COLOR1 = (48, 48, 48)
GROUND_COLOR2 = (59, 59, 59)
SKY_DISTANCE = 1000.0
HORIZON_SIZE1 = 0.3
HORIZON_SIZE2 = 0.1
Expand All @@ -108,6 +108,8 @@ def __init__(self, protein, window, bounding_box=None, point_size=8, outline=Tru
"""
self.window = window
self.protein = protein
self.save_image = False
self.transparent_save_image = False

self.point_size = 0
self.set_point_size(point_size)
Expand Down Expand Up @@ -241,14 +243,16 @@ def draw(self):
self.SKY_COLOR2 * 2 + self.SKY_COLOR1 * 2 + self.SKY_COLOR1 * 4
)
)
quad_list.draw(GL_QUADS)
if not self.transparent_save_image:
quad_list.draw(GL_QUADS)

glLoadIdentity()
glMatrixMode(GL_PROJECTION)
gluPerspective(self.FOV, self.window.width / float(self.window.height), self.Z_NEAR, self.Z_FAR)
self.camera.draw()

self.grid_list.draw(GL_LINES)
if not self.transparent_save_image:
self.grid_list.draw(GL_LINES)

glEnable(GL_POINT_SMOOTH)
if self.outline:
Expand All @@ -260,6 +264,11 @@ def draw(self):
glEnable(GL_DEPTH_TEST)
self.atom_vertices.draw(GL_POINTS)

if self.save_image or self.transparent_save_image:
pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')
self.save_image = False
self.transparent_save_image = False

# Clean up
glDisable(GL_SCISSOR_TEST)
glDisable(GL_LINE_SMOOTH)
Expand Down

0 comments on commit 00896c9

Please sign in to comment.