Esempio n. 1
0
    def __init__(self, controls):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.scroll = Gtk.ScrolledWindow()
        self.scroll.add(self)
        self.scroll.set_border_width(0)
        viewport = self.scroll.get_child()
        viewport.set_shadow_type(Gtk.ShadowType.NONE)
        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        self.set_buttons_style()

        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label.new(""))
        self.show_all()
Esempio n. 2
0
    def __init__(self, controls):
        super(RadioPerspective, self).__init__()

        self.auto_radio = RadioTreeControl(controls)
        self.my_radio = MyRadioTreeControl(controls)

        self.switch_button = Gtk.Button.new()
        self.switch_button.connect("clicked", self.switch_radio)

        self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.radios = StackableWidget()
        self.radios.add(self.auto_radio.scroll)
        self.radios.add(self.my_radio.scroll)

        self.vbox.pack_start(self.radios, True, True, 0)
        self.vbox.pack_start(self.switch_button, False, False, 0)
        self.vbox.show_all()

        self.update_button_label()
Esempio n. 3
0
    def __init__(self, controls):
        super(Controller, self).__init__(False, 0)

        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.HBox(False, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label(""))
        self.show_all()
Esempio n. 4
0
    def __init__(self, controls):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.scroll = Gtk.ScrolledWindow()
        self.scroll.add(self)
        self.scroll.set_border_width(0)
        viewport = self.scroll.get_child()
        viewport.set_shadow_type(Gtk.ShadowType.NONE)
        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}

        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label.new(""))
        self.show_all()
Esempio n. 5
0
    def __init__(self, controls):
        super(Controller, self).__init__(False, 0)

        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.HBox(False, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label(""))
        self.show_all()
Esempio n. 6
0
    def __init__(self, controls):
        super(RadioPerspective, self).__init__()

        self.auto_radio = RadioTreeControl(controls)
        self.my_radio = MyRadioTreeControl(controls)

        self.switch_button = Gtk.Button()
        self.switch_button.connect("clicked", self.switch_radio)

        self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.radios = StackableWidget()
        self.radios.add(self.auto_radio.scroll)
        self.radios.add(self.my_radio.scroll)

        self.vbox.pack_start(self.radios, True, True, 0)
        self.vbox.pack_start(self.switch_button, False, False, 0)
        self.vbox.show_all()

        self.update_button_label()
