[kernel] r5691 - people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor

Bastian Blank waldi at costa.debian.org
Thu Feb 2 22:57:15 UTC 2006


Author: waldi
Date: Thu Feb  2 22:57:13 2006
New Revision: 5691

Modified:
   people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py
Log:
debian/lib/python/debian_linux/kconfigeditor/editor.py: Update.


Modified: people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py
==============================================================================
--- people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py	(original)
+++ people/waldi/linux-2.6/debian/lib/python/debian_linux/kconfigeditor/editor.py	Thu Feb  2 22:57:13 2006
@@ -1,4 +1,5 @@
 from file import kconfigfile
+from debian_linux.utils import sorted_dict
 
 import pygtk
 import gtk
@@ -6,10 +7,7 @@
 _marker = object()
 
 class items_real(kconfigfile):
-    def __getitem__(self, key):
-        return self.get(key)
-
-    def get(self, key, default = _marker):
+    def get_summary(self, key, default = _marker):
         value = super(items_real, self).get(key, _marker)
         if value is _marker:
             if default is not _marker:
@@ -29,7 +27,15 @@
             if default is not _marker:
                 return default
             raise KeyError()
-        return '[%s]' % value
+        return value
+
+    def get_summary(self, key, default = _marker):
+        value = self.real.get_summary(key, _marker)
+        if value is _marker:
+            if default is not _marker:
+                return default
+            raise KeyError()
+        return value
 
 class editor(object):
     def __init__(self):
@@ -37,16 +43,18 @@
         self.columns = {}
         self.file_inodes = {}
         self.items = {}
+        self.variants = sorted_dict()
 
         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
         self.window.set_size_request(200, 200)
         self.window.set_title("KConfig editor")
-        self.window.connect("delete_event", self.delete_event)
-        self.window.connect("destroy", self.destroy)
+        self.window.connect("destroy", self.window_destroy)
 
         self.treestore = gtk.TreeStore(str)
 
         self.treeview = gtk.TreeView(self.treestore)
+        self.treeview.connect("row-activated", self.treeview_row_activated)
+
         tvoption = gtk.TreeViewColumn('Option')
         self.treeview.append_column(tvoption)
         cell = gtk.CellRendererText()
@@ -66,7 +74,7 @@
         self.columns[None] = col
 
     def add_data(self, arch, subarch = None, flavour = None):
-        if not self.columns.has_key(arch):
+        if not self.variants.has_key(arch):
             col = gtk.TreeViewColumn(arch)
             self.treeview.append_column(col)
             cell = gtk.CellRendererText()
@@ -74,16 +82,28 @@
             col.set_cell_data_func(cell, self.cell_data, (arch, None, None))
             self.cells[(arch, None, None)] = cell
             self.columns[arch] = col
-        if subarch is not None and not self.cells.has_key((arch, subarch, None)):
-            cell = gtk.CellRendererText()
-            self.columns[arch].pack_start(cell, False)
-            self.columns[arch].set_cell_data_func(cell, self.cell_data, (arch, subarch, None))
-            self.cells[(arch, subarch, None)] = cell
-        if flavour is not None and not self.cells.has_key((arch, subarch, flavour)):
+            self.variants[arch] = sorted_dict()
+
+        if subarch is None:
+            return
+        variant_arch = self.variants[arch]
+        if not variant_arch.has_key(subarch):
+            if subarch != 'none':
+                cell = gtk.CellRendererText()
+                self.columns[arch].pack_start(cell, False)
+                self.columns[arch].set_cell_data_func(cell, self.cell_data, (arch, subarch, None))
+                self.cells[(arch, subarch, None)] = cell
+            variant_arch[subarch] = sorted_dict()
+
+        if flavour is None:
+            return
+        variant_subarch = variant_arch[subarch]
+        if not variant_subarch.has_key(flavour):
             cell = gtk.CellRendererText()
             self.columns[arch].pack_start(cell, False)
             self.columns[arch].set_cell_data_func(cell, self.cell_data, (arch, subarch, flavour))
             self.cells[(arch, subarch, flavour)] = cell
+            variant_subarch[flavour] = True
 
     def add_file(self, file, arch = None, subarch = None, flavour = None):
         import os, stat
@@ -97,25 +117,9 @@
 
     def cell_data(self, column, cell, model, iter, data):
         key = model.get_value(iter, 0)
-        value = self.items[data].get(key, None)
-        text = ""
-        if value is not None:
-#            if data[2] is not None:
-#                if data[1] is None:
-#                    text = "%s: " % data[2]
-#                else:
-#                    text = "%s %s: " % data[1:]
-            text += str(value)
-        else:
-            text = "-"
+        text = self.items[data].get_summary(key, "-")
         cell.set_property('text', text)
 
