Ejemplo n.º 1
0
    def __init__(self, controls):
        FControl.__init__(self, controls)

        controls = self.controls
        self.configs.append(MusicLibraryConfig(controls))
        self.configs.append(TabsConfig(controls))
        self.configs.append(LastFmConfig(controls))
        self.configs.append(TrayIconConfig(controls))
        self.configs.append(NetworkConfig(controls))

        try:
            """check keybinder installed, debian"""
            import gi
            gi.require_version('Keybinder', '3.0')
            from gi.repository import Keybinder  #@UnresolvedImport @UnusedImport
            from foobnix.preferences.configs.hotkey_conf import HotKeysConfig
            self.configs.append(HotKeysConfig(controls))
        except Exception as e:
            logging.warn("Keybinder not installed" + str(e))

        self.configs.append(OtherConfig(controls))

        self.label = None

        mainVBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)

        ChildTopWindow.__init__(self, _("Preferences"), 900, 550)

        paned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
        paned.set_position(250)

        def func():
            bean = self.navigation.get_selected_bean()
            if bean:
                self.populate_config_category(bean.text)

        self.navigation = SimpleListTreeControl(_("Categories"), controls,
                                                True)

        for plugin in self.configs:
            self.navigation.append(FDModel(plugin.name))

        self.navigation.set_left_click_func(func)

        paned.add1(self.navigation.scroll)

        cbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        for plugin in self.configs:
            cbox.pack_start(plugin.widget, False, True, 0)

        self._container = self.create_container(cbox)
        paned.add2(self._container)

        mainVBox.pack_start(paned, True, True, 0)
        mainVBox.pack_start(self.create_save_cancel_buttons(), False, False, 0)

        #self.add(mainVBox)
        GLib.idle_add(self.add, mainVBox)
