[pyclutter] examples: Simplify scroll-actor's menu selection
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pyclutter] examples: Simplify scroll-actor's menu selection
- Date: Thu, 30 Apr 2015 12:55:29 +0000 (UTC)
commit fd71b42b3e6dd467ca0713ab606853ce159a5bd8
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Apr 30 13:54:14 2015 +0100
examples: Simplify scroll-actor's menu selection
Drop a bunch of duplicate code by using a convenience method.
examples/scroll-actor.py | 25 +++++++++++--------------
1 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/examples/scroll-actor.py b/examples/scroll-actor.py
index 9a02a3b..c9eb95c 100644
--- a/examples/scroll-actor.py
+++ b/examples/scroll-actor.py
@@ -20,29 +20,26 @@ class Menu(Clutter.Actor):
self._current_idx = 0
def select_next(self):
- old_item = self.get_child_at_index(self._current_idx)
- old_item.props.color = Clutter.Color.get_static(Clutter.StaticColor.WHITE)
-
- self._current_idx += 1
-
- if self._current_idx == self.get_n_children():
- self._current_idx = 0
-
- new_item = self.get_child_at_index(self._current_idx)
- new_item.props.color = Clutter.Color.get_static(Clutter.StaticColor.SKY_BLUE_LIGHT)
- return new_item
+ return self.select_item(self._current_idx + 1)
def select_prev(self):
+ return self.select_item(self._current_idx - 1)
+
+ def select_item(self, idx):
old_item = self.get_child_at_index(self._current_idx)
old_item.props.color = Clutter.Color.get_static(Clutter.StaticColor.WHITE)
- self._current_idx -= 1
+ self._current_idx = idx
- if self._current_idx < 0:
- self._current_idx = self.get_n_children() - 1;
+ n_children = self.get_n_children()
+ if self._current_idx >= n_children:
+ self._current_idx = 0
+ elif self._current_idx < 0:
+ self._current_idx = n_children - 1
new_item = self.get_child_at_index(self._current_idx)
new_item.props.color = Clutter.Color.get_static(Clutter.StaticColor.SKY_BLUE_LIGHT)
+
return new_item
def create_menu_actor(scroll):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]