Example #1
0
    def create_context_menu(self):
        """create_context_menu"""
        context_menu = Gtk.Menu()
        self.context_items = {}

        item = Gtk.ImageMenuItem(Gtk.STOCK_CUT)
        item.connect('activate', lambda menu: self.cut_selected())
        item.get_child().set_label(_("Cut"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_COPY)
        item.connect('activate', lambda menu: self.copy_selected())
        item.get_child().set_label(_("Copy"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_PASTE)
        item.connect('activate', lambda menu: self.insert_action(self.copied))
        item.get_child().set_label(_("Paste"))
        context_menu.append(item)
        self.sw_paste_buffer.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_REMOVE)
        item.connect('activate', lambda menu: self.del_selected())
        item.get_child().set_label(_("Remove"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        context_menu.show_all()
        return context_menu
Example #2
0
    def create_view(self, model):
        """create_view

        :param model:
        """
        renderer = Gtk.CellRendererCombo()

        def editingstarted(cell, widget, path):
            widget.set_wrap_width(1)

        chs = Gtk.TreeStore(TYPE_STRING, TYPE_STRING)
        renderer.props.model = self.create_choices(chs)
        renderer.props.text_column = 0
        renderer.props.editable = True
        renderer.props.has_entry = False
        renderer.connect('changed', self.action_class_changed)
        renderer.connect('editing-started', editingstarted)

        column = Gtk.TreeViewColumn(_("Actions"), renderer, text=0)

        view = Gtk.TreeView(model)
        view.append_column(column)
        view.get_selection().connect('changed', self.view_cursor_changed)
        view.connect('button-press-event', self.view_button_clicked)
        return view
Example #3
0
 def put_table(table, label_text, widget, row, addtosens=True):
     label = Gtk.Label(label=_(label_text))
     label.set_padding(5, 5)
     label.set_alignment(0, 0)
     if addtosens:
         sens_list.append(label)
     table.attach(label, 0, 1, row, row + 1, EXPAND | FILL, 0, 0, 0)
     table.attach(widget, 1, 2, row, row + 1, FILL, 0, 0, 0)
Example #4
0
    def create_toolbar(self):
        """create_toolbar"""
        toolbar = Gtk.Toolbar()
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR)
        toolbar.set_show_arrow(False)

        but = Gtk.ToolButton(Gtk.STOCK_ADD)
        but.set_tooltip_text(_("Insert action"))
        but.connect('clicked',
                    lambda b: self.insert_action(
                        OBAction("Execute")))
        toolbar.insert(but, -1)

        but = Gtk.ToolButton(Gtk.STOCK_REMOVE)
        but.set_tooltip_text(_("Remove action"))
        but.connect('clicked',
                    lambda b: self.del_selected())
        toolbar.insert(but, -1)
        self.sw_selection_available.append(but)

        but = Gtk.ToolButton(Gtk.STOCK_GO_UP)
        but.set_tooltip_text(_("Move action up"))
        but.connect('clicked',
                    lambda b: self.move_selected_up())
        toolbar.insert(but, -1)
        self.sw_can_move_up.append(but)

        but = Gtk.ToolButton(Gtk.STOCK_GO_DOWN)
        but.set_tooltip_text(_("Move action down"))
        but.connect('clicked',
                    lambda b: self.move_selected_down())
        toolbar.insert(but, -1)
        self.sw_can_move_down.append(but)

        sep = Gtk.SeparatorToolItem()
        sep.set_draw(False)
        sep.set_expand(True)
        toolbar.insert(sep, -1)

        but = Gtk.ToolButton(Gtk.STOCK_DELETE)
        but.set_tooltip_text(_("Remove all actions"))
        but.connect('clicked', lambda b: self.clear())
        toolbar.insert(but, -1)
        self.sw_action_list_nonempty.append(but)
        return toolbar
Example #5
0
    def _create_context_menu(self):
        """_create_context_menu"""
        context_menu = Gtk.Menu()
        self.context_items = {}

        item = Gtk.ImageMenuItem(Gtk.STOCK_CUT)
        item.connect('activate', lambda menu: self.cut_selected())
        item.get_child().set_label(_("Cut"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_COPY)
        item.connect('activate', lambda menu: self.copy_selected())
        item.get_child().set_label(_("Copy"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_PASTE)
        item.connect('activate',
                     lambda menu: self.insert_sibling(
                         copy.deepcopy(self.copied)))
        item.get_child().set_label(_("Paste"))
        context_menu.append(item)
        self.sw_paste_buffer.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_PASTE)
        item.get_child().set_label(_("Paste as child"))
        item.connect('activate',
                     lambda menu: self.insert_child(
                         copy.deepcopy(self.copied)))
        context_menu.append(item)
        self.sw_insert_child_and_paste.append(item)

        item = Gtk.ImageMenuItem(Gtk.STOCK_REMOVE)
        item.connect('activate',
                     lambda menu: self.del_selected())
        item.get_child().set_label(_("Remove"))
        context_menu.append(item)
        self.sw_selection_available.append(item)

        context_menu.show_all()
        return context_menu
Example #6
0
    def get_action_desc(self, kb):
        """get_action_desc

        :param kb:
            """
        if len(kb.actions) > 0:
            if kb.actions[0].name == "Execute":
                frst_action = "[ "\
                    + kb.actions[0].options['command'] + " ]"
            elif kb.actions[0].name == "SendToDesktop":
                frst_action = _(kb.actions[0].name)\
                    + " " + str(kb.actions[0].options['desktop'])
            elif kb.actions[0].name == "Desktop":
                frst_action = _(kb.actions[0].name)\
                    + " " + str(kb.actions[0].options['desktop'])
            else:
                frst_action = _(kb.actions[0].name)
        else:
            frst_action = "."
        return frst_action
Example #7
0
    def add_row(self, label_text, table):
        """add_row

        :param label_text:
        :param table:
        """
        label = Gtk.Label(label=_(label_text))
        label.set_alignment(0, 0)
        row = self.table.props.n_rows
        self.table.attach(label, 0, 1, row, row + 1, EXPAND | FILL, 0, 5, 0)
        self.table.attach(table, 1, 2, row, row + 1, FILL, 0, 5, 0)
Example #8
0
    def get_action_desc(self, kb):
        """get_action_desc

        :param kb:
            """
        if len(kb.actions) > 0:
            if kb.actions[0].name == "Execute":
                frst_action = "[ "\
                    + kb.actions[0].options['command'] + " ]"
            elif kb.actions[0].name == "SendToDesktop":
                frst_action = _(kb.actions[0].name)\
                    + " " + str(kb.actions[0].options['desktop'])
            elif kb.actions[0].name == "Desktop":
                frst_action = _(kb.actions[0].name)\
                    + " " + str(kb.actions[0].options['desktop'])
            else:
                frst_action = _(kb.actions[0].name)
        else:
            frst_action = "."
        return frst_action
Example #9
0
    def insert_action(self, action):
        """insert_action

        :param action:
        """
        if self.actions is None:
            return

        (model, item) = self.view.get_selection().get_selected()
        if item:
            self._insert_action(action, model.get_value(item, 1))
            newit = self.model.insert_after(item, (_(action.name), action))
        else:
            self._insert_action(action)
            newit = self.model.append((_(action.name), action))

        if newit:
            self.view.get_selection().select_iter(newit)

        self.cond_action_list_nonempty.set_state(len(self.model))
        if self.actions_cb:
            self.actions_cb()
Example #10
0
    def add_row(self, label_text, table):
        """add_row

        :param label_text:
        :param table:
        """
        label = Gtk.Label(label=_(label_text))
        label.set_alignment(0, 0)
        row = self.table.props.n_rows
        self.table.attach(
            label, 0, 1, row, row + 1,
            EXPAND | FILL,
            0, 5, 0)
        self.table.attach(table, 1, 2, row, row + 1, FILL, 0, 5, 0)
Example #11
0
    def create_choices(self, ch):
        """create_choices

        :param ch:
        """
        ret = ch
        actions_a = {}

        for act in self._actions_choices:
            actions_a[_(act)] = act
        for act in sorted(actions_a.keys()):
            actions_b = {}
            content_a = self._actions_choices[actions_a[act]]
            if (type(content_a) is dict):
                iter0 = ret.append(None, [act, ""])

                for b in content_a:
                    actions_b[_(b)] = b

                for b in sorted(actions_b.keys()):
                    actions_c = {}
                    content_b = content_a[actions_b[b]]
                    if (type(content_b) is dict):
                        iter1 = ret.append(
                            iter0, [b, ""])

                        for c in content_b:
                            actions_c[_(c)] = c
                        for c in sorted(actions_c.keys()):
                            ret.append(iter1, [c, actions_c[c]])

                    else:
                        ret.append(iter0, [b, actions_b[b]])
            else:
                ret.append(None, [act, actions_a[act]])

        return ret
Example #12
0
    def _create_cqk_hbox(self, cqk_view):
        """_create_cqk_hbox

        :param cqk_view:
            """
        cqk_hbox = Gtk.HBox()
        cqk_label = Gtk.Label(label=_("chainQuitKey:"))
        cqk_label.set_padding(5, 5)

        cqk_frame = Gtk.Frame()
        cqk_frame.add(cqk_view)

        cqk_hbox.pack_start(cqk_label, False, False, False)
        cqk_hbox.pack_start(cqk_frame, True, True, 0)
        return cqk_hbox
Example #13
0
    def _create_cqk_hbox(self, cqk_view):
        """_create_cqk_hbox

        :param cqk_view:
            """
        cqk_hbox = Gtk.HBox()
        cqk_label = Gtk.Label(label=_("chainQuitKey:"))
        cqk_label.set_padding(5, 5)

        cqk_frame = Gtk.Frame()
        cqk_frame.add(cqk_view)

        cqk_hbox.pack_start(cqk_label, False, False, False)
        cqk_hbox.pack_start(cqk_frame, True, True, 0)
        return cqk_hbox
Example #14
0
    def set_actions(self, actionlist):
        """set_actions

        :param actionlist:
            """
        self.actions = actionlist
        self.model.clear()
        self.widget.set_sensitive(self.actions is not None)
        if not self.actions:
            return
        for act in self.actions:
            self.model.append((_(act.name), act))

        if len(self.model):
            self.view.get_selection().select_iter(self.model.get_iter_first())
        self.cond_action_list_nonempty.set_state(len(self.model))
Example #15
0
    def generate_widget(self, action, callback=None):
        """generate_widget

        :param action:
        :param callback:
        """
        def changed(combo, action):
            text = combo.get_active()
            action.options[self.name] = self.choices[text]

        model = Gtk.ListStore(TYPE_STRING)
        for choice in self.choices:
            model.append((_(choice),))
        combo = Gtk.ComboBox()
        combo.set_active(self.choices.index(action.options[self.name]))
        combo.set_model(model)
        cell = Gtk.CellRendererText()
        combo.pack_start(cell, True)
        combo.add_attribute(cell, 'text', 0)
        combo.connect('changed', changed, action)
        return combo
Example #16
0
    def _create_toolbar(self):
        """_create_toolbar"""
        agr = Gtk.AccelGroup()
        self.window.add_accel_group(agr)

        toolbar = Gtk.Toolbar()
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.set_show_arrow(False)

        def duplicate(b):
            self.duplicate_selected()

        but = Gtk.ToolButton(Gtk.STOCK_DND_MULTIPLE)
        but.set_tooltip_text(_("Duplicate sibling keybind")+" (Ctrl + d)")
        but.connect('clicked', duplicate)
        key, mod = Gtk.accelerator_parse("<Control>d")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def copy(b):
            self.copy_selected()

        but = Gtk.ToolButton(Gtk.STOCK_COPY)
        but.set_tooltip_text(_("Copy")+" (Ctrl + c)")
        but.connect('clicked', copy)
        key, mod = Gtk.accelerator_parse("<Control>c")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)


        def paste(b):
            self.insert_sibling( copy.deepcopy(self.copied))

        but = Gtk.ToolButton(Gtk.STOCK_PASTE)
        but.set_tooltip_text(_("Paste")+" (Ctrl + v)")
        but.connect('clicked',paste)
        key, mod = Gtk.accelerator_parse("<Control>v")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def add_sibling(b):
            self.insert_sibling(OBKeyBind())

        but = Gtk.ToolButton()
        but.set_icon_widget(self.icons['add_sibling'])
        but.set_tooltip_text(_("Insert sibling keybind")+" (Ctrl + a)")
        but.connect('clicked',add_sibling)
        key, mod = Gtk.accelerator_parse("<Control>a")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)


        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def add_child(b):
            self.insert_child(OBKeyBind())

        but = Gtk.ToolButton()
        but.set_icon_widget(self.icons['add_child'])
        but.set_tooltip_text(_("Insert child keybind")+" (Ctrl + i)")
        but.connect('clicked',add_child)
        key, mod = Gtk.accelerator_parse("<Control>i")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def paste_as_child(b):
            self.insert_child(copy.deepcopy(self.copied))

        but = Gtk.ToolButton(Gtk.STOCK_PASTE)
        but.set_tooltip_text(_("Paste as child")+" (Ctrl + V)")
        but.connect('clicked', paste_as_child)
        key, mod = Gtk.accelerator_parse("<Control><Shift>v")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def remove(b):
            self.del_selected()

        but = Gtk.ToolButton(Gtk.STOCK_REMOVE)
        but.set_tooltip_text(_("Remove keybind")+" (Delete)")
        but.connect('clicked',remove)
        toolbar.insert(but, -1)
        key, mod = Gtk.accelerator_parse("Delete")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        self.sw_selection_available.append(but)

        sep = Gtk.SeparatorToolItem()
        sep.set_draw(False)
        sep.set_expand(True)
        toolbar.insert(sep, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def reset(b):
            for p in self.deleted_items_paths + self.changed_items_paths:
                self._refresh_row(p)
            self.deleted_items_paths = list()
            self.changed_items_paths = list()
            self.ob.load()
            if self.ob.keyboard_node:
                self.keyboard = OBKeyboard(self.ob.keyboard_node)
            for kb in self.keyboard.keybinds:
                self.apply_keybind(kb)

        but = Gtk.ToolButton(Gtk.STOCK_UNDO)
        but.set_tooltip_text(_("Undo everything")+" (Ctrl + z)")
        but.connect('clicked',reset)
        key, mod = Gtk.accelerator_parse("<Control>z")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def save(b):
            self.apply_delete()
            self.ob.save(self.keyboard.deparse())
            self.changed_items_paths=list([])

        but = Gtk.ToolButton(Gtk.STOCK_SAVE)
        but.set_tooltip_text(_("Save ") + self.ob.path + _(" file") + " (Ctrl + s)")
        but.connect('clicked', save)
        key, mod = Gtk.accelerator_parse("<Control>s")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)


        def quit(b):
            Gtk.main_quit()

        but = Gtk.ToolButton(Gtk.STOCK_QUIT)
        but.set_tooltip_text(_("Quit application") + " (Ctrl + q)")
        but.connect('clicked', quit)
        key, mod = Gtk.accelerator_parse("<Control>q")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        return toolbar
Example #17
0
    def _create_views(self, model, cqk_model):
        """_create_views

        :param model:
        :param cqk_model:
        """
        # added accel_mode=1 (CELL_RENDERER_ACCEL_MODE_OTHER) for key "Tab"
        r0 = Gtk.CellRendererAccel(accel_mode=1)
        r0.props.editable = True
        r0.connect('accel-edited', self.accel_edited)

        r1 = Gtk.CellRendererText()
        r1.props.editable = True
        r1.connect('edited', self.key_edited)

        r3 = Gtk.CellRendererText()
        r3.props.editable = False

        r2 = Gtk.CellRendererToggle()
        r2.connect('toggled', self.chroot_toggled)

        c0 = Gtk.TreeViewColumn(_("Key"), r0, accel_key=0, accel_mods=1)
        c1 = Gtk.TreeViewColumn(_("Key (text)"), r1, text=2)
        c2 = Gtk.TreeViewColumn(_("Chroot"), r2, active=3, visible=4)
        c3 = Gtk.TreeViewColumn(_("Action"), r3,  text=6)
        c0.set_cell_data_func(r0, self._cell_func)
        c1.set_cell_data_func(r1, self._cell_func)
        c2.set_cell_data_func(r2, self._cell_func)
        c3.set_cell_data_func(r3, self._cell_func)
        c0.set_resizable(True)
        c1.set_resizable(True)
        c2.set_resizable(True)
        c3.set_resizable(True)
        c0.set_fixed_width(200)
        c1.set_fixed_width(200)
        c2.set_fixed_width(100)
        c3.set_fixed_width(200)
        # the action column is the most important one,
        # so make it get the extra available space
        c3.set_expand(True)

        # SORT
        def compare(model, row1, row2, user_data):
            sort_column, _ = model.get_sort_column_id()
            value1 = model.get_value(row1, sort_column)
            value2 = model.get_value(row2, sort_column)
            if value1 < value2:
                return -1
            elif value1 == value2:
                return 0
            else:
                return 1

        c3.set_sort_column_id(6)
        model.set_sort_func(6, compare, None)
        c0.set_sort_column_id(2)
        c1.set_sort_column_id(2)
        model.set_sort_func(2, compare, None)
        c2.set_sort_column_id(4)


        # FILTER
        def match_func(model, column, query, iterr, data=None):
            value = model.get_value(iterr, 6)

            if query == "":
                return False
            else:
                query = query.lower()
                if query.startswith("+"): query = "\+"
                if query.startswith("*"): query = "\*"
                pattern = re.compile(".*"+query+".*")
                return not pattern.match(value.lower())

        # ADD TO VIEW
        view = Gtk.TreeView(model)

        view.set_search_column(6)
        view.set_search_equal_func(match_func)

        view.append_column(c3)
        view.append_column(c0)
        view.append_column(c1)
        view.append_column(c2)
        view.get_selection().connect('changed', self.view_cursor_changed)
        view.get_selection().set_mode(2) # BROWSE
        view.connect('button-press-event', self.view_button_clicked)
        # view.expand_all()


        # chainQuitKey table (wtf hack)

        r0 = Gtk.CellRendererAccel()
        r0.props.editable = True
        r0.connect('accel-edited', self.cqk_accel_edited)

        r1 = Gtk.CellRendererText()
        r1.props.editable = True
        r1.connect('edited', self.cqk_key_edited)

        c0 = Gtk.TreeViewColumn("Key", r0, accel_key=0, accel_mods=1)
        c1 = Gtk.TreeViewColumn("Key (text)", r1, text=2)

        def cqk_view_focus_lost(view, event):
            view.get_selection().unselect_all()

        cqk_view = Gtk.TreeView(cqk_model)
        cqk_view.set_headers_visible(False)
        cqk_view.append_column(c0)
        cqk_view.append_column(c1)
        cqk_view.connect('focus-out-event', cqk_view_focus_lost)
        return (view, cqk_view)
Example #18
0
    def _create_toolbar(self):
        """_create_toolbar"""
        agr = Gtk.AccelGroup()
        self.window.add_accel_group(agr)

        toolbar = Gtk.Toolbar()
        toolbar.set_style(Gtk.ToolbarStyle.ICONS)
        toolbar.set_show_arrow(False)

        def duplicate(b):
            self.duplicate_selected()

        but = Gtk.ToolButton(Gtk.STOCK_DND_MULTIPLE)
        but.set_tooltip_text(_("Duplicate sibling keybind")+" (Ctrl + d)")
        but.connect('clicked', duplicate)
        key, mod = Gtk.accelerator_parse("<Control>d")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def copy(b):
            self.copy_selected()

        but = Gtk.ToolButton(Gtk.STOCK_COPY)
        but.set_tooltip_text(_("Copy")+" (Ctrl + c)")
        but.connect('clicked', copy)
        key, mod = Gtk.accelerator_parse("<Control>c")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)


        def paste(b):
            self.insert_sibling( copy.deepcopy(self.copied))

        but = Gtk.ToolButton(Gtk.STOCK_PASTE)
        but.set_tooltip_text(_("Paste")+" (Ctrl + v)")
        but.connect('clicked',paste)
        key, mod = Gtk.accelerator_parse("<Control>v")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def add_sibling(b):
            self.insert_sibling(OBKeyBind())

        but = Gtk.ToolButton()
        but.set_icon_widget(self.icons['add_sibling'])
        but.set_tooltip_text(_("Insert sibling keybind")+" (Ctrl + a)")
        but.connect('clicked',add_sibling)
        key, mod = Gtk.accelerator_parse("<Control>a")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)


        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def add_child(b):
            self.insert_child(OBKeyBind())

        but = Gtk.ToolButton()
        but.set_icon_widget(self.icons['add_child'])
        but.set_tooltip_text(_("Insert child keybind")+" (Ctrl + i)")
        but.connect('clicked',add_child)
        key, mod = Gtk.accelerator_parse("<Control>i")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def paste_as_child(b):
            self.insert_child(copy.deepcopy(self.copied))

        but = Gtk.ToolButton(Gtk.STOCK_PASTE)
        but.set_tooltip_text(_("Paste as child")+" (Ctrl + V)")
        but.connect('clicked', paste_as_child)
        key, mod = Gtk.accelerator_parse("<Control><Shift>v")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def remove(b):
            self.del_selected()

        but = Gtk.ToolButton(Gtk.STOCK_REMOVE)
        but.set_tooltip_text(_("Remove keybind")+" (Delete)")
        but.connect('clicked',remove)
        toolbar.insert(but, -1)
        key, mod = Gtk.accelerator_parse("Delete")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        self.sw_selection_available.append(but)

        sep = Gtk.SeparatorToolItem()
        sep.set_draw(False)
        sep.set_expand(True)
        toolbar.insert(sep, -1)

        toolbar.insert(Gtk.SeparatorToolItem(), -1)

        def reset(b):
            for p in self.deleted_items_paths + self.changed_items_paths:
                self._refresh_row(p)
            self.deleted_items_paths = list()
            self.changed_items_paths = list()
            self.ob.load()
            if self.ob.keyboard_node:
                self.keyboard = OBKeyboard(self.ob.keyboard_node)
            for kb in self.keyboard.keybinds:
                self.apply_keybind(kb)

        but = Gtk.ToolButton(Gtk.STOCK_UNDO)
        but.set_tooltip_text(_("Undo everything")+" (Ctrl + z)")
        but.connect('clicked',reset)
        key, mod = Gtk.accelerator_parse("<Control>z")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        def save(b):
            self.apply_delete()
            self.ob.save(self.keyboard.deparse())
            self.changed_items_paths=list([])

        but = Gtk.ToolButton(Gtk.STOCK_SAVE)
        but.set_tooltip_text(_("Save ") + self.ob.path + _(" file") + " (Ctrl + s)")
        but.connect('clicked', save)
        key, mod = Gtk.accelerator_parse("<Control>s")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)


        def quit(b):
            Gtk.main_quit()

        but = Gtk.ToolButton(Gtk.STOCK_QUIT)
        but.set_tooltip_text(_("Quit application") + " (Ctrl + q)")
        but.connect('clicked', quit)
        key, mod = Gtk.accelerator_parse("<Control>q")
        but.add_accelerator("clicked", agr, key, mod, Gtk.AccelFlags.VISIBLE)
        toolbar.insert(but, -1)

        return toolbar