Ejemplo n.º 2
0
    def dirs(self):
        frame_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        frame_box.set_border_width(5)
        frame_box.show()
        self.frame = FrameDecorator(_("Music dirs"),
                                    frame_box,
                                    0.5,
                                    0.5,
                                    border_width=0)
        self.frame.show()
        self.frame.set_no_show_all(True)

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)
        """buttons"""
        button_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        button_box.show()

        bt_add = Gtk.Button.new_with_label(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button.new_with_label(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label.new("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame
Ejemplo n.º 3
0
    def formats(self):
        frame_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        frame = FrameDecorator(_("File Types"),
                               frame_box,
                               0.5,
                               0.5,
                               border_width=0)
        frame.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)
        """buttons"""
        button_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        button_box.show()

        bt_add = Gtk.Button.new_with_label(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button.new_with_label(_("Remove"))
        bt_remove.connect("clicked",
                          lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC,
                               Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        return frame
Ejemplo n.º 4
0
    def dirs(self):
        self.frame = Gtk.Frame(label=_("Music dirs"))
        self.frame.set_border_width(0)
        self.frame.show()
        self.frame.set_no_show_all(True)
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)
        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        self.frame.add(frame_box)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame
Ejemplo n.º 5
0
    def formats(self):
        frame = Gtk.Frame(label=_("File Types"))
        frame.set_border_width(0)
        frame.show()

        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)
        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked",
                          lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC,
                               Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        frame.add(frame_box)

        return frame
Ejemplo n.º 6
0
    def dirs(self):
        self.frame = Gtk.Frame(label=_("Music dirs"))
        self.frame.set_border_width(0)
        self.frame.show()
        self.frame.set_no_show_all(True)
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        self.frame.add(frame_box)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame
Ejemplo n.º 7
0
    def formats(self):
        frame = Gtk.Frame(label=_("File Types"))
        frame.set_border_width(0)
        frame.show()

        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        frame.add(frame_box)

        return frame
Ejemplo n.º 8
0
    def dirs(self):
        frame_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        frame_box.set_border_width(5)
        frame_box.show()
        self.frame = FrameDecorator(_("Music dirs"), frame_box, 0.5, 0.5, border_width=0)
        self.frame.show()
        self.frame.set_no_show_all(True)

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)

        """buttons"""
        button_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        button_box.show()

        bt_add = Gtk.Button.new_with_label(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button.new_with_label(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label.new("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame
Ejemplo n.º 9
0
    def formats(self):
        frame_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        frame = FrameDecorator(_("File Types"), frame_box, 0.5, 0.5, border_width=0)
        frame.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)

        """buttons"""
        button_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        button_box.show()

        bt_add = Gtk.Button.new_with_label(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button.new_with_label(_("Remove"))
        bt_remove.connect("clicked", lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        return frame
Ejemplo n.º 10
0
class MusicLibraryConfig(ConfigPlugin, FControl):
    name = CONFIG_MUSIC_LIBRARY
    enable = True

    def __init__(self, controls):
        FControl.__init__(self, controls)

        box = Gtk.VBox(False, 0)
        box.hide()
        box.pack_start(self.tabs_mode(), False, True, 0)
        box.pack_start(self.dirs(), False, True, 0)
        box.pack_start(self.formats(), False, True, 0)

        self.widget = box
        uhbox = Gtk.HBox()
        ulabel = Gtk.Label(_("Update library on start (more slow) "))
        self.update_on_start = Gtk.CheckButton()

        uhbox.pack_start(ulabel, False, True, 0)
        uhbox.pack_start(self.update_on_start, False, False, 0)
        box.pack_start(uhbox, False, True, 0)
        box.pack_start(self.gap(), False, True, 0)
        box.pack_start(self.buffer_size(), False, True, 0)

    def dirs(self):
        self.frame = Gtk.Frame(label=_("Music dirs"))
        self.frame.set_border_width(0)
        self.frame.show()
        self.frame.set_no_show_all(True)
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)
        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        self.frame.add(frame_box)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame

    def reload_dir(self, *a):
        FCache(
        ).music_paths[0] = self.temp_music_paths[:]  #create copy of list
        self.controls.update_music_tree()

    def on_load(self):
        self.tree_controller.clear_tree()
        for path in FCache().music_paths[0]:
            self.tree_controller.append(
                FDModel(os.path.basename(path), path).add_is_file(False))

        self.files_controller.clear_tree()
        for ext in FC().all_support_formats:
            self.files_controller.append(FDModel(ext))

        self.adjustment.set_value(FC().gap_secs)
        self.buffer_adjustment.set_value(FC().network_buffer_size)

        if FC().tabs_mode == "Single":
            self.singletab_button.set_active(True)
            self.controls.perspectives.get_perspective(
                'fs').get_tabhelper().set_show_tabs(False)

        if FC().update_tree_on_start:
            self.update_on_start.set_active(True)

        self.temp_music_paths = FCache(
        ).music_paths[0][:]  #create copy of list

    def on_save(self):
        FC().all_support_formats = self.files_controller.get_all_beans_text()
        FC().gap_secs = self.adjustment.get_value()
        FC().network_buffer_size = self.buffer_adjustment.get_value()
        if self.singletab_button.get_active():
            '''for i in xrange(len(FCache().music_paths) - 1, 0, -1):
                del FCache().music_paths[i]
                del FCache().cache_music_tree_beans[i]
                del FCache().tab_names[i]
                self.controls.tabhelper.remove_page(i)'''
            FC().tabs_mode = "Single"
            self.controls.perspectives.get_perspective(
                'fs').get_tabhelper().set_show_tabs(False)
            if self.temp_music_paths != FCache().music_paths[0]:
                self.reload_dir()

        else:
            FC().tabs_mode = "Multi"
            self.controls.perspectives.get_perspective(
                'fs').get_tabhelper().set_show_tabs(True)
        if self.update_on_start.get_active():
            FC().update_tree_on_start = True
        else:
            FC().update_tree_on_start = False

    def add_dir(self, *a):
        current_folder = FCache().last_music_path if FCache(
        ).last_music_path else None
        paths = directory_chooser_dialog(_("Choose directory with music"),
                                         current_folder)
        if not paths:
            return
        path = paths[0]
        FCache().last_music_path = path[:path.rfind("/")]
        for path in paths:
            if path not in self.temp_music_paths:
                self.tree_controller.append(
                    FDModel(os.path.basename(path), path).add_is_file(False))
                self.temp_music_paths.append(path)

    def remove_dir(self, *a):
        selection = self.tree_controller.get_selection()
        fm, paths = selection.get_selected_rows()  #@UnusedVariable
        paths.reverse()
        for path in paths:
            del FCache().music_paths[0][path[0]]
            del FCache().cache_music_tree_beans[0][path[0]]

        self.tree_controller.delete_selected()
        remaining_beans = self.tree_controller.get_all_beans()
        if remaining_beans:
            self.temp_music_paths = [
                bean.path for bean in self.tree_controller.get_all_beans()
            ]
        else:
            self.temp_music_paths = []

    def formats(self):
        frame = Gtk.Frame(label=_("File Types"))
        frame.set_border_width(0)
        frame.show()

        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)
        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked",
                          lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC,
                               Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        frame.add(frame_box)

        return frame

    def on_add_file(self, *a):
        val = show_entry_dialog(_("Please add audio extension"),
                                _("Extension should be like '.mp3'"))
        if val and val.find(".") >= 0 and len(
                val
        ) <= 5 and val not in self.files_controller.get_all_beans_text():
            self.files_controller.append(FDModel(val))
        else:
            logging.info("Can't add your value" + val)

    def gap(self):
        label = Gtk.Label(_("Gap between tracks"))

        self.adjustment = Gtk.Adjustment(value=0,
                                         lower=0,
                                         upper=5,
                                         step_incr=0.5)

        gap_len = Gtk.SpinButton(adjustment=self.adjustment,
                                 climb_rate=0.0,
                                 digits=1)
        gap_len.show()

        hbox = Gtk.HBox(False, 10)
        hbox.pack_start(gap_len, False, False, 0)
        hbox.pack_start(label, False, False, 0)
        hbox.show_all()

        return hbox

    def buffer_size(self):
        label = Gtk.Label(_("Buffer size for network streams (KBytes)"))

        self.buffer_adjustment = Gtk.Adjustment(value=128,
                                                lower=16,
                                                upper=2048,
                                                step_incr=16)

        buff_size = Gtk.SpinButton(adjustment=self.buffer_adjustment,
                                   climb_rate=0,
                                   digits=0)
        buff_size.show()

        hbox = Gtk.HBox(False, 10)
        hbox.pack_start(buff_size, False, False, 0)
        hbox.pack_start(label, False, False, 0)
        hbox.show_all()

        return hbox

    def tabs_mode(self):
        hbox = Gtk.HBox()
        self.multitabs_button = Gtk.RadioButton(None, _("Multi tab mode"))

        def on_toggle_multitab(widget, data=None):
            self.frame.hide()

        self.multitabs_button.connect("toggled", on_toggle_multitab)
        hbox.pack_start(self.multitabs_button, True, False, 0)

        self.singletab_button = Gtk.RadioButton.new_with_label_from_widget(
            self.multitabs_button, _("Single tab mode"))

        def on_toggle_singletab(widget, data=None):
            self.tree_controller.clear_tree()
            for path in FCache().music_paths[0]:
                self.tree_controller.append(
                    FDModel(os.path.basename(path), path).add_is_file(False))
            self.temp_music_paths = FCache().music_paths[0][:]
            self.frame.show()

        self.singletab_button.connect("toggled", on_toggle_singletab)
        hbox.pack_end(self.singletab_button, True, False, 0)
        return hbox
Ejemplo n.º 11
0
class MusicLibraryConfig(ConfigPlugin, FControl):
    name = CONFIG_MUSIC_LIBRARY
    enable = True

    def __init__(self, controls):
        FControl.__init__(self, controls)

        box = Gtk.VBox(False, 0)
        box.hide()
        box.pack_start(self.tabs_mode(), False, True, 0)
        box.pack_start(self.dirs(), False, True, 0)
        box.pack_start(self.formats(), False, True, 0)

        self.widget = box
        uhbox = Gtk.HBox()
        ulabel = Gtk.Label(_("Update library on start (more slow) "))
        self.update_on_start = Gtk.CheckButton()

        uhbox.pack_start(ulabel, False, True, 0)
        uhbox.pack_start(self.update_on_start, False, False, 0)
        box.pack_start(uhbox, False, True, 0)
        box.pack_start(self.gap(), False, True, 0)

    def dirs(self):
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()
        self.frame = FrameDecorator(_("Music dirs"), frame_box, 0.5, 0.5, border_width=0)
        self.frame.show()
        self.frame.set_no_show_all(True)

        self.tree_controller = SimpleListTreeControl(_("Paths"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.add_dir)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", self.remove_dir)
        bt_remove.set_size_request(80, -1)
        bt_remove.show()

        empty = Gtk.Label("")
        empty.show()

        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)
        button_box.pack_start(empty, True, True, 0)

        self.tree_controller.scroll.show_all()
        frame_box.pack_start(self.tree_controller.scroll, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        if FC().tabs_mode == "Multi":
            self.frame.hide()
        return self.frame

    def reload_dir(self, *a):
        FCache().music_paths[0] = self.temp_music_paths[:] #create copy of list
        self.controls.update_music_tree()

    def on_load(self):
        self.tree_controller.clear_tree()
        for path in FCache().music_paths[0]:
            self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))

        self.files_controller.clear_tree()
        for ext in FC().all_support_formats:
            self.files_controller.append(FDModel(ext))

        self.adjustment.set_value(FC().gap_secs)

        if FC().tabs_mode == "Single":
            self.singletab_button.set_active(True)
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(False)

        if FC().update_tree_on_start:
            self.update_on_start.set_active(True)

        self.temp_music_paths = FCache().music_paths[0][:] #create copy of list

    def on_save(self):
        FC().all_support_formats = self.files_controller.get_all_beans_text()
        FC().gap_secs = self.adjustment.get_value()

        if self.singletab_button.get_active():
            '''for i in xrange(len(FCache().music_paths) - 1, 0, -1):
                del FCache().music_paths[i]
                del FCache().cache_music_tree_beans[i]
                del FCache().tab_names[i]
                self.controls.tabhelper.remove_page(i)'''
            FC().tabs_mode = "Single"
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(False)
            if self.temp_music_paths != FCache().music_paths[0]:
                self.reload_dir()

        else:
            FC().tabs_mode = "Multi"
            self.controls.perspectives.get_perspective('fs').get_tabhelper().set_show_tabs(True)
        if self.update_on_start.get_active():
            FC().update_tree_on_start = True
        else:
            FC().update_tree_on_start = False

    def add_dir(self, *a):
        current_folder = FCache().last_music_path if FCache().last_music_path else None
        paths = directory_chooser_dialog(_("Choose directory with music"), current_folder)
        if not paths:
            return
        path = paths[0]
        FCache().last_music_path = path[:path.rfind("/")]
        for path in paths:
            if path not in self.temp_music_paths:
                self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
                self.temp_music_paths.append(path)

    def remove_dir(self, *a):
        selection = self.tree_controller.get_selection()
        fm, paths = selection.get_selected_rows()#@UnusedVariable
        paths.reverse()
        for path in paths:
            del FCache().music_paths[0][path[0]]
            del FCache().cache_music_tree_beans[0][path[0]]

        self.tree_controller.delete_selected()
        remaining_beans = self.tree_controller.get_all_beans()
        if remaining_beans:
            self.temp_music_paths = [bean.path for bean in self.tree_controller.get_all_beans()]
        else:
            self.temp_music_paths = []

    def formats(self):
        frame_box = Gtk.HBox(False, 0)
        frame_box.set_border_width(5)
        frame_box.show()

        frame = FrameDecorator(_("File Types"), frame_box, 0.5, 0.5, border_width=0)
        frame.show()

        self.files_controller = SimpleListTreeControl(_("Extensions"), None)

        """buttons"""
        button_box = Gtk.VBox(False, 0)
        button_box.show()

        bt_add = Gtk.Button(_("Add"))
        bt_add.connect("clicked", self.on_add_file)
        bt_add.set_size_request(80, -1)
        bt_add.show()

        bt_remove = Gtk.Button(_("Remove"))
        bt_remove.connect("clicked", lambda *a: self.files_controller.delete_selected())
        bt_remove.set_size_request(80, -1)
        bt_remove.show()
        button_box.pack_start(bt_add, False, False, 0)
        button_box.pack_start(bt_remove, False, False, 0)

        scrool_tree = Gtk.ScrolledWindow()
        scrool_tree.set_size_request(-1, 160)
        scrool_tree.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrool_tree.add_with_viewport(self.files_controller.scroll)
        scrool_tree.show()

        frame_box.pack_start(scrool_tree, True, True, 0)
        frame_box.pack_start(button_box, False, False, 0)

        return frame

    def on_add_file(self, *a):
        val = show_entry_dialog(_("Please add audio extension"), _("Extension should be like '.mp3'"))
        if val and val.find(".") >= 0 and len(val) <= 5 and val not in self.files_controller.get_all_beans_text():
            self.files_controller.append(FDModel(val))
        else:
            logging.info("Can't add your value" + val)

    def gap(self):
        label = Gtk.Label(_("Gap between tracks"))

        self.adjustment = Gtk.Adjustment(value=0, lower=0, upper=5, step_incr=0.5)

        gap_len = Gtk.SpinButton(adjustment=self.adjustment, climb_rate=0.0, digits=1)
        gap_len.show()

        hbox = Gtk.HBox(False, 10)
        hbox.pack_start(gap_len, False, False, 0)
        hbox.pack_start(label, False, False, 0)
        hbox.show_all()

        return hbox

    def tabs_mode(self):
        hbox = Gtk.HBox()
        self.multitabs_button = Gtk.RadioButton.new_with_label(None, _("Multi tab mode"))
        def on_toggle_multitab(widget, data=None):
            self.frame.hide()
        self.multitabs_button.connect("toggled", on_toggle_multitab)
        hbox.pack_start(self.multitabs_button, True, False, 0)

        self.singletab_button = Gtk.RadioButton.new_with_label_from_widget(self.multitabs_button, _("Single tab mode"))
        def on_toggle_singletab(widget, data=None):
            self.tree_controller.clear_tree()
            for path in FCache().music_paths[0]:
                self.tree_controller.append(FDModel(os.path.basename(path), path).add_is_file(False))
            self.temp_music_paths = FCache().music_paths[0][:]
            self.frame.show()
        self.singletab_button.connect("toggled", on_toggle_singletab)
        hbox.pack_end(self.singletab_button, True, False, 0)
        return hbox
Ejemplo n.º 12
0
class PreferencesWindow(ChildTopWindow, FControl, LoadSave):

    configs = []
    POS_NAME = 0

    def __init__(self, controls):
        FControl.__init__(self, controls)

        controls = self.controls
        self.configs.append(MusicLibraryConfig(controls))
        self.configs.append(TabsConfig(controls))
        self.configs.append(LastFmConfig(controls))
        self.configs.append(TrayIconConfig(controls))
        self.configs.append(NetworkConfig(controls))

        try:
            """check keybinder installed, debian"""
            import gi
            gi.require_version('Keybinder', '3.0')
            from gi.repository import Keybinder  #@UnresolvedImport @UnusedImport
            from foobnix.preferences.configs.hotkey_conf import HotKeysConfig
            self.configs.append(HotKeysConfig(controls))
        except Exception as e:
            logging.warn("Keybinder not installed" + str(e))

        self.configs.append(OtherConfig(controls))

        self.label = None

        mainVBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)

        ChildTopWindow.__init__(self, _("Preferences"), 900, 550)

        paned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
        paned.set_position(250)

        def func():
            bean = self.navigation.get_selected_bean()
            if bean:
                self.populate_config_category(bean.text)

        self.navigation = SimpleListTreeControl(_("Categories"), controls,
                                                True)

        for plugin in self.configs:
            self.navigation.append(FDModel(plugin.name))

        self.navigation.set_left_click_func(func)

        paned.add1(self.navigation.scroll)

        cbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        for plugin in self.configs:
            cbox.pack_start(plugin.widget, False, True, 0)

        self._container = self.create_container(cbox)
        paned.add2(self._container)

        mainVBox.pack_start(paned, True, True, 0)
        mainVBox.pack_start(self.create_save_cancel_buttons(), False, False, 0)

        #self.add(mainVBox)
        GLib.idle_add(self.add, mainVBox)

    def show(self, current=CONFIG_MUSIC_LIBRARY):
        self.show_all()
        self.populate_config_category(current)
        self.on_load()
        analytics.action("PreferencesWindow")

    def on_load(self):
        logging.debug("LOAD PreferencesWindow")
        for plugin in self.configs:
            plugin.on_load()

    def on_save(self):
        for plugin in self.configs:
            plugin.on_save()
        FC().save()
        bean = self.navigation.get_selected_bean()
        if bean:
            self.populate_config_category(bean.text)

    def hide_window(self, *a):
        self.hide()
        for plugin in self.configs:
            if hasattr(plugin, "on_close"):
                plugin.on_close()
        self.navigation.set_cursor_on_cell(Gtk.TreePath(0), None, None, False)
        return True

    def populate_config_category(self, name):
        for plugin in self.configs:
            if plugin.name == name:
                plugin.widget.show()
                try:
                    self.update_label(name)
                except:
                    pass
            else:
                plugin.widget.hide()

    def create_save_cancel_buttons(self):
        box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
        box.show()

        button_restore = Gtk.Button.new_with_label(
            _("Restore Defaults Settings"))
        button_restore.connect("clicked", lambda *a: self.restore_defaults())
        button_restore.show()

        button_apply = Gtk.Button.new_with_label(_("Apply"))
        button_apply.set_size_request(100, -1)
        button_apply.connect("clicked", lambda *a: self.on_save())
        button_apply.show()

        button_close = Gtk.Button.new_with_label(_("Close"))
        button_close.set_size_request(100, -1)
        button_close.connect("clicked", self.hide_window)
        button_close.show()

        empty = Gtk.Label.new("")
        empty.show()

        box.pack_start(button_restore, False, True, 0)
        box.pack_start(empty, True, True, 0)
        box.pack_start(button_apply, False, True, 0)
        box.pack_start(button_close, False, True, 0)

        return box

    def restore_defaults(self):
        logging.debug("restore defaults settings")
        Gtk.main_quit()
        FC().delete()
        threading.Thread(target=os.system, args=("foobnix", )).start()

    def update_label(self, title):
        self.label.set_markup('<b><i><span  size="x-large" >' + title +
                              '</span></i></b>')

    def create_container(self, widget):
        box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        box.show()

        self.label = Gtk.Label.new(None)
        self.label.show()

        separator = Gtk.HSeparator.new()
        separator.show()

        box.pack_start(self.label, False, True, 0)
        box.pack_start(separator, False, True, 0)
        box.pack_start(widget, False, True, 0)

        return box
Ejemplo n.º 13
0
class PreferencesWindow(ChildTopWindow, FControl, LoadSave):

    configs = []
    POS_NAME = 0

    def __init__(self, controls):
        FControl.__init__(self, controls)
        thread.start_new_thread(self.lazy_init, (True, ))

    def lazy_init(self, sleep=False):
        controls = self.controls
        self.configs.append(MusicLibraryConfig(controls))
        self.configs.append(TabsConfig(controls))
        self.configs.append(LastFmConfig(controls))
        self.configs.append(TrayIconConfig(controls))
        self.configs.append(NetworkConfig(controls))

        try:
            """check keybinder installed, debian"""
            from gi.repository import Keybinder  #@UnresolvedImport @UnusedImport
            from foobnix.preferences.configs.hotkey_conf import HotKeysConfig
            self.configs.append(HotKeysConfig(controls))
        except Exception, e:
            logging.warn("Keybinder not installed" + str(e))

        self.configs.append(OtherConfig(controls))

        self.label = None

        mainVBox = Gtk.VBox(False, 0)

        ChildTopWindow.__init__(self, _("Preferences"), 900, 550)

        paned = Gtk.HPaned()
        paned.set_position(250)

        def func():
            bean = self.navigation.get_selected_bean()
            if bean:
                self.populate_config_category(bean.text)

        self.navigation = SimpleListTreeControl(_("Categories"), controls,
                                                True)

        for plugin in self.configs:
            self.navigation.append(FDModel(plugin.name))

        self.navigation.set_left_click_func(func)

        paned.add1(self.navigation.scroll)

        cbox = Gtk.VBox(False, 0)
        for plugin in self.configs:
            cbox.pack_start(plugin.widget, False, True, 0)

        self._container = self.create_container(cbox)
        paned.add2(self._container)

        mainVBox.pack_start(paned, True, True, 0)
        mainVBox.pack_start(self.create_save_cancel_buttons(), False, False, 0)

        #self.add(mainVBox)
        GLib.idle_add(self.add, mainVBox)