Skip to content

Commit

Permalink
Add config options: size, opacity and flip.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgrigolato committed Dec 2, 2013
1 parent b90f01e commit f6acb95
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions dose.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
TIME_BEFORE_CALL = 1.0 # seconds between event and the call action
CONFIG_FILE_NAME = ".dose.conf"
CONFIG_DEFAULT_OPTIONS = {
"position": (-1, -1) # by default let the win system decide
"position": (-1, -1), # by default let the win system decide
"size": (FIRST_WIDTH, FIRST_HEIGHT),
"opacity": FIRST_OPACITY,
"flipped": False
}

def rounded_rectangle_region(width, height, radius):
Expand Down Expand Up @@ -117,15 +120,17 @@ class DoseGraphicalSemaphore(wx.Frame):
This class knows nothing about the led color meaning, and just print them
at the screen.
"""
def __init__(self, parent, config, leds=FIRST_LEDS,
width=FIRST_WIDTH, height=FIRST_HEIGHT,
opacity=FIRST_OPACITY, flip=False):
def __init__(self, parent, config, leds=FIRST_LEDS):
self._config = config
frame_style = (wx.FRAME_SHAPED | # Allows wx.SetShape
wx.FRAME_NO_TASKBAR |
wx.STAY_ON_TOP |
wx.NO_BORDER
)
pos = config.get_option("position")
size = config.get_option("size")
opacity = config.get_option("opacity")
flip = config.get_option("flipped")
super(DoseGraphicalSemaphore, self).__init__(parent, style=frame_style,
pos=pos)
#self.BackgroundStyle = wx.BG_STYLE_CUSTOM # Avoids flicker
Expand All @@ -135,7 +140,7 @@ def __init__(self, parent, config, leds=FIRST_LEDS,
) # Needed to at least have transparency on wxGTK
self._paint_width, self._paint_height = 0, 0 # Ensure update_sizes at
# first on_paint
self.ClientSize = (width, height)
self.ClientSize = size
self._flip = flip
self.opacity = opacity
self.Bind(wx.EVT_PAINT, self.on_paint)
Expand All @@ -159,6 +164,7 @@ def opacity(self):
@opacity.setter
def opacity(self, value):
self._opacity = value
self._config.set_option("opacity", value)
self.SetTransparent(self.opacity)

@property
Expand All @@ -169,6 +175,7 @@ def flip(self):
def flip(self, value):
if self._flip != value:
self._flip = value
self._config.set_option("flipped", value)
self.Refresh()

def on_paint(self, evt):
Expand Down Expand Up @@ -295,7 +302,9 @@ def on_timer(self, evt):
new_h = max(MIN_HEIGHT, self._click_frame_height +
2 * delta_y * self._quad_signal_y
)
self.ClientSize = new_w, new_h
new_size = new_w, new_h
self.ClientSize = new_size
self._config.set_option("size", new_size)
self.SendSizeEvent() # Needed for wxGTK

# Center should be kept
Expand Down Expand Up @@ -513,7 +522,7 @@ class DoseConfig:
"""

def get_option(self, key):
return self._config[key]
return self._config.get(key, CONFIG_DEFAULT_OPTIONS[key])

def set_option(self, key, value):
self._config[key] = value
Expand Down

0 comments on commit f6acb95

Please sign in to comment.