Skip to content

Commit

Permalink
[refactor] all the classes earlier in odemis.gui.comp.overlay.view.py…
Browse files Browse the repository at this point in the history
… have been split into individual python files.
  • Loading branch information
nandishjpatel committed Jan 19, 2024
1 parent 4f1f621 commit 2043951
Show file tree
Hide file tree
Showing 19 changed files with 2,039 additions and 1,710 deletions.
50 changes: 29 additions & 21 deletions src/odemis/gui/comp/miccanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from odemis.acq.stream import DataProjection
from odemis.gui import BLEND_SCREEN, BLEND_DEFAULT
from odemis.gui.comp.canvas import CAN_ZOOM, CAN_DRAG, CAN_FOCUS, CAN_MOVE_STAGE, BitmapCanvas
from odemis.gui.comp.overlay.view import HistoryOverlay, PointSelectOverlay, MarkingLineOverlay
from odemis.gui.util import wxlimit_invocation, ignore_dead, img, \
call_in_wx_main
from odemis.gui.util.img import format_rgba_darray, apply_flip
Expand All @@ -44,16 +43,25 @@
import wx.lib.newevent

import odemis.gui as gui
import odemis.gui.comp.canvas as canvas
from odemis.gui.comp.overlay.centered_line import CenteredLineOverlay
from odemis.gui.comp.overlay.cryo_feature import CryoFeatureOverlay
from odemis.gui.comp.overlay.dichotomy import DichotomyOverlay
from odemis.gui.comp.overlay.fastem import FastEMROAOverlay, FastEMROCOverlay, FastEMBackgroundOverlay
from odemis.gui.comp.overlay.focus import FocusOverlay
from odemis.gui.comp.overlay.gadget import GadgetOverlay
from odemis.gui.comp.overlay.history import HistoryOverlay
from odemis.gui.comp.overlay.marking_line import MarkingLineOverlay
from odemis.gui.comp.overlay.pixel_select import PixelSelectOverlay
from odemis.gui.comp.overlay.pixel_value import PixelValueOverlay
from odemis.gui.comp.overlay.play_icon import PlayIconOverlay
from odemis.gui.comp.overlay.point_select import PointSelectOverlay
from odemis.gui.comp.overlay.points import PointsOverlay
from odemis.gui.comp.overlay.polar import PolarOverlay
from odemis.gui.comp.overlay.repetition_select import RepetitionSelectOverlay
from odemis.gui.comp.overlay.spectrum_line_select import SpectrumLineSelectOverlay
from odemis.gui.comp.overlay.spot_mode import SpotModeOverlay
import odemis.gui.comp.canvas as canvas
import odemis.gui.comp.overlay.view as view_overlay
from odemis.gui.comp.overlay.spot_mode import SpotModeViewOverlay, SpotModeWorldOverlay
from odemis.gui.comp.overlay.text_view import TextViewOverlay
import odemis.gui.model as guimodel
import wx.lib.wxcairo as wxcairo

Expand Down Expand Up @@ -125,7 +133,7 @@ def __init__(self, *args, **kwargs):
self.cryofeature_overlay = None

# play/pause icon
self.play_overlay = view_overlay.PlayIconOverlay(self)
self.play_overlay = PlayIconOverlay(self)
self.add_view_overlay(self.play_overlay)

# Unused at the moment
Expand Down Expand Up @@ -290,7 +298,7 @@ def _on_cross_hair_show(self, activated):
""" Activate the cross hair view overlay """
if activated:
if self._crosshair_ol is None:
self._crosshair_ol = view_overlay.CenteredLineOverlay(self)
self._crosshair_ol = CenteredLineOverlay(self)
self.add_view_overlay(self._crosshair_ol)
elif self._crosshair_ol:
self.remove_view_overlay(self._crosshair_ol)
Expand All @@ -306,7 +314,7 @@ def _on_pixel_value_show(self, activated):
if activated:
if self._pixelvalue_ol is None:
view = self.view
self._pixelvalue_ol = view_overlay.PixelValueOverlay(self, view)
self._pixelvalue_ol = PixelValueOverlay(self, view)
self.add_view_overlay(self._pixelvalue_ol)
self._pixelvalue_ol.active.value = True
elif self._pixelvalue_ol:
Expand All @@ -318,7 +326,7 @@ def _on_debug(self, activated):
""" Called when GUI debug mode changes => display FPS overlay """
if activated:
if self._fps_ol is None:
self._fps_ol = view_overlay.TextViewOverlay(self)
self._fps_ol = TextViewOverlay(self)
self._fps_ol.add_label("")
self.add_view_overlay(self._fps_ol)
elif self._fps_ol:
Expand All @@ -333,11 +341,11 @@ def _set_spot_mode(self, tool_mode):
if self._spotmode_ol is None:
if use_world:
spot_va = self._tab_data_model.spotPosition
self._spotmode_ol = SpotModeOverlay(self, spot_va,
self._tab_data_model.fovComp)
self._spotmode_ol = SpotModeWorldOverlay(self, spot_va,
self._tab_data_model.fovComp)
else:
spot_va = None
self._spotmode_ol = view_overlay.SpotModeOverlay(self, spot_va)
self._spotmode_ol = SpotModeViewOverlay(self, spot_va)

