diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2013-05-14 23:06:23 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2013-05-14 23:06:23 (GMT) |
commit | ee35c7d88c55b67b77661e146056fc5559f12186 (patch) | |
tree | e8fb42dd46501107796c6d8b2378f5d3f82c3879 | |
parent | a81a16eb9fb8a2d49c918d2d1922ee2d2ac3ed5c (diff) |
more colors - agroup options
-rwxr-xr-x | activity.py | 153 | ||||
-rwxr-xr-x | main.py | 18 |
2 files changed, 151 insertions, 20 deletions
diff --git a/activity.py b/activity.py index e161e36..7e9495f 100755 --- a/activity.py +++ b/activity.py @@ -30,6 +30,7 @@ from sugar.activity.widgets import ActivityToolbarButton from sugar.graphics.toolbutton import ToolButton from sugar.activity.widgets import StopButton from sugar.graphics.colorbutton import ColorToolButton +from sugar.graphics.toolbarbox import ToolbarButton from gettext import gettext as _ @@ -60,12 +61,32 @@ class Activity(activity.Activity): toolbar_box.toolbar.insert(activity_button, -1) activity_button.show() + self.build_size_toolbar(toolbar_box) + self.build_colors_toolbar(toolbar_box) + + # end separator + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + stop_button = StopButton(self) + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.show_all() + + def build_size_toolbar(self, toolbox): + + size_bar = gtk.Toolbar() + #Horizontal item1 = gtk.ToolItem() label1 = gtk.Label() label1.set_text(' %s ' % _('H')) item1.add(label1) - toolbar_box.toolbar.insert(item1, -1) + size_bar.insert(item1, -1) item2 = gtk.ToolItem() self.h_spin = gtk.SpinButton() @@ -74,14 +95,14 @@ class Activity(activity.Activity): self.h_spin.props.value = self.game_size[0] self.h_spin.connect('notify::value', self.h_spin_change) item2.add(self.h_spin) - toolbar_box.toolbar.insert(item2, -1) + size_bar.insert(item2, -1) #Vertical item3 = gtk.ToolItem() label2 = gtk.Label() label2.set_text(' %s ' % _('V')) item3.add(label2) - toolbar_box.toolbar.insert(item3, -1) + size_bar.insert(item3, -1) item4 = gtk.ToolItem() self.v_spin = gtk.SpinButton() @@ -90,27 +111,108 @@ class Activity(activity.Activity): self.v_spin.props.value = self.game_size[1] self.v_spin.connect('notify::value', self.v_spin_change) item4.add(self.v_spin) - toolbar_box.toolbar.insert(item4, -1) + size_bar.insert(item4, -1) + + size_bar.show_all() + size_button = ToolbarButton(label=_('Board size'), + page=size_bar, + icon_name='preferences-system') + toolbox.toolbar.insert(size_button, -1) + size_button.show() + + def build_colors_toolbar(self, toolbox): + colors_bar = gtk.Toolbar() + + ######################################################################## # Point color - item5 = gtk.ToolItem() - self._fill_color = ColorToolButton() - self._fill_color.connect('notify::color', self.color_button_change) - item5.add(self._fill_color) - toolbar_box.toolbar.insert(item5, -1) + item = gtk.ToolItem() + label = gtk.Label() + label.set_text('%s ' % _('Points')) + item.add(label) + colors_bar.insert(item, -1) - # end separator + # select color + item = gtk.ToolItem() + fill_color = ColorToolButton() + fill_color.connect('notify::color', self.color_point_change) + item.add(fill_color) + colors_bar.insert(item, -1) + + # Separator separator = gtk.SeparatorToolItem() - separator.props.draw = False - separator.set_expand(True) - toolbar_box.toolbar.insert(separator, -1) + colors_bar.insert(separator, -1) separator.show() - stop_button = StopButton(self) - toolbar_box.toolbar.insert(stop_button, -1) - stop_button.show() + ######################################################################## + # Back color + item = gtk.ToolItem() + label = gtk.Label() + label.set_text('%s ' % _('Background')) + item.add(label) + colors_bar.insert(item, -1) - self.show_all() + # select color + item = gtk.ToolItem() + _fill_color = ColorToolButton() + c = gtk.gdk.Color() + c.red = 21588 + c.green = 47546 + c.blue = 18504 + _fill_color.set_color(c) + _fill_color.connect('notify::color', self.color_back_change) + item.add(_fill_color) + colors_bar.insert(item, -1) + + # Separator + separator = gtk.SeparatorToolItem() + colors_bar.insert(separator, -1) + separator.show() + + ######################################################################## + # Line color + item = gtk.ToolItem() + label = gtk.Label() + label.set_text('%s ' % _('Lines')) + item.add(label) + colors_bar.insert(item, -1) + + # select color + item = gtk.ToolItem() + _fill_color = ColorToolButton() + _fill_color.connect('notify::color', self.color_line_change) + item.add(_fill_color) + colors_bar.insert(item, -1) + + # Separator + separator = gtk.SeparatorToolItem() + colors_bar.insert(separator, -1) + separator.show() + + ######################################################################## + # Owner color + item = gtk.ToolItem() + label = gtk.Label() + label.set_text('%s ' % _('Owner')) + item.add(label) + colors_bar.insert(item, -1) + + # select color + item = gtk.ToolItem() + _fill_color = ColorToolButton() + c = gtk.gdk.Color() + c.red = 65535 + _fill_color.set_color(c) + _fill_color.connect('notify::color', self.color_owner_change) + item.add(_fill_color) + colors_bar.insert(item, -1) + + colors_bar.show_all() + colors_button = ToolbarButton(label=_('Colors'), + page=colors_bar, + icon_name='toolbar-colors') + toolbox.toolbar.insert(colors_button, -1) + colors_button.show() def h_spin_change(self, spin, value): self.game_size = (int(spin.props.value) + 1, self.game_size[1]) @@ -126,11 +228,26 @@ class Activity(activity.Activity): def v_spin_set_max(self, value): self.v_spin.set_range(2, value) - def color_button_change(self, widget, pspec): + def color_point_change(self, widget, pspec): color = widget.get_color() new_color = self.color_to_rgb(color) self.game.set_point_color(new_color) + def color_back_change(self, widget, pspec): + color = widget.get_color() + new_color = self.color_to_rgb(color) + self.game.set_back_color(new_color) + + def color_line_change(self, widget, pspec): + color = widget.get_color() + new_color = self.color_to_rgb(color) + self.game.set_line_color(new_color) + + def color_owner_change(self, widget, pspec): + color = widget.get_color() + new_color = self.color_to_rgb(color) + self.game.set_owner_color(new_color) + def color_to_rgb(self, color): r = color.red *255 / 65536 g = color.green *255 / 65536 @@ -49,6 +49,7 @@ class Game: self.box_size = (50, 50) self.x_offset = 100 self.y_offset = 100 + self.back_color = (84, 185, 72) self.line_color = (0, 0, 0) self.point_color = (0, 0, 0) @@ -63,6 +64,19 @@ class Game: self.point_color = color self.draw_grid() + def set_back_color(self, color): + self.back_color = color + self.draw_grid() + + def set_line_color(self, color): + self.line_color = color + self.draw_grid() + + def set_owner_color(self, color): + global COLOR_OWNER + COLOR_OWNER = color + self.draw_grid() + def draw_grid(self): w = self.grid_size[0] h = self.grid_size[1] @@ -87,7 +101,7 @@ class Game: yy = h * (self.box_size[1] - 1) self.y_offset = int((s_h - yy) / 2.0) + LINE_SIZE * 2 - self.screen.fill((84, 185, 72)) + self.screen.fill(self.back_color) self.horizontal = [] self.vertical = [] self.boxes = [] @@ -279,7 +293,7 @@ class Game: self.screen = pygame.display.get_surface() if not self.screen: self.screen = pygame.display.set_mode((900, 700)) - self.screen.fill((84, 185, 72)) + self.screen.fill(self.back_color) self.fuente = pygame.font.Font(None, self.box_size[0]) self.draw_grid() |