-    def delete_event(self, widget, event, data = None):
-        return False
-
-    def destroy(self, widget, data = None):
-        gtk.main_quit()
-
     def show(self):
         tmp = {}
         for i in self.items.itervalues():
@@ -126,6 +130,118 @@
             self.treestore.append(None, [key])
         self.window.show_all()
 
+    def treeview_row_activated(self, treeview, path, view_column):
+        key = self.treestore.get_value(self.treestore.get_iter(path), 0)
+        edit_setting(self, key)
+
+    def window_destroy(self, widget, data = None):
+        gtk.main_quit()
+
+class edit_setting(object):
+    def __init__(self, editor, key):
+        self.editor = editor
+        self.key = key
+
+        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+        self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
+        self.window.set_title("Edit %s" % key)
+        self.window.set_transient_for(self.editor.window)
+        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+
+        box = gtk.VBox()
+        self.window.add(box)
+
+        action_area = gtk.HButtonBox()
+        box.pack_end(action_area)
+        action_area.set_border_width(5)
+        action_area.set_spacing(10)
+        action_area.set_layout(gtk.BUTTONBOX_END)
+
+        button = gtk.Button(stock = "gtk-close")
+        action_area.pack_end(button)
+        button.connect("clicked", lambda button: self.window.destroy())
+
+        sep = gtk.HSeparator()
+        box.pack_end(sep)
+
+        self.items = {}
+
+        notebook = gtk.Notebook()
+        box.pack_start(notebook)
+
+        table = gtk.Table(1, 3)
+        table.set_col_spacing(0, 5)
+        table.set_col_spacing(1, 5)
+
+        label = gtk.Label("global")
+        label.set_alignment(0, 0)
+        table.attach(label, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
+
+        table.attach(self.get_edit_label(key), 1, 2, 0, 1, gtk.FILL|gtk.EXPAND, gtk.FILL)
+        table.attach(self.get_edit_button(key), 2, 3, 0, 1, gtk.FILL, gtk.FILL)
+
+        notebook.append_page(table, gtk.Label("global"))
+
+        for arch, variant_arch in self.editor.variants.iteritems():
+            items = 1
+            for subarch, variant_subarch in variant_arch.iteritems():
+                if subarch != "none":
+                    items += 1
+                items += len(variant_subarch)
+
+            table = gtk.Table(items, 3)
+            table.set_col_spacing(0, 5)
+            table.set_col_spacing(1, 5)
+            item = 1
+
+            label = gtk.Label("global")
+            label.set_alignment(0, 0)
+            table.attach(label, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
+
+            table.attach(self.get_edit_label(key, arch), 1, 2, 0, 1, gtk.FILL|gtk.EXPAND, gtk.FILL)
+            table.attach(self.get_edit_button(key, arch), 2, 3, 0, 1, gtk.FILL, gtk.FILL)
+
+            for subarch, variant_subarch in variant_arch.iteritems():
+                text = ""
+                if subarch != "none":
+                    text = "Subarch %s / " % subarch
+                    label = gtk.Label(test + "global")
+                    label.set_alignment(0, 0)
+                    table.attach(label, 0, 1, item, item + 1, gtk.FILL, gtk.FILL)
+
+                    table.attach(self.get_edit_label(key, arch, subarch), 1, 2, item, item + 1, gtk.FILL|gtk.EXPAND, gtk.FILL)
+                    table.attach(self.get_edit_button(key, arch, subarch), 2, 3, item, item + 1, gtk.FILL, gtk.FILL)
+                    item = +1
+
+                for flavour in variant_subarch.iterkeys():
+                    label = gtk.Label("%sFlavour %s" % (text, flavour))
+                    label.set_alignment(0, 0)
+                    table.attach(label, 0, 1, item, item + 1, gtk.FILL, gtk.FILL)
+
+                    table.attach(self.get_edit_label(key, arch, subarch, flavour), 1, 2, item, item + 1, gtk.FILL|gtk.EXPAND, gtk.FILL)
+                    table.attach(self.get_edit_button(key, arch, subarch, flavour), 2, 3, item, item + 1, gtk.FILL, gtk.FILL)
+
+                    item += 1
+
+            notebook.append_page(table, gtk.Label(arch))
+
+        self.window.show_all()
+
+    def get_edit_button(self, name, arch = None, subarch = None, flavour = None):
+        key = (arch, subarch, flavour)
+        button = gtk.Button(stock = "gtk-edit")
+        return button
+
+    def get_edit_label(self, name, arch = None, subarch = None, flavour = None):
+        key = (arch, subarch, flavour)
+        label = gtk.Label()
+        text = self.editor.items[key].get(name, "-")
+        label.set_alignment(0, 0)
+        label.set_selectable(True)
+        label.set_text(text)
+        self.items[key] = label
+        return label
+
 if __name__ == '__main__':
     e = editor()
     from file import kconfigfile



More information about the Kernel-svn-changes mailing list