Example #19
0
    def _create_views(self, model, cqk_model):
        """_create_views

        :param model:
        :param cqk_model:
        """
        # added accel_mode=1 (CELL_RENDERER_ACCEL_MODE_OTHER) for key "Tab"
        r0 = Gtk.CellRendererAccel(accel_mode=1)
        r0.props.editable = True
        r0.connect('accel-edited', self.accel_edited)

        r1 = Gtk.CellRendererText()
        r1.props.editable = True
        r1.connect('edited', self.key_edited)

        r3 = Gtk.CellRendererText()
        r3.props.editable = False

        r2 = Gtk.CellRendererToggle()
        r2.connect('toggled', self.chroot_toggled)

        c0 = Gtk.TreeViewColumn(_("Key"), r0, accel_key=0, accel_mods=1)
        c1 = Gtk.TreeViewColumn(_("Key (text)"), r1, text=2)
        c2 = Gtk.TreeViewColumn(_("Chroot"), r2, active=3, visible=4)
        c3 = Gtk.TreeViewColumn(_("Action"), r3,  text=6)
        c0.set_cell_data_func(r0, self._cell_func)
        c1.set_cell_data_func(r1, self._cell_func)
        c2.set_cell_data_func(r2, self._cell_func)
        c3.set_cell_data_func(r3, self._cell_func)
        c0.set_resizable(True)
        c1.set_resizable(True)
        c2.set_resizable(True)
        c3.set_resizable(True)
        c0.set_fixed_width(200)
        c1.set_fixed_width(200)
        c2.set_fixed_width(100)
        c3.set_fixed_width(200)
        # the action column is the most important one,
        # so make it get the extra available space
        c3.set_expand(True)

        # SORT
        def compare(model, row1, row2, user_data):
            sort_column, _ = model.get_sort_column_id()
            value1 = model.get_value(row1, sort_column)
            value2 = model.get_value(row2, sort_column)
            if value1 < value2:
                return -1
            elif value1 == value2:
                return 0
            else:
                return 1

        c3.set_sort_column_id(6)
        model.set_sort_func(6, compare, None)
        c0.set_sort_column_id(2)
        c1.set_sort_column_id(2)
        model.set_sort_func(2, compare, None)
        c2.set_sort_column_id(4)


        # FILTER
        def match_func(model, column, query, iterr, data=None):
            value = model.get_value(iterr, 6)

            if query == "":
                return False
            else:
                query = query.lower()
                if query.startswith("+"): query = "\+"
                if query.startswith("*"): query = "\*"
                pattern = re.compile(".*"+query+".*")
                return not pattern.match(value.lower())

        # ADD TO VIEW
        view = Gtk.TreeView(model)

        view.set_search_column(6)
        view.set_search_equal_func(match_func)

        view.append_column(c3)
        view.append_column(c0)
        view.append_column(c1)
        view.append_column(c2)
        view.get_selection().connect('changed', self.view_cursor_changed)
        view.get_selection().set_mode(2) # BROWSE
        view.connect('button-press-event', self.view_button_clicked)
        # view.expand_all()


        # chainQuitKey table (wtf hack)

        r0 = Gtk.CellRendererAccel()
        r0.props.editable = True
        r0.connect('accel-edited', self.cqk_accel_edited)

        r1 = Gtk.CellRendererText()
        r1.props.editable = True
        r1.connect('edited', self.cqk_key_edited)

        c0 = Gtk.TreeViewColumn("Key", r0, accel_key=0, accel_mods=1)
        c1 = Gtk.TreeViewColumn("Key (text)", r1, text=2)

        def cqk_view_focus_lost(view, event):
            view.get_selection().unselect_all()

        cqk_view = Gtk.TreeView(cqk_model)
        cqk_view.set_headers_visible(False)
        cqk_view.append_column(c0)
        cqk_view.append_column(c1)
        cqk_view.connect('focus-out-event', cqk_view_focus_lost)
        return (view, cqk_view)