Esempio n. 1
0
	def __init__(self):
		gobject.GObject.__init__(self)
		self._defaults_path = None
		self._config = self._read_config()
		self._save_timer = scheduler.Timer(True)
		self._alternatives = {}
		self._alternative_validators = {}
Esempio n. 2
0
    def __init__(self):
        super(DataController, self).__init__()

        self.source_pane = LeafPane()
        self.object_pane = SecondaryObjectPane()
        self.source_pane.connect("new-source", self._new_source)
        self.object_pane.connect("new-source", self._new_source)
        self.action_pane = PrimaryActionPane()
        self._panectl_table = {
            SourcePane: self.source_pane,
            ActionPane: self.action_pane,
            ObjectPane: self.object_pane,
        }
        for pane, ctl in self._panectl_table.items():
            ctl.connect("search-result", self._pane_search_result, pane)
        self.mode = None
        self._search_ids = itertools.count(1)
        self._latest_interaction = -1
        self._execution_context = commandexec.DefaultActionExecutionContext()
        self._execution_context.connect("command-result",
                                        self._command_execution_result)
        self._execution_context.connect("late-command-result",
                                        self._late_command_execution_result)

        self._save_data_timer = scheduler.Timer()

        sch = scheduler.GetScheduler()
        sch.connect("load", self._load)
        sch.connect("display", self._display)
        sch.connect("finish", self._finish)
Esempio n. 3
0
 def activate(self, leaf, iobj, ctx):
     from kupfer import scheduler
     # make a timer that will fire when Kupfer exits
     interval = utils.parse_time_interval(iobj.object)
     pretty.print_debug(__name__, "Run %s in %s seconds" % (leaf, interval))
     timer = scheduler.Timer(True)
     args = (ctx, ) if leaf.wants_context() else ()
     timer.set(interval, leaf.run, *args)
Esempio n. 4
0
 def __init__(self, period=5, startup=10, campaign=3600):
     self.startup = startup
     self.period = period
     self.campaign = campaign
     self.timer = scheduler.Timer()
     # Source -> time mapping
     self.latest_rescan_time = weakref.WeakKeyDictionary()
     self._min_rescan_interval = campaign // 4
Esempio n. 5
0
 def __init__(self):
     GObject.GObject.__init__(self)
     self._defaults_path = None
     self.encoding = _override_encoding(locale.getpreferredencoding())
     self.output_debug("Using", self.encoding)
     self._config = self._read_config()
     self._save_timer = scheduler.Timer(True)
     self._alternatives = {}
     self._alternative_validators = {}
Esempio n. 6
0
 def activate(self, leaf):
     closer = CloseAll()
     if closer.valid_for_item(leaf): closer.activate(leaf)
     if (not launch.application_is_running(leaf.get_id())):
         pretty.print_debug(__name__, 'App stoped')
         launcher = Launch()
         if launcher.valid_for_item(leaf):
             launcher.activate(leaf, self.wants_context())
     else:
         pretty.print_debug(__name__, 'App not ended yet')
         interval = utils.parse_time_interval(
             "%ss" % (__kupfer_settings__["app_ended_interval"]))
         self.retry += 1
         if self.try_again(self.retry):
             pretty.print_debug(__name__, 'App not ended yet - retry')
             from kupfer import scheduler
             timer = scheduler.Timer(True)
             timer.set(interval, RestartApp, leaf, self.retry)
         else:
             pretty.print_debug(__name__, 'App will not end - abort')
