diff options
author | florent <florent.pigout@gmail.com> | 2011-04-28 18:58:47 (GMT) |
---|---|---|
committer | florent <florent.pigout@gmail.com> | 2011-04-28 18:58:47 (GMT) |
commit | 1cc8cd378b181c67dbfbcf4978478d6847d68ad1 (patch) | |
tree | 36b0c4ac06c503ad174c5f9e997f5e9a712a4dff | |
parent | 10376e6aa0eb8221ae61981a56df18dde0b84d5b (diff) |
manage frame rate from config
-rw-r--r-- | activity.py | 19 | ||||
-rw-r--r-- | atoidejouer/story/keys.py | 3 | ||||
-rw-r--r-- | atoidejouer/tools/config.py | 39 | ||||
-rw-r--r-- | atoidejouer/ui/screens.py | 98 | ||||
-rw-r--r-- | static/data/config/config.ini | 4 |
5 files changed, 116 insertions, 47 deletions
diff --git a/activity.py b/activity.py index 094dcab..bf6d6ee 100644 --- a/activity.py +++ b/activity.py @@ -17,7 +17,7 @@ from sugar.activity import activity # atoidejouer import from atoidejouer.ui import screens, toolbar # .. -from atoidejouer.tools import storage +from atoidejouer.tools import config, storage # .. from atoidejouer.story.keys import StoryKeys @@ -28,7 +28,7 @@ logger.setLevel(logging.DEBUG) class ThreadAnim(threading.Thread): - def __init__(self, activity_, rate=1): + def __init__(self, activity_): # init parent threading.Thread.__init__(self) # main flag @@ -36,7 +36,6 @@ class ThreadAnim(threading.Thread): self._pause = True # main vars self._activity = activity_ - self._rate = rate self._time = 0 # start right now self.start() @@ -98,8 +97,10 @@ class ThreadAnim(threading.Thread): def run(self): # ... while self._die is False: + # get current rate + _rate = config.Config().get_rate_value() # ... - time.sleep(self._rate) + time.sleep(_rate) # do pause if (self._time + 1) >= self._activity._number_of_keys\ and self._pause is False: @@ -115,7 +116,7 @@ class ThreadAnim(threading.Thread): # .. do something else: # ... - self.set_time(rate=self._rate) + self.set_time(rate=_rate) def _toolbar_changed(toolbox, page, activity_): @@ -146,11 +147,9 @@ class AToiDeJouerActivity(activity.Activity): self._toolbox = activity.ActivityToolbox(self) # add tool bars self.set_toolbox(self._toolbox) - # ... - _rate = 0.25 # sequence dict and list - self.graphic_keys = StoryKeys('graphics', rate=_rate) - self.sound_keys = StoryKeys('sounds', rate=_rate) + self.graphic_keys = StoryKeys('graphics') + self.sound_keys = StoryKeys('sounds') # keep thread & screen self._thread = None self._screens = dict() @@ -173,7 +172,7 @@ class AToiDeJouerActivity(activity.Activity): # .. self._toolbox.connect('current-toolbar-changed', _toolbar_changed, self) # do anim - self._thread = ThreadAnim(self, rate=_rate) + self._thread = ThreadAnim(self) def get_toolbox(self): return self._toolbox diff --git a/atoidejouer/story/keys.py b/atoidejouer/story/keys.py index 7d8f9cf..4bebb2e 100644 --- a/atoidejouer/story/keys.py +++ b/atoidejouer/story/keys.py @@ -20,10 +20,9 @@ logger = logging.getLogger('atoidejouer') class StoryKeys(object): - def __init__(self, type_, rate=1.0): + def __init__(self, type_): # keep type self._type = type_ - self.__rate = rate # .. self.clear() diff --git a/atoidejouer/tools/config.py b/atoidejouer/tools/config.py index 59b1052..d4d8700 100644 --- a/atoidejouer/tools/config.py +++ b/atoidejouer/tools/config.py @@ -28,6 +28,45 @@ class Config(object): else: self.__config = config + def get_mode(self): + # get mode value + _mode = self.get('activity>mode') + # ensure mode + if _mode in ['easy', 'advanced']: + pass + else: + # is easy by default + _mode = 'easy' + # ensure config for further use + self.set('activity>mode', _mode) + # return it + return _mode + + def get_rate(self): + # get rate value + _rate = self.get('activity>rate') + # ensure rate + if _rate in ['normal', 'smooth', 'faster']: + pass + else: + # is easy by default + _rate = 'normal' + # ensure config for further use + self.set('activity>rate', _rate) + # return it + return _rate + + def get_rate_value(self): + # .. + _rate = self.get_rate() + # simple rate factory + if _rate == 'faster': + return 0.2 + elif _rate == 'smooth': + return 0.5 + else: + return 1.0 + def set(self, path, value, type_=str): # set value self.set_value(*path.split(">"), value=value, type_=type_) diff --git a/atoidejouer/ui/screens.py b/atoidejouer/ui/screens.py index 044da17..657ad45 100644 --- a/atoidejouer/ui/screens.py +++ b/atoidejouer/ui/screens.py @@ -125,9 +125,8 @@ class ScreenStory(graphics.Scene): # get the current frame _time = 0.0 if self.toolbar.activity._thread is None\ else self.toolbar.activity._thread._time - # get the current frame - _rate = 1.0 if self.toolbar.activity._thread is None\ - else self.toolbar.activity._thread._rate + # get the current rate + _rate = config.Config().get_rate_value() # clear ?? self._check_clear() # .. @@ -140,19 +139,11 @@ class ScreenStory(graphics.Scene): _currents.append(self.__refresh_image(_n, _time, _rate)) # draw mask _currents.append(self.__refresh_default('mask')) - # DEBUG - logger.debug('[screens] refresh - _currents: %s' % _currents) - # DEBUG - # .. - # self.queue_draw() - # TODO - hide previous + # hide previous for _code, _image in self.__graphics.items(): if _code in _currents: continue else: - # DEBUG - logger.debug('[screens] refresh - not in _code: %s' % _code) - # DEBUG _image.visible = False self.queue_draw() # show first @@ -244,9 +235,6 @@ class ScreenStory(graphics.Scene): int(time), filename) # get transition ratio _ratio = time - int(time) - # DEBUG - logger.debug('[screens] __compute_transition_align - _ratio: %s' % _ratio) - # DEBUG if _ratio < rate: return _x, _y else: @@ -267,9 +255,6 @@ class ScreenStory(graphics.Scene): # get sequence file codes _code = self._get_keys('graphics').get_code( self.toolbar.name, sequence_name, _current) - # DEBUG - logger.debug('[screens] __refresh_image - _code: %s' % _code) - # DEBUG # current file code _code = key.random_str() if _code is None else _code # get/update width and height @@ -594,8 +579,14 @@ def _on_button_click(button, screen, name, msg_label, value): [ ADVANCED, - MEDIUM, EASY, +] = range(2) + + +[ + FASTER, + SMOOTH, + NORMAL, ] = range(3) @@ -611,6 +602,7 @@ class ScreenActivity(gtk.HBox): self.msg_label_export = None # add left menu self._group_mode = None + self._group_rate = None self._add_left_part() # .. self.pack_start(gtk.EventBox(), expand=False, fill=True) @@ -619,30 +611,43 @@ class ScreenActivity(gtk.HBox): # do show self._show() - def refresh(self): + def __refresh_mode_part(self): # get mode value - _mode = config.Config().get('activity>mode') - if _mode in ['easy', 'medium', 'advanced']: - pass - else: - # is easy - _mode = 'easy' - # ensure config for further use - config.Config().set('activity>mode', _mode) + _mode = config.Config().get_mode() # update ui for _i, _b in enumerate(self._group_mode): _b.set_active(False) # update radio boxes if _mode == 'easy': self._group_mode[EASY].set_active(True) - elif _mode == 'medium': - self._group_mode[MEDIUM].set_active(True) elif _mode == 'advanced': self._group_mode[ADVANCED].set_active(True) # default easy else: self._group_mode[EASY].set_active(True) + def __refresh_rate_part(self): + # get rate value + _rate = config.Config().get_rate() + # update ui + for _i, _b in enumerate(self._group_rate): + _b.set_active(False) + # update radio boxes + if _rate == 'normal': + self._group_rate[NORMAL].set_active(True) + elif _rate == 'smooth': + self._group_rate[SMOOTH].set_active(True) + elif _rate == 'faster': + self._group_rate[FASTER].set_active(True) + # default easy + else: + self._group_rate[NORMAL].set_active(True) + + def refresh(self): + # mode + self.__refresh_mode_part() + # rate + self.__refresh_rate_part() def _get_title(self, text): # init @@ -705,8 +710,6 @@ class ScreenActivity(gtk.HBox): # add options _vbox.pack_start(_easy, expand=False, fill=True) # with easy as group - _vbox.pack_start(self._get_toggle_box(_easy, 'mode', 'medium', - _('Meduim')), expand=False, fill=True) _vbox.pack_start(self._get_toggle_box(_easy, 'mode', 'advanced', _('Advanced')), expand=False, fill=True) # init group @@ -714,6 +717,32 @@ class ScreenActivity(gtk.HBox): # .. return _vbox + def _get_rate_part(self): + # .. + _vbox = gtk.VBox(homogeneous=False, spacing=5) + # border + _vbox.set_border_width(5) + # show + _vbox.show() + # add first part title + _vbox.pack_start(self._get_title(_('FRAME RATE')), + expand=False, fill=True) + # TODO - add some explanation text + # init normal option and use it as group + _normal = self._get_toggle_box(None, 'rate', 'normal', _('Normal')) + # add options + _vbox.pack_start(_normal, expand=False, fill=True) + # with easy as group + _vbox.pack_start(self._get_toggle_box(_normal, 'rate', 'smooth', + _('Smooth')), expand=False, fill=True) + # with easy as group + _vbox.pack_start(self._get_toggle_box(_normal, 'rate', 'faster', + _('Faster')), expand=False, fill=True) + # init group + self._group_rate = _normal.get_group() + # .. + return _vbox + def _add_left_part(self): # .. _vbox = gtk.VBox(homogeneous=False, spacing=5) @@ -723,9 +752,12 @@ class ScreenActivity(gtk.HBox): _vbox.show() # add self.pack_start(_vbox, expand=False, fill=True) - # add first part title + # add part choices _vbox.pack_start(self._get_mode_part(), expand=False, fill=True) + # add rate choices + _vbox.pack_start(self._get_rate_part(), + expand=False, fill=True) def _get_export_part(self): # .. diff --git a/static/data/config/config.ini b/static/data/config/config.ini index a3ae9b6..5668210 100644 --- a/static/data/config/config.ini +++ b/static/data/config/config.ini @@ -1,7 +1,7 @@ [activity] mode = easy +rate = normal [mode] -easy = image sound -medium = image position sound +easy = image position sound advanced = image position sound time remove |