if use_world:
self.add_world_overlay(self._spotmode_ol)
Expand All @@ -361,7 +369,7 @@ def _set_dichotomy_mode(self, tool_mode):

if tool_mode == guimodel.TOOL_DICHO:
if not self.dicho_overlay:
self.dicho_overlay = view_overlay.DichotomyOverlay(self,
self.dicho_overlay = DichotomyOverlay(self,
self._tab_data_model.dicho_seq)
self.add_view_overlay(self.dicho_overlay)
self.dicho_overlay.active.value = True
Expand Down Expand Up @@ -751,7 +759,7 @@ def _show_focus_overlay_timed(self):
self.focus_timer.Stop()

if not self._focus_overlay:
self._focus_overlay = self.add_view_overlay(view_overlay.FocusOverlay(self))
self._focus_overlay = self.add_view_overlay(FocusOverlay(self))

# Set a timer to clear the overlay in x seconds
self.focus_timer = wx.CallLater(5000, self._hide_focus_overlay)
Expand Down Expand Up @@ -854,7 +862,7 @@ def on_right_down(self, event):
if CAN_FOCUS in self.abilities and not self.dragging:
# Create the overlay, on the first time it is needed
if not self._focus_overlay:
self._focus_overlay = self.add_view_overlay(view_overlay.FocusOverlay(self))
self._focus_overlay = self.add_view_overlay(FocusOverlay(self))
# Note: Set the cursor before the super method is called.
# There is a Ubuntu/wxPython related bug that SetCursor does not work once CaptureMouse
# is called (which happens in the super method).
Expand Down Expand Up @@ -1209,7 +1217,7 @@ def __init__(self, *args, **kwargs):
super(BarPlotCanvas, self).__init__(*args, **kwargs)

# play/pause icon
self.play_overlay = view_overlay.PlayIconOverlay(self)
self.play_overlay = PlayIconOverlay(self)
self.add_view_overlay(self.play_overlay)

self.drag_init_pos = None
Expand All @@ -1220,7 +1228,7 @@ def __init__(self, *args, **kwargs):
self.closed = canvas.PLOT_CLOSE_BOTTOM
self.plot_mode = canvas.PLOT_MODE_BAR

self.markline_overlay = view_overlay.MarkingLineOverlay(self,
self.markline_overlay = MarkingLineOverlay(self,
orientation=MarkingLineOverlay.HORIZONTAL | MarkingLineOverlay.VERTICAL,
map_y_from_x=True)
self.add_view_overlay(self.markline_overlay)
Expand Down Expand Up @@ -1492,12 +1500,12 @@ def __init__(self, *args, **kwargs):
self._crosshair_ol = None
self._pixelvalue_ol = None

self.markline_overlay = view_overlay.MarkingLineOverlay(self,
self.markline_overlay = MarkingLineOverlay(self,
orientation=MarkingLineOverlay.HORIZONTAL | MarkingLineOverlay.VERTICAL)
self.add_view_overlay(self.markline_overlay)

# play/pause icon
self.play_overlay = view_overlay.PlayIconOverlay(self)
self.play_overlay = PlayIconOverlay(self)
self.add_view_overlay(self.play_overlay)

self.background_brush = wx.BRUSHSTYLE_SOLID
Expand Down Expand Up @@ -1583,7 +1591,7 @@ def _on_cross_hair_show(self, activated):
""" Activate the cross hair view overlay """
if activated:
if self._crosshair_ol is None:
self._crosshair_ol = view_overlay.CenteredLineOverlay(self)
self._crosshair_ol = CenteredLineOverlay(self)
self.add_view_overlay(self._crosshair_ol)
elif self._crosshair_ol:
self.remove_view_overlay(self._crosshair_ol)
Expand All @@ -1595,7 +1603,7 @@ def _on_pixel_value_show(self, activated):
if activated:
if self._pixelvalue_ol is None:
view = self.view
self._pixelvalue_ol = view_overlay.PixelValueOverlay(self, view)
self._pixelvalue_ol = PixelValueOverlay(self, view)
self.add_view_overlay(self._pixelvalue_ol)
elif self._pixelvalue_ol:
self.remove_view_overlay(self._pixelvalue_ol)
Expand Down Expand Up @@ -1674,7 +1682,7 @@ def __init__(self, *args, **kwargs):

# Overlays

self.polar_overlay = view_overlay.PolarOverlay(self)
self.polar_overlay = PolarOverlay(self)
self.polar_overlay.canvas_padding = 10
self.add_view_overlay(self.polar_overlay)

Expand Down
103 changes: 103 additions & 0 deletions src/odemis/gui/comp/overlay/centered_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-

"""
:created: 2014-01-25
:author: Rinze de Laat
:copyright: © 2014 Rinze de Laat, Delmic
This file is part of Odemis.
.. license::
Odemis is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License version 2 as published by the Free
Software Foundation.
Odemis is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
Odemis. If not, see http://www.gnu.org/licenses/.
"""

import odemis.gui as gui
import odemis.gui.comp.overlay.base as base
import odemis.util.conversion as conversion

# Shape type of CenteredLineOverlay
CROSSHAIR, HORIZONTAL_LINE, VERTICAL_LINE = 0, 1, 2


class CenteredLineOverlay(base.ViewOverlay):
""" Render a static line (horizontal, vertical, crosshair) around the center of the view """

def __init__(self, cnvs, colour=gui.CROSSHAIR_COLOR, size=gui.CROSSHAIR_SIZE, shape=CROSSHAIR,
thickness=gui.CENTERED_LINE_THICKNESS):
base.ViewOverlay.__init__(self, cnvs)

self.colour = conversion.hex_to_frgba(colour)
self.size = size
self.thickness = thickness
self.shape = shape
if self.shape not in (CROSSHAIR, HORIZONTAL_LINE, VERTICAL_LINE):
raise ValueError("Unknown shape input {}.".format(self.shape))

def _draw_vertical_line(self, ctx, center, size, colour, thickness):
"""
Draw vertical line around the center point
"""
top = center[1] - size
bottom = center[1] + size

ctx.set_line_width(thickness)

# Draw shadow
ctx.set_source_rgba(0, 0, 0, 0.9)
ctx.move_to(center[0] + 1.5, top + 1.5)
ctx.line_to(center[0] + 1.5, bottom + 1.5)
ctx.stroke()

# Draw cross hair
ctx.set_source_rgba(*colour)
ctx.move_to(center[0] + 0.5, top + 0.5)
ctx.line_to(center[0] + 0.5, bottom + 0.5)
ctx.stroke()

def _draw_horizontal_line(self, ctx, center, size, colour, thickness):
"""
Draw horizontal line around the center point
"""
left = center[0] - size
right = center[0] + size

ctx.set_line_width(thickness)

# Draw shadow
ctx.set_source_rgba(0, 0, 0, 0.9)
ctx.move_to(left + 1.5, center[1] + 1.5)
ctx.line_to(right + 1.5, center[1] + 1.5)
ctx.stroke()

# Draw cross hair
ctx.set_source_rgba(*colour)
ctx.move_to(left + 0.5, center[1] + 0.5)
ctx.line_to(right + 0.5, center[1] + 0.5)
ctx.stroke()

def draw_crosshair(self, ctx, center, size, colour, thickness):
"""
Draw cross hair given Cairo context and center position
"""
self._draw_horizontal_line(ctx, center, size, colour, thickness)
self._draw_vertical_line(ctx, center, size, colour, thickness)

def draw(self, ctx):
""" Draw a cross hair to the Cairo context """
center = self.cnvs.get_half_view_size()
if self.shape is CROSSHAIR:
self.draw_crosshair(ctx, center, size=self.size, colour=self.colour, thickness=self.thickness)
elif self.shape is HORIZONTAL_LINE:
self._draw_horizontal_line(ctx, center, size=center[0], colour=self.colour, thickness=self.thickness)
elif self.shape is VERTICAL_LINE:
self._draw_vertical_line(ctx, center, size=center[1], colour=self.colour, thickness=self.thickness)
2 changes: 1 addition & 1 deletion src/odemis/gui/comp/overlay/current_pos_cross_hair.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import odemis.gui as gui
import odemis.util.conversion as conversion
from odemis.gui.comp.overlay.base import WorldOverlay
from odemis.gui.comp.overlay.view import CenteredLineOverlay
from odemis.gui.comp.overlay.centered_line import CenteredLineOverlay
from odemis.gui.util import call_in_wx_main


Expand Down
Loading

0 comments on commit 2043951

Please sign in to comment.