Esempio n. 7
0
class ArchiveContent(Source):
    extractors = []
    unarchived_files = []
    end_timer = scheduler.Timer(True)

    def __init__(self, fileleaf, unarchive_func):
        Source.__init__(self, _("Content of %s") % fileleaf)
        self.path = fileleaf.object
        self.unarchiver = unarchive_func

    def repr_key(self):
        return self.path

    def get_items(self):
        # always use the same destination for the same file and mtime
        basename = os.path.basename(os.path.normpath(self.path))
        root, ext = os.path.splitext(basename)
        mtime = os.stat(self.path).st_mtime
        fileid = hashlib.sha1("%s%s" % (self.path, mtime)).hexdigest()
        pth = os.path.join("/tmp", "kupfer-%s-%s" % (
            root,
            fileid,
        ))
        if not os.path.exists(pth):
            self.output_debug("Extracting with %s" % (self.unarchiver, ))
            self.unarchiver(self.path, pth)
            self.unarchived_files.append(pth)
            self.end_timer.set(VERY_LONG_TIME_S,
                               self.clean_up_unarchived_files)
        files = list(DirectorySource(pth, show_hidden=True).get_leaves())
        if len(files) == 1 and files[0].has_content():
            return files[0].content_source().get_leaves()
        return files

    def get_description(self):
        return None

    @classmethod
    def decorates_type(cls):
        return FileLeaf

    @classmethod
    def decorate_item(cls, leaf):
        basename = os.path.basename(leaf.object).lower()
        for extractor in cls.extractors:
            if any(basename.endswith(ext) for ext in extractor.extensions):
                if extractor.predicate(leaf.object):
                    return cls._source_for_path(leaf, extractor)

    @classmethod
    def _source_for_path(cls, leaf, extractor):
        byte_size = os.stat(leaf.object).st_size
        if byte_size < MAX_ARCHIVE_BYTE_SIZE:
            return cls(leaf, extractor)
        return None

    @classmethod
    def clean_up_unarchived_files(cls):
        if not cls.unarchived_files:
            return
        pretty.print_info(__name__, "Removing extracted archives..")
        for filetree in set(cls.unarchived_files):
            pretty.print_debug(__name__, "Removing",
                               os.path.basename(filetree))
            shutil.rmtree(filetree, onerror=cls._clean_up_error_handler)
        cls.unarchived_files = []

    @classmethod
    def _clean_up_error_handler(cls, func, path, exc_info):
        pretty.print_error(__name__, "Error in %s deleting %s:" % (func, path))
        pretty.print_error(__name__, exc_info)

    @classmethod
    def extractor(cls, extensions, predicate):
        def decorator(func):
            func.extensions = extensions
            func.predicate = predicate
            cls.extractors.append(func)
            return func

        return decorator
Esempio n. 8
0
 def initialize(self):
     self._timer = scheduler.Timer()
