Public paste
python treeview editable???
By: silwol | Date: Aug 21 2007 06:45 | Format: None | Expires: never | Size: 2.04 KB | Hits: 657

  1. try:
  2.   import pygtk
  3.   pygtk.require("2.0")
  4. except:
  5.   pass
  6. try:
  7.   import gtk
  8. except:
  9.   print "You need to install pyGTK or GTKv2"
  10.   sys.exit(1)
  11.  
  12. import gobject
  13.  
  14. TypeSpin = 0
  15. TypeEnum = 1
  16.  
  17. class sceneinfo_treeview(gtk.TreeView):
  18.   def __init__(self, knob):
  19.     gtk.TreeView.__init__(self)
  20.  
  21.     self.knob = knob
  22.  
  23.     self.model = gtk.TreeStore(
  24.         gobject.TYPE_STRING,    # Name of the register
  25.         gobject.TYPE_INT,       # The associated value
  26.         gobject.TYPE_BOOLEAN,   # Is Spin?
  27.         gobject.TYPE_BOOLEAN,   # Is Enum?
  28.         gobject.TYPE_INT,       # The min value
  29.         gobject.TYPE_INT,       # The max value
  30.         gobject.TYPE_INT,       # The register number
  31.         gobject.TYPE_BOOLEAN,   # editable
  32.         )
  33.  
  34.     self.set_model(self.model)
  35.  
  36.     renderer = gtk.CellRendererText()
  37.     self.name_column = gtk.TreeViewColumn(
  38.         "Register",
  39.         renderer,
  40.         text = 0
  41.         )
  42.     self.append_column(self.name_column)
  43.  
  44.     renderer_combo = gtk.CellRendererCombo()
  45.     renderer_spin = gtk.CellRendererSpin()
  46.  
  47.     self.value_column = gtk.TreeViewColumn(
  48.         "Value"
  49.         )
  50.     self.value_column.pack_start(renderer_combo, True)
  51.     self.value_column.set_attributes(renderer_combo, text=1, visible=3, editable=7)
  52.     self.value_column.pack_start(renderer_spin, True)
  53.     self.value_column.set_attributes(renderer_spin, text=1, visible=2, editable=7)
  54.     self.append_column(self.value_column)
  55.  
  56.     self.type_column = gtk.TreeViewColumn(
  57.         "Type",
  58.         renderer,
  59.         text = 7
  60.         )
  61.     self.append_column(self.type_column)
  62.  
  63.     self.show_all()
  64.  
  65.   def add(self, name, value, registernumber, type, min, max, editable):
  66.     if type == TypeEnum:
  67.       enum = True
  68.       spin = False
  69.     else:
  70.       enum = False
  71.       spin = True
  72.     iter = self.model.append(
  73.         None,
  74.         (
  75.           name,
  76.           value,
  77.           spin,
  78.           enum,
  79.           min,
  80.           max,
  81.           registernumber,
  82.           editable,
  83.         )
  84.     )
  85.  
  86.  
Latest pastes
8 hours ago
18 hours ago
2 days ago
3 days ago
3 days ago