Ejemplo n.º 1
0
    def __init__(self, value=True, getter=None, setter=None, action=None):
        ''' Create a boolean entry.

        :Parameters:
        `value` : bool
            Initial value
        `getter` : function()
            Function to be used to get actual value
        `setter` : function(value)
            Function to be used to set actual value
        `action` : function(widget)
            Action to be executed when entry has changed
        '''

        self._setter = setter
        self._getter = getter
        self._action_callback = action
        if value:
            text = 'True'
        else:
            text = 'False'
        ToggleButton.__init__(self, text=text, active=value, action=self._on_commit)
        self._expand[0] = True
        if self._getter:
            pyglet.clock.schedule_interval(self._update_value, 0.1)
        self.text = text
        self.style = theme.BoolEntry
Ejemplo n.º 2
0
    def __init__(self, value=True, getter=None, setter=None, action=None):
        ''' Create a boolean entry.

        :Parameters:
        `value` : bool
            Initial value
        `getter` : function()
            Function to be used to get actual value
        `setter` : function(value)
            Function to be used to set actual value
        `action` : function(widget)
            Action to be executed when entry has changed
        '''

        self._setter = setter
        self._getter = getter
        self._action_callback = action
        if value:
            text = 'True'
        else:
            text = 'False'
        ToggleButton.__init__(self,
                              text=text,
                              active=value,
                              action=self._on_commit)
        self._expand[0] = True
        if self._getter:
            pyglet.clock.schedule_interval(self._update_value, 0.1)
        self.text = text
        self.style = theme.BoolEntry
Ejemplo n.º 3
0
 def create_toggle_button(self,
                          name1,
                          callback1,
                          name2,
                          callback2,
                          location=Location.SOUTH):
     btn = ToggleButton(name1, callback1, name2, callback2, location)
     self.sprites.add(btn)
     return btn
Ejemplo n.º 4
0
def create_revert_button():
    button = ToggleButton(
        app_theme.get_pixbuf("mode/simple_normal.png"),
        app_theme.get_pixbuf("mode/full_normal.png"),
        app_theme.get_pixbuf("mode/simple_hover.png"),
        app_theme.get_pixbuf("mode/full_hover.png"),
        app_theme.get_pixbuf("mode/simple_press.png"),
        app_theme.get_pixbuf("mode/full_press.png"),
    )
    return button
Ejemplo n.º 5
0
    def __init__(self,
                 interactor,
                 label,
                 vertical=True,
                 left=10,
                 top=10,
                 open_label="Open",
                 on_open=None,
                 close_label="Close",
                 on_close=None,
                 button_margin=5,
                 parent=None,
                 save=None):

        self.save = save
        self.interactor = interactor
        self.margin = button_margin
        # Left is automatically modified by the margin; was running into issues
        # with updating left at a later date, this was the easiest solution.
        self.left = left
        self.top = top
        self.label = ToggleButton(self.interactor,
                                  label,
                                  on=self.__on__,
                                  off=self.__off__,
                                  on_prefix=open_label,
                                  off_prefix=close_label,
                                  left=self.left - self.margin,
                                  top=self.top)
        self.on_open = on_open
        self.on_close = on_close
        self.vertical = vertical

        self.open = False

        # Increment this as widgets are added
        self.width, self.height = self.label.get_dimensions()

        self.widgets = []
        self.bars = {}
        self.parent = parent

        self.__placing__ = False