Esempio n. 9
0
    def __init__(self):
        """Load ui from data file"""
        builder = Gtk.Builder()
        builder.set_translation_domain(version.PACKAGE_NAME)
        ui_file = config.get_data_file("preferences.ui")

        if ui_file:
            builder.add_from_file(ui_file)
        else:
            self.window = None
            return
        self.window = builder.get_object("preferenceswindow")
        self.window.set_position(Gtk.WindowPosition.CENTER)
        self.window.connect("delete-event", self._close_window)
        self.pluglist_parent = builder.get_object("plugin_list_parent")
        self.dirlist_parent = builder.get_object("directory_list_parent")
        self.plugin_about_parent = builder.get_object("plugin_about_parent")
        self.preferences_notebook = builder.get_object("preferences_notebook")

        self.buttonremovedirectory = builder.get_object(
            "buttonremovedirectory")
        checkautostart = builder.get_object("checkautostart")
        checkstatusicon_gtk = builder.get_object("checkstatusicon_gtk")
        checkstatusicon_ai = builder.get_object("checkstatusicon_ai")
        combo_icons_large_size = builder.get_object("icons_large_size")
        combo_icons_small_size = builder.get_object("icons_small_size")
        checkusecommandkeys = builder.get_object("checkusecommandkeys")
        radio_actionaccelalt = builder.get_object("radio_actionaccelalt")
        radio_actionaccelctrl = builder.get_object("radio_actionaccelctrl")
        self.entry_plugins_filter = builder.get_object('entry_plugins_filter')
        self.keybindings_list_parent = builder.get_object(
            'keybindings_list_parent')
        self.gkeybindings_list_parent = builder.get_object(
            'gkeybindings_list_parent')
        source_list_parent = builder.get_object("source_list_parent")
        button_reset_keys = builder.get_object("button_reset_keys")
        self.sources_list_ctrl = SourceListController(source_list_parent)

        setctl = settings.GetSettingsController()
        checkautostart.set_active(self._get_should_autostart())
        checkstatusicon_gtk.set_active(setctl.get_show_status_icon())

        large_icon_size = setctl.get_config_int("Appearance",
                                                "icon_large_size")
        small_icon_size = setctl.get_config_int("Appearance",
                                                "icon_small_size")

        set_combobox(large_icon_size, combo_icons_large_size)
        set_combobox(small_icon_size, combo_icons_small_size)

        if supports_app_indicator():
            checkstatusicon_ai.set_active(setctl.get_show_status_icon_ai())
        else:
            checkstatusicon_ai.set_sensitive(False)

        label = checkstatusicon_gtk.get_label()
        checkstatusicon_gtk.set_label(label + " (GtkStatusIcon)")
        label = checkstatusicon_ai.get_label()
        checkstatusicon_ai.set_label(label + " (AppIndicator)")

        checkusecommandkeys.set_active(setctl.get_use_command_keys())
        radio_actionaccelalt.set_active(
            setctl.get_action_accelerator_modifer() != 'ctrl')
        radio_actionaccelctrl.set_active(
            setctl.get_action_accelerator_modifer() == 'ctrl')

        # List store with columns (Name, ID)
        # Make alternative comboboxes
        terminal_combobox = builder.get_object("terminal_combobox")
        icons_combobox = builder.get_object("icons_combobox")

        def make_combobox_model(combobox):
            combobox_store = Gtk.ListStore(GObject.TYPE_STRING,
                                           GObject.TYPE_STRING)
            combobox.set_model(combobox_store)
            combobox_cell = Gtk.CellRendererText()
            combobox.pack_start(combobox_cell, True)
            combobox.add_attribute(combobox_cell, 'text', 0)

        make_combobox_model(terminal_combobox)
        make_combobox_model(icons_combobox)

        self._update_alternative_combobox('terminal', terminal_combobox)
        self._update_alternative_combobox('icon_renderer', icons_combobox)
        self.terminal_combobox = terminal_combobox
        self.icons_combobox = icons_combobox
        setctl.connect("alternatives-changed", self._on_alternatives_changed)

        # Plugin List
        columns = [
            {
                "key": "plugin_id",
                "type": str
            },
            {
                "key": "enabled",
                "type": bool
            },
            {
                "key": "icon-name",
                "type": str
            },
            {
                "key": "text",
                "type": str
            },
        ]
        # setup plugin list table
        column_types = [c["type"] for c in columns]
        self.columns = [c["key"] for c in columns]
        self.store = Gtk.ListStore.new(column_types)
        self.table = Gtk.TreeView.new_with_model(self.store)
        self.table.set_headers_visible(False)
        self.table.set_property("enable-search", False)
        self.table.connect("cursor-changed", self.plugin_table_cursor_changed)
        self.table.get_selection().set_mode(Gtk.SelectionMode.BROWSE)

        checkcell = Gtk.CellRendererToggle()
        checkcol = Gtk.TreeViewColumn("item", checkcell)
        checkcol.add_attribute(checkcell, "active",
                               self.columns.index("enabled"))
        checkcell.connect("toggled", self.on_checkplugin_toggled)

        icon_cell = Gtk.CellRendererPixbuf()
        icon_cell.set_property("height", LIST_ICON_SIZE)
        icon_cell.set_property("width", LIST_ICON_SIZE)

        icon_col = Gtk.TreeViewColumn("icon", icon_cell)
        icon_col.add_attribute(icon_cell, "icon-name",
                               self.columns.index("icon-name"))

        cell = Gtk.CellRendererText()
        col = Gtk.TreeViewColumn("item", cell)
        col.add_attribute(cell, "text", self.columns.index("text"))

        self.table.append_column(checkcol)
        # hide icon for now
        #self.table.append_column(icon_col)
        self.table.append_column(col)

        self.plugin_list_timer = scheduler.Timer()
        self.plugin_info = utils.locale_sort(
            plugins.get_plugin_info(), key=lambda rec: rec["localized_name"])
        self._refresh_plugin_list()
        self.output_debug("Standard Plugins: %d" % len(self.store))
        self.table.show()
        self.pluglist_parent.add(self.table)

        # Directory List
        self.dir_store = Gtk.ListStore.new([str, Gio.Icon, str])
        self.dir_table = Gtk.TreeView.new_with_model(self.dir_store)
        self.dir_table.set_headers_visible(False)
        self.dir_table.set_property("enable-search", False)
        self.dir_table.connect("cursor-changed", self.dir_table_cursor_changed)
        self.dir_table.get_selection().set_mode(Gtk.SelectionMode.BROWSE)

        icon_cell = Gtk.CellRendererPixbuf()

        icon_col = Gtk.TreeViewColumn("icon", icon_cell)
        icon_col.add_attribute(icon_cell, "gicon", 1)

        cell = Gtk.CellRendererText()
        col = Gtk.TreeViewColumn("name", cell)
        col.add_attribute(cell, "text", 2)
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
        self.dir_table.append_column(icon_col)
        self.dir_table.append_column(col)
        self.dir_table.show()
        self.dirlist_parent.add(self.dir_table)
        self.read_directory_settings()

        # global keybindings list
        self.keybind_table, self.keybind_store = _create_conf_keys_list()
        self.keybindings_list_parent.add(self.keybind_table)
        self.keybind_table.connect("row-activated",
                                   self.on_keybindings_row_activate)
        button_reset_keys.set_sensitive(keybindings.is_available())
        self.keybind_table.set_sensitive(keybindings.is_available())

        # kupfer interface (accelerators) keybindings list
        self.gkeybind_table, self.gkeybind_store = _create_conf_keys_list()
        self.gkeybindings_list_parent.add(self.gkeybind_table)
        self.gkeybind_table.connect("row-activated",
                                    self.on_gkeybindings_row_activate)

        # Requires GTK 3.22
        try:
            self.gkeybindings_list_parent.set_propagate_natural_height(True)
        except AttributeError:
            pass

        self._show_keybindings(setctl)
        self._show_gkeybindings(setctl)

        # Connect to signals at the last point
        builder.connect_signals(self)