Esempio n. 7
0
class Controller(Gtk.VBox, LoadSave, Quitable, Filterable):

    def __init__(self, controls):
        super(Controller, self).__init__(False, 0)

        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.HBox(False, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label(""))
        self.show_all()

    def attach_perspective(self, perspective):
        assert isinstance(perspective, BasePerspective)
        perspective_id = perspective.get_id()
        self.perspectives[perspective_id] = perspective
        self._perspectives.append(perspective)
        widget = perspective.get_widget()
        perspective.widget_id = self.perspectives_container.add(widget)
        button = PerspectiveButton(perspective.get_name(), perspective.get_icon(), perspective.get_tooltip())

        def toggle_handler(btn, handler, *args):
            if btn.get_active():
                handler()
        button.connect("toggled", toggle_handler, lambda *a: self.activate_perspective(perspective_id))
        perspective.button = button
        self.button_container.pack_start(button, False, False, 0)
        self.button_controller.add_button(button)

    def activate_perspective(self, perspective_id):
        if self.is_activated(perspective_id):
            return
        perspective = self.get_perspective(perspective_id)
        assert perspective
        for _id in self.perspectives.keys():
            if self.is_activated(_id):
                self.get_perspective(_id).emit("deactivated")
        self.perspectives_container.set_active_by_index(perspective.widget_id)
        perspective.button.set_active(True)
        if isinstance(perspective, Filterable):
            self.filter.show()
        else:
            self.filter.hide()
        perspective.emit("activated")
        analytics.action("PERSPECTIVE_" + perspective.get_id())
        self.check_availability()

    def check_availability(self):
        for perspective in self._perspectives:
            if not perspective.is_available():
                perspective.button.set_sensitive(False)
                perspective.button.set_tooltip_text("Not available")
                if self.is_activated(perspective.get_id()):
                    self.activate_perspective(self._perspectives[0].get_id())
            else:
                perspective.button.set_sensitive(True)
                perspective.button.set_tooltip_text(perspective.get_tooltip())

    def is_activated(self, perspective_id):
        perspective = self.get_perspective(perspective_id)
        assert perspective
        return perspective.widget_id == self.perspectives_container.get_active_index()

    def get_perspective(self, perspective_id):
        if perspective_id in self.perspectives:
            return self.perspectives[perspective_id]
        return None

    def filter_by_file(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_file(value)

    def filter_by_folder(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_folder(value)

    def on_load(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_load()
        self.activate_perspective(self._perspectives[0].get_id())

    def on_save(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_save()

    def on_quit(self):
        for perspective in self._perspectives:
            if isinstance(perspective, Quitable):
                perspective.on_quit()
Esempio n. 8
0
class RadioPerspective(BasePerspective, Filterable, Quitable):

    def __init__(self, controls):
        super(RadioPerspective, self).__init__()

        self.auto_radio = RadioTreeControl(controls)
        self.my_radio = MyRadioTreeControl(controls)

        self.switch_button = Gtk.Button()
        self.switch_button.connect("clicked", self.switch_radio)

        self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.radios = StackableWidget()
        self.radios.add(self.auto_radio.scroll)
        self.radios.add(self.my_radio.scroll)

        self.vbox.pack_start(self.radios, True, True, 0)
        self.vbox.pack_start(self.switch_button, False, False, 0)
        self.vbox.show_all()

        self.update_button_label()

    def switch_radio(self, *args):
        index = self.radios.get_active_index()
        new_index = abs(index - 1)
        self.radios.set_active_by_index(new_index)
        self.update_button_label()

    def update_button_label(self):
        index = self.radios.get_active_index()
        radio = self.radios.get_nth_page(index)
        self.switch_button.set_label(radio.get_child().switcher_label)

    def get_id(self):
        return "radio"

    def get_icon(self):
        return "network-idle"

    def get_name(self):
        return _("Radio")

    def get_tooltip(self):
        return _("Radio Stantions (Alt+2)")

    def get_widget(self):
        return self.vbox

    ## LoadSave implementation
    def on_load(self):
        self.auto_radio.on_load()
        self.my_radio.on_load()

    def on_save(self):
        self.auto_radio.on_save()
        self.my_radio.on_save()

    ## Quitable implementation
    def on_quit(self):
        self.auto_radio.on_quit()
        self.my_radio.on_quit()

    ## Filterable implementation
    def filter_by_folder(self, value):
        self.auto_radio.filter_by_folder(value)
        self.my_radio.filter_by_folder(value)

    def filter_by_file(self, value):
        self.auto_radio.filter_by_file(value)
        self.my_radio.filter_by_file(value)
Esempio n. 9
0
class RadioPerspective(BasePerspective, Filterable, Quitable):
    def __init__(self, controls):
        super(RadioPerspective, self).__init__()

        self.auto_radio = RadioTreeControl(controls)
        self.my_radio = MyRadioTreeControl(controls)

        self.switch_button = Gtk.Button.new()
        self.switch_button.connect("clicked", self.switch_radio)

        self.vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.radios = StackableWidget()
        self.radios.add(self.auto_radio.scroll)
        self.radios.add(self.my_radio.scroll)

        self.vbox.pack_start(self.radios, True, True, 0)
        self.vbox.pack_start(self.switch_button, False, False, 0)
        self.vbox.show_all()

        self.update_button_label()

    def switch_radio(self, *args):
        index = self.radios.get_active_index()
        new_index = abs(index - 1)
        self.radios.set_active_by_index(new_index)
        self.update_button_label()

    def update_button_label(self):
        index = self.radios.get_active_index()
        radio = self.radios.get_nth_page(index)
        self.switch_button.set_label(radio.get_child().switcher_label)

    def get_id(self):
        return "radio"

    def get_icon(self):
        return "network-idle"

    def get_name(self):
        return _("Radio")

    def get_tooltip(self):
        return _("Radio Stantions (Alt+2)")

    def get_widget(self):
        return self.vbox

    ## LoadSave implementation
    def on_load(self):
        self.auto_radio.on_load()
        self.my_radio.on_load()

    def on_save(self):
        self.auto_radio.on_save()
        self.my_radio.on_save()

    ## Quitable implementation
    def on_quit(self):
        self.auto_radio.on_quit()
        self.my_radio.on_quit()

    ## Filterable implementation
    def filter_by_folder(self, value):
        self.auto_radio.filter_by_folder(value)
        self.my_radio.filter_by_folder(value)

    def filter_by_file(self, value):
        self.auto_radio.filter_by_file(value)
        self.my_radio.filter_by_file(value)
Esempio n. 10
0
class Controller(Gtk.VBox, LoadSave, Quitable, Filterable):
    def __init__(self, controls):
        super(Controller, self).__init__(False, 0)

        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.HBox(False, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label(""))
        self.show_all()

    def attach_perspective(self, perspective):
        assert isinstance(perspective, BasePerspective)
        perspective_id = perspective.get_id()
        self.perspectives[perspective_id] = perspective
        self._perspectives.append(perspective)
        widget = perspective.get_widget()
        perspective.widget_id = self.perspectives_container.add(widget)
        button = PerspectiveButton(perspective.get_name(),
                                   perspective.get_icon(),
                                   perspective.get_tooltip())

        def toggle_handler(btn, handler, *args):
            if btn.get_active():
                handler()

        button.connect("toggled", toggle_handler,
                       lambda *a: self.activate_perspective(perspective_id))
        perspective.button = button
        self.button_container.pack_start(button, False, False, 0)
        self.button_controller.add_button(button)

    def activate_perspective(self, perspective_id):
        if self.is_activated(perspective_id):
            return
        perspective = self.get_perspective(perspective_id)
        assert perspective
        for _id in self.perspectives.keys():
            if self.is_activated(_id):
                self.get_perspective(_id).emit("deactivated")
        self.perspectives_container.set_active_by_index(perspective.widget_id)
        perspective.button.set_active(True)
        if isinstance(perspective, Filterable):
            self.filter.show()
        else:
            self.filter.hide()
        perspective.emit("activated")
        analytics.action("PERSPECTIVE_" + perspective.get_id())
        self.check_availability()

    def check_availability(self):
        for perspective in self._perspectives:
            if not perspective.is_available():
                perspective.button.set_sensitive(False)
                perspective.button.set_tooltip_text("Not available")
                if self.is_activated(perspective.get_id()):
                    self.activate_perspective(self._perspectives[0].get_id())
            else:
                perspective.button.set_sensitive(True)
                perspective.button.set_tooltip_text(perspective.get_tooltip())

    def is_activated(self, perspective_id):
        perspective = self.get_perspective(perspective_id)
        assert perspective
        return perspective.widget_id == self.perspectives_container.get_active_index(
        )

    def get_perspective(self, perspective_id):
        if perspective_id in self.perspectives:
            return self.perspectives[perspective_id]
        return None

    def filter_by_file(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_file(value)

    def filter_by_folder(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_folder(value)

    def on_load(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_load()
        self.activate_perspective(self._perspectives[0].get_id())

    def on_save(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_save()

    def on_quit(self):
        for perspective in self._perspectives:
            if isinstance(perspective, Quitable):
                perspective.on_quit()
Esempio n. 11
0
class Controller(Gtk.Box, LoadSave, Quitable, Filterable):

    def __init__(self, controls):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.scroll = Gtk.ScrolledWindow()
        self.scroll.add(self)
        self.scroll.set_border_width(0)
        viewport = self.scroll.get_child()
        viewport.set_shadow_type(Gtk.ShadowType.NONE)
        self.perspectives_container = StackableWidget()
        self.button_container = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        self.button_controller = OneButtonToggled()
        self.perspectives = {}
        self.set_buttons_style()

        ## internal property
        self._perspectives = []

        self.filter = FilterControl(self)

        self.pack_start(self.perspectives_container, True, True, 0)
        self.pack_start(self.filter, False, False, 0)
        self.pack_start(self.button_container, False, False, 0)

        ## insert dummy page
        self.perspectives_container.add(Gtk.Label.new(""))
        self.show_all()

    def set_buttons_style(self):
        self.set_name("perspective")
        provider = Gtk.CssProvider.new()
        Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

        provider.load_from_data("""
                                    #perspective .button {
                                        padding-left: 5px;
                                        padding-right: 5px;
                                    } """)

    def attach_perspective(self, perspective):
        assert isinstance(perspective, BasePerspective)
        perspective_id = perspective.get_id()
        self.perspectives[perspective_id] = perspective
        self._perspectives.append(perspective)
        widget = perspective.get_widget()
        perspective.widget_id = self.perspectives_container.add(widget)
        button = PerspectiveButton(perspective.get_name(), perspective.get_icon(), perspective.get_tooltip())

        def toggle_handler(btn, handler, *args):
            if btn.get_active():
                handler()
        button.connect("toggled", toggle_handler, lambda *a: self.activate_perspective(perspective_id))
        perspective.button = button
        self.button_container.pack_start(button, False, False, 0)
        self.button_controller.add_button(button)

    def activate_perspective(self, perspective_id):
        if self.is_activated(perspective_id):
            return
        perspective = self.get_perspective(perspective_id)
        assert perspective
        for _id in self.perspectives.keys():
            if self.is_activated(_id):
                self.get_perspective(_id).emit("deactivated")
        self.perspectives_container.set_active_by_index(perspective.widget_id)
        perspective.button.set_active(True)
        if isinstance(perspective, Filterable):
            self.filter.show()
        else:
            self.filter.hide()
        perspective.emit("activated")
        analytics.action("PERSPECTIVE_" + perspective.get_id())
        self.check_availability()

    def check_availability(self):
        for perspective in self._perspectives:
            if not perspective.is_available():
                perspective.button.set_sensitive(False)
                perspective.button.set_tooltip_text("Not available")
                if self.is_activated(perspective.get_id()):
                    self.activate_perspective(self._perspectives[0].get_id())
            else:
                perspective.button.set_sensitive(True)
                perspective.button.set_tooltip_text(perspective.get_tooltip())

    def is_activated(self, perspective_id):
        perspective = self.get_perspective(perspective_id)
        assert perspective
        return perspective.widget_id == self.perspectives_container.get_active_index()

    def get_perspective(self, perspective_id):
        if perspective_id in self.perspectives:
            return self.perspectives[perspective_id]
        return None

    def filter_by_file(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_file(value)

    def filter_by_folder(self, value):
        for perspective in self._perspectives:
            if isinstance(perspective, Filterable):
                perspective.filter_by_folder(value)

    def on_load(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_load()
        self.activate_perspective(self._perspectives[0].get_id())

    def on_save(self):
        for perspective in self._perspectives:
            if isinstance(perspective, LoadSave):
                perspective.on_save()

    def on_quit(self):
        for perspective in self._perspectives:
            if isinstance(perspective, Quitable):
                perspective.on_quit()