Ejemplo n.º 6
0
    def add_toggle_button(self, label, **kwargs):

        _off = kwargs.get("off", None)
        _on  = kwargs.get("on", None)

        def off():
            if _off:
                _off()
            if self.save:
                self.save()

        def on():
            if _on:
                _on()

        kwargs['off'] = off
        kwargs['on'] = on

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = ToggleButton(self.interactor, label, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b
Ejemplo n.º 7
0
    def __init__(self, title='Title', child=None, active=True, spacing=1):
        ''' Create folder. '''

        self._text = title
        self._closed_prefix = u'▹ '
        self._opened_prefix = u'▿ '
        if active:
            prefix = self._opened_prefix
        else:
            prefix = self._closed_prefix
        self._title = ToggleButton(prefix + title,
                                   active=active,
                                   action=self.toggle)
        VBox.__init__(self, children=[self._title, child], spacing=spacing)
        self.style = theme.Folder
        self.title.style = theme.Folder.title
        self.child.style = theme.Folder.child
Ejemplo n.º 8
0
    def __init__(self, interactor, label, vertical=True, left=10, top=10, open_label="Open", on_open=None, close_label="Close", button_margin=5, parent=None, save=None):

        self.save = save
        self.interactor = interactor
        self.margin = button_margin
        # Left is automatically modified by the margin; was running into issues with updating left at a later date, this was the easiest solution.
        self.left = left
        self.top = top
        self.label = ToggleButton(self.interactor, label, on=self.__on__, off=self.__off__, on_prefix=open_label, off_prefix=close_label, left=self.left - self.margin, top=self.top)
        self.on_open = on_open
        self.vertical = vertical

        self.open = False

        # Increment this as widgets are added
        self.width, self.height = self.label.get_dimensions()
        self.height += button_margin

        self.widgets = []
        self.bars = {}
        self.parent = parent

        self.__placing__ = False
Ejemplo n.º 9
0
    def add_toggle_button(self, label, **kwargs):

        _off = kwargs.get("off", None)
        _on = kwargs.get("on", None)

        def off():
            if _off:
                _off()
            if self.save:
                self.save()

        def on():
            if _on:
                _on()

        kwargs['off'] = off
        kwargs['on'] = on

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = ToggleButton(self.interactor, label, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b
Ejemplo n.º 10
0
class Toolbar(object):
    def __init__(self,
                 interactor,
                 label,
                 vertical=True,
                 left=10,
                 top=10,
                 open_label="Open",
                 on_open=None,
                 close_label="Close",
                 button_margin=5,
                 parent=None,
                 save=None):

        self.save = save
        self.interactor = interactor
        self.margin = button_margin
        # Left is automatically modified by the margin; was running into issues with updating left at a later date, this was the easiest solution.
        self.left = left
        self.top = top
        self.label = ToggleButton(self.interactor,
                                  label,
                                  on=self.__on__,
                                  off=self.__off__,
                                  on_prefix=open_label,
                                  off_prefix=close_label,
                                  left=self.left - self.margin,
                                  top=self.top)
        self.on_open = on_open
        self.vertical = vertical

        self.open = False

        # Increment this as widgets are added
        self.width, self.height = self.label.get_dimensions()
        self.height += button_margin

        self.widgets = []
        self.bars = {}
        self.parent = parent

        self.__placing__ = False

    def get_text(self):
        return self.label.get_text()

    def in_toolbar(self, x, y):
        width, top = self.interactor.GetRenderWindow().GetSize()
        if x > self.left and x < self.left + self.width and y < top and y > top - self.height:
            return True
        else:
            return False

    # Left property definition
    def __getleft(self):
        return self.__left

    def __setleft(self, left):
        self.__left = left + self.margin

    def __delleft(self):
        del self.__left

    left = property(__getleft, __setleft, __delleft,
                    "The Left property, modified by the margin")

    def __on__(self):
        self.open = True
        if self.on_open is not None:
            self.on_open()
        self.show_widgets()

    def __off__(self):
        self.open = False
        self.hide_widgets()

    def copy(self, interactor):
        t = Toolbar(interactor,
                    self.label.label,
                    vertical=self.vertical,
                    left=self.left - self.margin,
                    top=self.top,
                    button_margin=self.margin)

        for widget in self.widgets:
            t.widgets.append(widget.copy(interactor))

        if self.label.get_state() == 1:
            t.show_widgets()
            t.label.set_state(1)

        return t

    def place(self):

        if self.parent and self.__placing__ == False:
            # Navigate up the tree, work from the root
            self.parent.place()
            return

        self.label.left = self.left - self.margin
        self.label.top = self.top
        self.label.place()

        self.width, self.height = self.label.get_dimensions()

        if self.vertical:
            self.height += self.margin
        else:
            self.width += self.margin

        for widget in self.widgets:

            widget_width, widget_height = widget.get_dimensions()

            if self.vertical:
                widget.left = self.left
                widget.top = self.top + self.height
            else:
                widget.left = self.left + self.width
                widget.top = self.top

            widget.__placing__ = True
            widget.place()
            widget.__placing__ = False

            widget_width, widget_height = widget.get_dimensions()

            if self.vertical:
                self.height += widget_height + self.margin
            else:
                self.width += widget_width + self.margin

    def get_dimensions(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        if self.open:
            # Children are visible, width/height are correct
            return self.width, self.height
        else:
            # Children are invisible, use label dimensions
            return self.label.get_dimensions()

    def show(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        self.place()
        self.label.show()
        if self.open:
            self.show_widgets()

    def hide(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        self.label.hide()
        self.hide_widgets()

    def show_widgets(self):
        for widget in self.widgets:
            widget.show()

        self.place()

    def hide_widgets(self):
        """
        Hides all widgets in this toolbar

        Triggers a reflow of the toolbar tree
        """
        for button in self.widgets:
            button.hide()

        self.place()

    def detach(self):
        self.label.detach()
        for w in self.widgets:
            w.detach()

    def get_toolbar(self, label):
        """
        Retrieve a toolbar by label.

        Should probably use some other identifier, but this is the only one available right now.
        """
        return self.bars.get(label, None)

    """
    Convenience functions to add managed widgets to the toolbar.
    """

    def add_button(self, labels, **kwargs):

        states = [ButtonState(label=label) for label in labels]
        kwargs["states"] = states

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = Button(self.interactor, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b

    def add_toolbar(self, label, **kwargs):
        """
        Adds a toolbar using the same configs as this one has
        """
        kwargs["parent"] = self
        if self.vertical:
            kwargs["top"] = self.top + self.height + self.margin
            kwargs["left"] = self.left
        else:
            kwargs["top"] = self.top
            kwargs["left"] = self.left + self.width + self.margin
        kwargs["button_margin"] = self.margin

        if "vertical" not in kwargs:
            kwargs["vertical"] = self.vertical

        toolbar = Toolbar(self.interactor, label, **kwargs)

        if self.open:
            toolbar.label.show()

        if self.vertical:
            self.height += self.margin + toolbar.get_dimensions()[1]
        else:
            self.width += self.margin + toolbar.get_dimensions()[0]

        self.widgets.append(toolbar)
        self.bars[label] = toolbar
        return toolbar

    def add_toggle_button(self, label, **kwargs):

        _off = kwargs.get("off", None)
        _on = kwargs.get("on", None)

        def off():
            if _off:
                _off()
            if self.save:
                self.save()

        def on():
            if _on:
                _on()

        kwargs['off'] = off
        kwargs['on'] = on

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = ToggleButton(self.interactor, label, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b

    def add_slider_button(self, value, min_val, max_val, label, **kwargs):

        _end = kwargs.get("end", None)

        def end(val):

            if _end:
                _end(val)

            if self.save:
                self.save()

        _on_show = kwargs.get("on_show_slider", None)

        def on_show():
            self.hide_sliders()
            if _on_show:
                _on_show()

        kwargs["on_show_slider"] = on_show
        kwargs["end"] = end

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = SliderButton(self.interactor, value, min_val, max_val, label,
                         **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b

    def hide_sliders(self):
        for w in self.widgets:
            if type(w) == SliderButton:
                if w.slider.is_showing():
                    w.set_state(0)
                    w.off()
            if type(w) == Toolbar:
                w.hide_sliders()
Ejemplo n.º 11
0
    def __init__(self, appid, widget_display=[]):

        Statusbar.__init__(
            self,
            39,
        )

        self.appid = appid
        self.widget_display = widget_display
        self.widget_main_box = gtk.HBox()

        self.register_widgets = {}

        self.mute_button = ToggleButton(
            app_theme.get_pixbuf('mute/sound_normal.png'),
            app_theme.get_pixbuf('mute/mute_normal.png'),
            app_theme.get_pixbuf('mute/sound_hover.png'),
            app_theme.get_pixbuf('mute/mute_hover.png'),
            app_theme.get_pixbuf('mute/sound_press.png'),
            app_theme.get_pixbuf('mute/mute_press.png'),
            active_button_label=_('Volume'),
            inactive_button_label=_('Mute'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6)
        #self.mute_button.connect('clicked', self.mute_handler)
        mute_button_align = gtk.Alignment()
        mute_button_align.set(0, 0.5, 0, 0)
        mute_button_align.set_padding(3, 6, 3, 3)
        mute_button_align.add(self.mute_button)
        self.register_widgets["mute"] = mute_button_align

        self.favorite_button = ToggleButton(
            app_theme.get_pixbuf('favorite/unfavorite_normal.png'),
            app_theme.get_pixbuf('favorite/favorite_normal.png'),
            app_theme.get_pixbuf('favorite/unfavorite_hover.png'),
            app_theme.get_pixbuf('favorite/favorite_hover.png'),
            app_theme.get_pixbuf('favorite/unfavorite_press.png'),
            app_theme.get_pixbuf('favorite/favorite_press.png'),
            active_button_label=_('Favorite'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6)
        #self.favorite_button.connect('clicked', self.toggle_favorite)
        favorite_button_align = gtk.Alignment()
        favorite_button_align.set(0, 0.5, 0, 0)
        favorite_button_align.set_padding(3, 6, 3, 3)
        favorite_button_align.add(self.favorite_button)
        self.register_widgets['favorite'] = favorite_button_align

        self.replay_button = Button(
            app_theme.get_pixbuf('replay/replay_normal.png'),
            app_theme.get_pixbuf('replay/replay_hover.png'),
            app_theme.get_pixbuf('replay/replay_press.png'),
            button_label=_('Replay'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6)
        #self.replay_button.connect('clicked', self.replay_action)
        replay_button_align = gtk.Alignment()
        replay_button_align.set(0, 0.5, 0, 0)
        replay_button_align.set_padding(3, 6, 3, 3)
        replay_button_align.add(self.replay_button)
        self.register_widgets["replay"] = replay_button_align

        if LANGUAGE == 'en_US':
            more_width = 14
        else:
            more_width = 0
        self.pause_button = ToggleButton(
            app_theme.get_pixbuf('pause/pause_normal.png'),
            app_theme.get_pixbuf('pause/play_normal.png'),
            app_theme.get_pixbuf('pause/pause_hover.png'),
            app_theme.get_pixbuf('pause/play_hover.png'),
            app_theme.get_pixbuf('pause/pause_press.png'),
            app_theme.get_pixbuf('pause/play_press.png'),
            active_button_label=_('Pause'),
            inactive_button_label=_('Continue'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6,
            more_width=more_width)
        #self.pause_button.connect('button-press-event', self.pause_handler)
        pause_button_align = gtk.Alignment()
        pause_button_align.set(0, 0.5, 0, 0)
        pause_button_align.set_padding(3, 6, 10, 3)
        pause_button_align.add(self.pause_button)
        self.register_widgets["pause"] = pause_button_align

        self.fullscreen_button = ToggleButton(
            app_theme.get_pixbuf('fullscreen/fullscreen_normal.png'),
            app_theme.get_pixbuf('fullscreen/unfullscreen_normal.png'),
            app_theme.get_pixbuf('fullscreen/fullscreen_hover.png'),
            app_theme.get_pixbuf('fullscreen/unfullscreen_hover.png'),
            app_theme.get_pixbuf('fullscreen/fullscreen_press.png'),
            app_theme.get_pixbuf('fullscreen/unfullscreen_press.png'),
            active_button_label=_('Fullscreen'),
            inactive_button_label=_('Normal'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6)
        #self.fullscreen_button.connect('clicked', self.fullscreen_action)
        fullscreen_button_align = gtk.Alignment()
        fullscreen_button_align.set(0, 0.5, 0, 0)
        fullscreen_button_align.set_padding(3, 6, 3, 3)
        fullscreen_button_align.add(self.fullscreen_button)
        self.register_widgets["fullscreen"] = fullscreen_button_align

        self.share_button = Button(
            app_theme.get_pixbuf('share/share_normal.png'),
            app_theme.get_pixbuf('share/share_hover.png'),
            app_theme.get_pixbuf('share/share_press.png'),
            button_label=_('Share'),
            draw_background=True,
            padding_edge=10,
            padding_middle=6)
        #self.share_button.connect('clicked', self.share_action)
        share_button_align = gtk.Alignment()
        share_button_align.set(0, 0.5, 0, 0)
        share_button_align.set_padding(3, 6, 3, 3)
        share_button_align.add(self.share_button)
        self.register_widgets["share"] = share_button_align

        star_box = gtk.HBox()
        self.star = StarView()
        self.star.set_star_level(9)
        star_align = gtk.Alignment(0.5, 0.5, 0, 0)
        star_align.set_padding(2, 2, 3, 0)
        star_align.add(self.star)

        self.star_mark = Markbox(5.0, '#ffffff')
        star_mark_align = gtk.Alignment(0.5, 0, 0, 0)
        star_mark_align.set_padding(2, 4, 3, 20)
        star_mark_align.add(self.star_mark)

        star_box.pack_start(star_align)
        star_box.pack_start(star_mark_align)
        star_box_align = gtk.Alignment(1, 0.5, 0, 0)
        star_box_align.set_padding(0, 0, 3, 0)
        star_box_align.add(star_box)
        self.register_widgets["star"] = star_box_align

        if "pause" in self.widget_display:
            self.widget_main_box.pack_start(pause_button_align, False, False)
        #if "mute" in self.widget_display:
        #self.widget_main_box.pack_start(mute_button_align, False, False)
        if "replay" in self.widget_display:
            self.widget_main_box.pack_start(replay_button_align, False, False)
        if "favorite" in self.widget_display:
            self.widget_main_box.pack_start(favorite_button_align, False,
                                            False)
        if "fullscreen" in self.widget_display:
            self.widget_main_box.pack_start(fullscreen_button_align, False,
                                            False)
        if "share" in self.widget_display:
            self.widget_main_box.pack_start(share_button_align, False, False)
        if "star" in self.widget_display:
            self.widget_main_box.pack_end(star_box_align)

        self.status_box.pack_start(self.widget_main_box, True, True)

        self.leave_callback = None
        #self.connect('motion-notify-event', self.leave_event_handler)

        global_event.register_event('download-app-info-finish',
                                    self.update_star)
        global_event.register_event('set-star-score-success',
                                    self.score_success_handler)
        self.star.connect("button-press-event", self.star_press)

        self.cookie = get_cookie_star(self.appid)
        if self.cookie:
            self.star.set_read_only(True)
Ejemplo n.º 12
0
class Toolbar(object):

    def __init__(self, interactor, label, vertical=True, left=10, top=10, open_label="Open", on_open=None, close_label="Close", button_margin=5, parent=None, save=None):

        self.save = save
        self.interactor = interactor
        self.margin = button_margin
        # Left is automatically modified by the margin; was running into issues with updating left at a later date, this was the easiest solution.
        self.left = left
        self.top = top
        self.label = ToggleButton(self.interactor, label, on=self.__on__, off=self.__off__, on_prefix=open_label, off_prefix=close_label, left=self.left - self.margin, top=self.top)
        self.on_open = on_open
        self.vertical = vertical

        self.open = False

        # Increment this as widgets are added
        self.width, self.height = self.label.get_dimensions()
        self.height += button_margin

        self.widgets = []
        self.bars = {}
        self.parent = parent

        self.__placing__ = False

    def get_text(self):
        return self.label.get_text()

    def in_toolbar(self, x, y):
        width, top = self.interactor.GetRenderWindow().GetSize()
        if x > self.left and x < self.left + self.width and y < top and y > top - self.height:
            return True
        else:
            return False

    # Left property definition
    def __getleft(self):
        return self.__left
    def __setleft(self, left):
        self.__left = left + self.margin
    def __delleft(self):
        del self.__left
    left = property(__getleft, __setleft, __delleft, "The Left property, modified by the margin")

    def __on__(self):
        self.open = True
        if self.on_open is not None:
            self.on_open()
        self.show_widgets()

    def __off__(self):
        self.open = False
        self.hide_widgets()

    def copy(self, interactor):
        t = Toolbar(interactor, self.label.label, vertical=self.vertical, left=self.left - self.margin, top=self.top, button_margin=self.margin)

        for widget in self.widgets:
            t.widgets.append(widget.copy(interactor))

        if self.label.get_state() == 1:
            t.show_widgets()
            t.label.set_state(1)

        return t

    def place(self):

        if self.parent and self.__placing__ == False:
            # Navigate up the tree, work from the root
            self.parent.place()
            return

        self.label.left = self.left - self.margin
        self.label.top = self.top
        self.label.place()


        self.width, self.height = self.label.get_dimensions()

        if self.vertical:
            self.height += self.margin
        else:
            self.width += self.margin

        for widget in self.widgets:

            widget_width, widget_height = widget.get_dimensions()

            if self.vertical:
                widget.left = self.left
                widget.top = self.top + self.height
            else:
                widget.left = self.left + self.width
                widget.top = self.top

            widget.__placing__ = True
            widget.place()
            widget.__placing__ = False

            widget_width, widget_height = widget.get_dimensions()

            if self.vertical:
                self.height += widget_height + self.margin
            else:
                self.width += widget_width + self.margin

    def get_dimensions(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        if self.open:
            # Children are visible, width/height are correct
            return self.width, self.height
        else:
            # Children are invisible, use label dimensions
            return self.label.get_dimensions()

    def show(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        self.place()
        self.label.show()
        if self.open:
            self.show_widgets()

    def hide(self):
        """
        Widget shim; makes this behave the same as a button with regards to being layed out.
        """
        self.label.hide()
        self.hide_widgets()

    def show_widgets(self):
        for widget in self.widgets:
            widget.show()

        self.place()

    def hide_widgets(self):
        """
        Hides all widgets in this toolbar

        Triggers a reflow of the toolbar tree
        """
        for button in self.widgets:
            button.hide()

        self.place()

    def detach(self):
        self.label.detach()
        for w in self.widgets:
            w.detach()

    def get_toolbar(self, label):
        """
        Retrieve a toolbar by label.

        Should probably use some other identifier, but this is the only one available right now.
        """
        return self.bars.get(label, None)

    """
    Convenience functions to add managed widgets to the toolbar.
    """

    def add_button(self, labels, **kwargs):

        states = [ButtonState(label=label) for label in labels]
        kwargs["states"] = states

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = Button(self.interactor, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b



    def add_toolbar(self, label, **kwargs):
        """
        Adds a toolbar using the same configs as this one has
        """
        kwargs["parent"] = self
        if self.vertical:
            kwargs["top"] = self.top + self.height + self.margin
            kwargs["left"] = self.left
        else:
            kwargs["top"] = self.top
            kwargs["left"] = self.left + self.width + self.margin
        kwargs["button_margin"] = self.margin

        if "vertical" not in kwargs:
            kwargs["vertical"] = self.vertical

        toolbar = Toolbar(self.interactor, label, **kwargs)

        if self.open:
            toolbar.label.show()

        if self.vertical:
            self.height += self.margin + toolbar.get_dimensions()[1]
        else:
            self.width += self.margin + toolbar.get_dimensions()[0]

        self.widgets.append(toolbar)
        self.bars[label] = toolbar
        return toolbar

    def add_toggle_button(self, label, **kwargs):

        _off = kwargs.get("off", None)
        _on  = kwargs.get("on", None)

        def off():
            if _off:
                _off()
            if self.save:
                self.save()

        def on():
            if _on:
                _on()

        kwargs['off'] = off
        kwargs['on'] = on

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = ToggleButton(self.interactor, label, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b

    def add_slider_button(self, value, min_val, max_val, label, **kwargs):

        _end = kwargs.get("end", None)
        def end(val):

            if _end:
                _end(val)

            if self.save:
                self.save()

        _on_show = kwargs.get("on_show_slider", None)
        def on_show():
            self.hide_sliders()
            if _on_show:
                _on_show()

        kwargs["on_show_slider"] = on_show
        kwargs["end"] = end

        if self.vertical:
            kwargs["left"] = self.left
            kwargs["top"] = self.top + self.height + self.margin
        else:
            kwargs["left"] = self.left + self.width + self.margin
            kwargs["top"] = self.top

        b = SliderButton(self.interactor, value, min_val, max_val, label, **kwargs)

        if self.open:
            b.show()

        if self.vertical:
            self.height = kwargs["top"] + b.get_dimensions()[1]
        else:
            self.width = kwargs["left"] + b.get_dimensions()[0]

        self.widgets.append(b)
        return b

    def hide_sliders(self):
        for w in self.widgets:
            if type(w) == SliderButton:
                if w.slider.is_showing():
                    w.set_state(0)
                    w.off()
            if type(w) == Toolbar:
                w.hide_sliders()
Ejemplo n.º 13
0
    # Initialize starting variables
    start_vertex = None
    end_vertex = None
    run_once = True

    return (display_surface, surface, graph, maze_surface, maze_centered_width,
            maze_centered_height, start_vertex, end_vertex, run_once)


# Initialize variables from the initialize_maze call with the specified maze
display, surf, graph1, maze_img, \
    centered_w, centered_h, start, end, once = initialize_maze('mazes/maze.png')

# Initialize the GUI. This includes buttons, text boxes, drop down menus, timers, and counters.
start_button = ToggleButton((10, 10, 100, 50), 'Start', (0, 170, 0))
end_button = ToggleButton((110, 10, 100, 50), 'End', (170, 0, 0))
restart_button = Button((720, 10, 100, 50), 'Restart', (255, 0, 0))
iteration_counter_pos = (210, 10)
timer_pos = (210, 30)
algo_drop_down = DropDown(['Breadth First Search', 'Depth First Search', 'A*'],
                          (520, 10, 200, 50), display)
maze_drop_down = DropDown(['Maze 1', 'Maze 2', 'Maze 3', 'Other'],
                          (820, 10, 200, 50), display)
maze_drop_down_text_box = TextBox('', 'Enter File Name', (1025, 10, 150, 50),
                                  display)
draw_text_box = False

# Initialize the algorithm object
alg = PathfindingAlgorithms(iteration_counter_pos, centered_w, centered_h,
                            timer_pos)