コード例 #1
0
ファイル: __init__.py プロジェクト: mrmoneyc/lazyscripts
    def load_tree(self, list_store, scripts_list_file):
        loc = locale.getlocale (locale.LC_ALL)
        lzs_loc = ""
        if (loc[0] == None):
            lzs_loc = "enUS"
        else:
            lzs_loc = loc[0].replace ("_", "")

        scripts_list = ScriptsList(scripts_list_file)
        scripts_list.update()
        script_set = ScriptSet.from_scriptslist(scripts_list)
        for category in script_set.categories():
            category.lang = lzs_loc
            tool_page = ToolPage()
            tool_page.title = category.name
            tool_page.img = category._icon_name

            for script in category.items():
                tool = Tool (script, script.selected)
                tool_page.tools.append(tool)

            tool_page.get_widget()
            list_store.append( (tool_page.img, tool_page.title, tool_page) )
            self.all_tools.append(tool_page)
コード例 #2
0
class Editor:
    def __init__ (self):
        # Model
        self.scripts_liststore = gtk.ListStore \
            (gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)

        self.scripts_list = ScriptsList (get_root()+"/conf/scripts.list")
        self.scripts_list.update ()

        for entry in self.scripts_list.items():
            if not entry.has_key ("selected"):
                entry['selected'] = False
            self.scripts_liststore.append((entry['selected'], entry['name'], entry))

        # View
        self.window = gtk.Window ()
        self.window.set_title ("scripts.list editor")
        self.window.set_size_request (400, 400)

        self.scroll = gtk.ScrolledWindow ()
        self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)

        self.treeview = gtk.TreeView ()
        self.vbox = gtk.VBox (False, 10)

        self.ok_button = gtk.Button ("OK")
        self.ok_button.connect ("clicked", self.on_press_ok, None)

        self.scroll.add (self.treeview)
        self.vbox.pack_start (self.scroll, True, True, 0)
        self.vbox.pack_start (self.ok_button, False, False, 0)
        self.window.add (self.vbox)

        # first column
        render = gtk.CellRendererToggle ()
        render.set_property ('activatable', True)
        render.set_property ('width', 20)
        render.connect ('toggled', self.on_toggled, self.scripts_liststore)
        col = gtk.TreeViewColumn ()
        col.pack_start (render)
        col.set_attributes (render, active=0)
        self.treeview.append_column (col)

        # second column
        col = gtk.TreeViewColumn ("items")
        render=gtk.CellRendererText ()
        col.pack_start (render)
        col.set_attributes (render, markup=1)
        self.treeview.append_column (col)

        self.treeview.set_model (self.scripts_liststore)

        self.treeview.show ()
        self.scroll.show ()
        self.window.show_all ()

        # Controller
        self.window.connect ("destroy", gtk.main_quit)

    def on_toggled (self, render, path, list):
        it = list.get_iter_from_string(path)
        used, entry = list.get (it, 0, 2)
        entry['selected'] = not used
        list.set (it, 0, not used)

    def on_press_ok (self, button, data):
        self.scripts_list.save ()
        gtk.main_quit ()