Esempio n. 10
0
	def initialize(self):
		ToplevelGroupingSource.initialize(self)
		self._install_dbus_signal()
		self._buddy_update_timer = scheduler.Timer()
		self._buddy_update_queue = set()
Esempio n. 11
0
    def __init__(self):
        """Load ui from data file"""
        builder = gtk.Builder()
        builder.set_translation_domain(version.PACKAGE_NAME)
        ui_file = config.get_data_file("preferences.ui")

        if ui_file:
            builder.add_from_file(ui_file)
        else:
            self.window = None
            return
        builder.connect_signals(self)
        self.window = builder.get_object("preferenceswindow")
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.connect("delete-event", self._close_window)
        self.pluglist_parent = builder.get_object("plugin_list_parent")
        self.dirlist_parent = builder.get_object("directory_list_parent")
        self.plugin_about_parent = builder.get_object("plugin_about_parent")
        self.preferences_notebook = builder.get_object("preferences_notebook")

        self.buttonremovedirectory = builder.get_object(
            "buttonremovedirectory")
        checkautostart = builder.get_object("checkautostart")
        checkstatusicon = builder.get_object("checkstatusicon")
        checkusecommandkeys = builder.get_object("checkusecommandkeys")
        self.entry_plugins_filter = builder.get_object('entry_plugins_filter')
        self.keybindings_list_parent = builder.get_object(
            'keybindings_list_parent')
        self.gkeybindings_list_parent = builder.get_object(
            'gkeybindings_list_parent')
        source_list_parent = builder.get_object("source_list_parent")
        self.sources_list_ctrl = SourceListController(source_list_parent)

        setctl = settings.GetSettingsController()
        checkautostart.set_active(self._get_should_autostart())
        checkstatusicon.set_active(setctl.get_show_status_icon())
        checkusecommandkeys.set_active(setctl.get_use_command_keys())

        # List store with columns (Name, ID)
        # Make alternative comboboxes
        terminal_combobox = builder.get_object("terminal_combobox")
        icons_combobox = builder.get_object("icons_combobox")

        def make_combobox_model(combobox):
            combobox_store = gtk.ListStore(gobject.TYPE_STRING,
                                           gobject.TYPE_STRING)
            combobox.set_model(combobox_store)
            combobox_cell = gtk.CellRendererText()
            combobox.pack_start(combobox_cell, True)
            combobox.add_attribute(combobox_cell, 'text', 0)

        make_combobox_model(terminal_combobox)
        make_combobox_model(icons_combobox)

        self._update_alternative_combobox('terminal', terminal_combobox)
        self._update_alternative_combobox('icon_renderer', icons_combobox)
        self.terminal_combobox = terminal_combobox
        self.icons_combobox = icons_combobox
        setctl.connect("alternatives-changed", self._on_alternatives_changed)

        # Plugin List
        columns = [
            {
                "key": "plugin_id",
                "type": str
            },
            {
                "key": "enabled",
                "type": bool
            },
            {
                "key": "icon-name",
                "type": str
            },
            {
                "key": "text",
                "type": str
            },
        ]
        # setup plugin list table
        column_types = [c["type"] for c in columns]
        self.columns = [c["key"] for c in columns]
        self.store = gtk.ListStore(*column_types)
        self.table = gtk.TreeView(self.store)
        self.table.set_headers_visible(False)
        self.table.set_property("enable-search", False)
        self.table.set_rules_hint(True)
        self.table.connect("cursor-changed", self.plugin_table_cursor_changed)
        self.table.get_selection().set_mode(gtk.SELECTION_BROWSE)

        checkcell = gtk.CellRendererToggle()
        checkcol = gtk.TreeViewColumn("item", checkcell)
        checkcol.add_attribute(checkcell, "active",
                               self.columns.index("enabled"))
        checkcell.connect("toggled", self.on_checkplugin_toggled)

        icon_cell = gtk.CellRendererPixbuf()
        icon_cell.set_property("height", LIST_ICON_SIZE)
        icon_cell.set_property("width", LIST_ICON_SIZE)

        icon_col = gtk.TreeViewColumn("icon", icon_cell)
        icon_col.add_attribute(icon_cell, "icon-name",
                               self.columns.index("icon-name"))

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("item", cell)
        col.add_attribute(cell, "text", self.columns.index("text"))

        self.table.append_column(checkcol)
        # hide icon for now
        #self.table.append_column(icon_col)
        self.table.append_column(col)

        self.plugin_list_timer = scheduler.Timer()
        self.plugin_info = utils.locale_sort(
            plugins.get_plugin_info(), key=lambda rec: rec["localized_name"])
        self._refresh_plugin_list()
        self.output_debug("Standard Plugins: %d" % len(self.store))
        self.table.show()
        self.pluglist_parent.add(self.table)

        # Directory List
        self.dir_store = gtk.ListStore(str, gio.Icon, str)
        self.dir_table = gtk.TreeView(self.dir_store)
        self.dir_table.set_headers_visible(False)
        self.dir_table.set_property("enable-search", False)
        self.dir_table.connect("cursor-changed", self.dir_table_cursor_changed)
        self.dir_table.get_selection().set_mode(gtk.SELECTION_BROWSE)

        icon_cell = gtk.CellRendererPixbuf()

        icon_col = gtk.TreeViewColumn("icon", icon_cell)
        icon_col.add_attribute(icon_cell, "gicon", 1)

        cell = gtk.CellRendererText()
        col = gtk.TreeViewColumn("name", cell)
        col.add_attribute(cell, "text", 2)
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
        self.dir_table.append_column(icon_col)
        self.dir_table.append_column(col)
        self.dir_table.show()
        self.dirlist_parent.add(self.dir_table)
        self.read_directory_settings()

        # keybindings list
        self.keybind_table, self.keybind_store = _create_conf_keys_list()
        self.keybindings_list_parent.add(self.keybind_table)
        self.keybind_table.connect("row-activated",
                                   self.on_keybindings_row_activate)
        # global keybindings list
        self.gkeybind_table, self.gkeybind_store = _create_conf_keys_list()
        self.gkeybindings_list_parent.add(self.gkeybind_table)
        self.gkeybind_table.connect("row-activated",
                                    self.on_gkeybindings_row_activate)

        self._show_keybindings(setctl)
        self._show_gkeybindings(setctl)