Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2013-08-01 20:52:54 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2013-09-02 17:50:01 (GMT)
commitb78b89a88eb63ca84ab5229cafaec02e6b73bf67 (patch)
tree2f182d11a1a7e92fc8c3d64a2162c428d2e36882
parentd2957df00729971e4a17812bb2c780e8d9c53ecc (diff)
Modularización de OptionsCanvas
-rw-r--r--Widgets.py124
-rw-r--r--poll.py121
2 files changed, 126 insertions, 119 deletions
diff --git a/Widgets.py b/Widgets.py
index cfb4c50..d113884 100644
--- a/Widgets.py
+++ b/Widgets.py
@@ -28,6 +28,8 @@ from sugar3.graphics.toolbutton import ToolButton
from sugar3.activity.widgets import StopButton
from sugar3.activity.widgets import ActivityToolbarButton
+from sugar3.graphics.alert import NotifyAlert
+
class Toolbar(ToolbarBox):
def __init__(self, activity):
@@ -259,3 +261,125 @@ class ItemNewPoll(Gtk.Box):
self.pack_start(self.entry, True, True, 10)
self.show_all()
+
+class OptionsCanvas(Gtk.Box):
+ """
+ Show the options canvas.
+ """
+
+ def __init__(self, poll_activity):
+
+ Gtk.Box.__init__(self, orientation = Gtk.Orientation.VERTICAL)
+
+ self.poll_activity = poll_activity
+ self.poll_activity._current_view = 'options'
+
+ alignment = Gtk.Alignment.new(0.5, 0, 0, 0)
+ # optionsbox is centered within self
+ optionsbox = Gtk.VBox()
+
+ alignment.add(optionsbox)
+ self.pack_start(alignment, True, True, 0)
+
+ mainbox = Gtk.VBox()
+
+ optionsbox.pack_start(mainbox, True, False, 0)
+
+ mainbox.pack_start(Gtk.Label(_('Settings')), True, True, 10)
+
+ options_details_box = Gtk.VBox()
+ mainbox.pack_start(options_details_box, True, False, 10)
+
+ #options widgets
+ options_widgets = []
+
+ viewResultCB = Gtk.CheckButton(label=_('Show answers while voting'))
+ viewResultCB.set_active(self.poll_activity._view_answer)
+ viewResultCB.connect('toggled', self.__view_result_checkbox_cb)
+ options_details_box.pack_start(viewResultCB, True, True, 10)
+
+ rememberVoteCB = Gtk.CheckButton(label=_('Remember last vote'))
+ rememberVoteCB.set_active(self.poll_activity._remember_last_vote)
+ rememberVoteCB.connect('toggled', self.__remember_last_vote_checkbox_cb)
+ options_details_box.pack_start(rememberVoteCB, True, True, 10)
+
+ playVoteSoundCB = Gtk.CheckButton(
+ label=_('Play a sound when make a vote'))
+ playVoteSoundCB.set_active(self.poll_activity._play_vote_sound)
+ playVoteSoundCB.connect('toggled', self.__play_vote_sound_checkbox_cb)
+ options_details_box.pack_start(playVoteSoundCB, True, True, 10)
+
+ vbox = Gtk.VBox()
+ useImageCB = Gtk.CheckButton(label=_('Use image in answer'))
+ useImageCB.set_active(self.poll_activity._use_image)
+ options_details_box.pack_start(useImageCB, True, True, 10)
+
+ hbox2 = Gtk.HBox()
+ hbox2.pack_start(Gtk.Label(_('Image Size: ')), True, True, 10)
+ entrybox = Gtk.Entry(max_length=3)
+
+ #entrybox.modify_bg(Gtk.StateType.INSENSITIVE,
+ # style.COLOR_WHITE.get_gdk_color())
+
+ entrybox.set_text(str(self.poll_activity._image_size['height']))
+ entrybox.connect('changed', self.__entry_image_size_cb, 'height')
+ hbox2.pack_start(entrybox, True, True, 10)
+ hbox2.pack_start(Gtk.Label('x'), True, True, 10)
+ entrybox = Gtk.Entry(max_length=3)
+
+ #entrybox.modify_bg(Gtk.StateType.INSENSITIVE,
+ # style.COLOR_WHITE.get_gdk_color())
+
+ entrybox.set_text(str(self.poll_activity._image_size['width']))
+ entrybox.connect('changed', self.__entry_image_size_cb, 'width')
+ hbox2.pack_start(entrybox, True, True, 10)
+ useImageCB.connect('toggled', self.__use_image_checkbox_cb, vbox, hbox2)
+
+ if self.poll_activity._use_image:
+ vbox.pack_start(hbox2, True, True, 10)
+
+ options_details_box.pack_start(vbox, True, True, 0)
+
+ hbox = Gtk.HBox()
+ # SAVE button
+ button = Gtk.Button(_("Save"))
+ button.connect('clicked', self.__button_save_options_cb)
+ hbox.pack_start(button, True, True, 10)
+
+ options_details_box.pack_end(hbox, True, True, 10)
+
+ self.show_all()
+
+ def __view_result_checkbox_cb(self, checkbox):
+ self.poll_activity._view_answer = checkbox.get_active()
+
+ def __remember_last_vote_checkbox_cb(self, checkbox):
+ self.poll_activity._remember_last_vote = checkbox.get_active()
+
+ def __play_vote_sound_checkbox_cb(self, checkbox, data=None):
+ self.poll_activity._play_vote_sound = checkbox.get_active()
+
+ def __entry_image_size_cb(self, entrycontrol, data):
+
+ text = entrycontrol.get_text()
+
+ if text: self.poll_activity._image_size[data] = int(text)
+
+ def __use_image_checkbox_cb(self, checkbox, data=None, data2=None):
+
+ self.poll_activity._use_image = checkbox.get_active()
+
+ if checkbox.get_active():
+ data.add(data2)
+
+ else:
+ data.remove(data2)
+
+ def __button_save_options_cb(self, button):
+
+ alert = NotifyAlert(timeout=3)
+ alert.props.title = _('Poll Activity')
+ alert.props.msg = _('The settings have been saved')
+ self.poll_activity.add_alert(alert)
+ alert.connect('response', self.poll_activity._alert_cancel_cb)
+ alert.show()
diff --git a/poll.py b/poll.py
index ce69a5f..6a32e52 100644
--- a/poll.py
+++ b/poll.py
@@ -81,6 +81,7 @@ IMAGE_THUMBNAIL_WIDTH = 80
from Widgets import NewPollCanvas
from Widgets import Toolbar
+from Widgets import OptionsCanvas
class PollBuilder(activity.Activity):
"""
@@ -692,7 +693,7 @@ class PollBuilder(activity.Activity):
def __button_options_clicked(self, button):
- self.set_canvas(self.__options_canvas())
+ self.set_canvas(OptionsCanvas(self))
def _button_choose_image_cb(self, button, data=None, data2=None):
@@ -779,124 +780,6 @@ class PollBuilder(activity.Activity):
else:
return False
- def __options_canvas(self, editing=False, highlight=[]):
- """
- Show the options canvas.
- """
-
- self._current_view = 'options'
- canvasbox = Gtk.VBox()
- alignment = Gtk.Alignment.new(0.5, 0, 0, 0)
- # optionsbox is centered within canvasbox
- optionsbox = Gtk.VBox()
-
- alignment.add(optionsbox)
- canvasbox.pack_start(alignment, True, True, 0)
-
- mainbox = Gtk.VBox()
-
- optionsbox.pack_start(mainbox, True, False, 0)
-
- mainbox.pack_start(Gtk.Label(_('Settings')), True, True, 10)
-
- options_details_box = Gtk.VBox()
- mainbox.pack_start(options_details_box, True, False, 10)
-
- #options widgets
- options_widgets = []
-
- viewResultCB = Gtk.CheckButton(label=_('Show answers while voting'))
- viewResultCB.set_active(self._view_answer)
- viewResultCB.connect('toggled', self._view_result_checkbox_cb)
- options_details_box.pack_start(viewResultCB, True, True, 10)
-
- rememberVoteCB = Gtk.CheckButton(label=_('Remember last vote'))
- rememberVoteCB.set_active(self._remember_last_vote)
- rememberVoteCB.connect('toggled', self._remember_last_vote_checkbox_cb)
- options_details_box.pack_start(rememberVoteCB, True, True, 10)
-
- playVoteSoundCB = Gtk.CheckButton(
- label=_('Play a sound when make a vote'))
- playVoteSoundCB.set_active(self._play_vote_sound)
- playVoteSoundCB.connect('toggled', self._play_vote_sound_checkbox_cb)
- options_details_box.pack_start(playVoteSoundCB, True, True, 10)
-
- vbox = Gtk.VBox()
- useImageCB = Gtk.CheckButton(label=_('Use image in answer'))
- useImageCB.set_active(self._use_image)
- options_details_box.pack_start(useImageCB, True, True, 10)
-
- hbox2 = Gtk.HBox()
- hbox2.pack_start(Gtk.Label(_('Image Size: ')), True, True, 10)
- entrybox = Gtk.Entry(max_length=3)
-
- entrybox.modify_bg(Gtk.StateType.INSENSITIVE,
- style.COLOR_WHITE.get_gdk_color())
-
- entrybox.set_text(str(self._image_size['height']))
- entrybox.connect('changed', self._entry_image_size_cb, 'height')
- hbox2.pack_start(entrybox, True, True, 10)
- hbox2.pack_start(Gtk.Label('x'), True, True, 10)
- entrybox = Gtk.Entry(max_length=3)
-
- entrybox.modify_bg(Gtk.StateType.INSENSITIVE,
- style.COLOR_WHITE.get_gdk_color())
-
- entrybox.set_text(str(self._image_size['width']))
- entrybox.connect('changed', self._entry_image_size_cb, 'width')
- hbox2.pack_start(entrybox, True, True, 10)
- useImageCB.connect('toggled', self._use_image_checkbox_cb, vbox, hbox2)
-
- if self._use_image:
- vbox.pack_start(hbox2, True, True, 10)
-
- options_details_box.pack_start(vbox, True, True, 0)
-
- hbox = Gtk.HBox()
- # SAVE button
- button = Gtk.Button(_("Save"))
- button.connect('clicked', self._button_save_options_cb)
- hbox.pack_start(button, True, True, 10)
-
- options_details_box.pack_end(hbox, True, True, 10)
-
- canvasbox.show_all()
- return canvasbox
-
- def _view_result_checkbox_cb(self, checkbox, data=None):
- self._view_answer = checkbox.get_active()
-
- def _remember_last_vote_checkbox_cb(self, checkbox, data=None):
- self._remember_last_vote = checkbox.get_active()
-
- def _play_vote_sound_checkbox_cb(self, checkbox, data=None):
- self._play_vote_sound = checkbox.get_active()
-
- def _use_image_checkbox_cb(self, checkbox, data=None, data2=None):
-
- self._use_image = checkbox.get_active()
-
- if checkbox.get_active():
- data.add(data2)
-
- else:
- data.remove(data2)
-
- def _button_save_options_cb(self, button, data=None):
-
- alert = NotifyAlert(timeout=3)
- alert.props.title = _('Poll Activity')
- alert.props.msg = _('The settings have been saved')
- self.add_alert(alert)
- alert.connect('response', self._alert_cancel_cb)
- alert.show()
-
- def _entry_image_size_cb(self, entrycontrol, data):
-
- text = entrycontrol.get_text()
-
- if text: self._image_size[data] = int(text)
-
'''
def _make_default_poll(self):
"""