For a lot of Plug-ins the standard way of building it is sufficient, nice and easy, if you have done it once
yourself.
BUT if you need a better UI for your new plugin, one probably is forced to use gtk, right?
Nice example is the Arakne guide-lab!!! My starting point of leaning gtk.
There must be a lot of people knowing gtk and its marvelous possibilities. Finding something on the internet succeeds partially. But becomes more difficult if you need some special things you can not find, and at least not suitable directly for GimpFu.
Here my (not perfect) but working example together with some "know how" for using the Python Console of Gimp (used in 2.8.18).
Copy the following code into the Python Console of Gimp:
#http://mailman.daa.com.au/cgi-bin/pipermail/pygtk/2003-February/004454.html
import gobject
import gtk
result = None
COLUMN_TEXT=0
class ComboBoxSelectPattern():
def __init__(self):
self.win = gtk.Window()
# initialize the ListStore. Fom more complicated lists, see pygtk src example
# pygtk-demo/demos/list_store.py
#mydata = ['John', 'Miriam', 'Rahel', 'Ava', 'Baerbel']
num_patterns, mydata = pdb.gimp_patterns_list('')
#PKHG>ORIG model = gtk.ListStore(gobject.TYPE_STRING)
model = gtk.ListStore(str)
for item in mydata:
iter = model.append()
model.set(iter, COLUMN_TEXT, item)
# set up the self.treeview to do multiple selection
self.treeview = gtk.TreeView(model)
self.treeview.set_rules_hint(gtk.TRUE)
column = gtk.TreeViewColumn('Name', gtk.CellRendererText(),
text=COLUMN_TEXT)
self.treeview.append_column(column)
self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
# when you click ok, call this function for each selected item
def foreach(self, model, path, iter, selected):
selected.append(model.get_value(iter, COLUMN_TEXT))
def ok_clicked(self, event):
global result
selected = []
self.treeview.get_selection().selected_foreach(self.foreach, selected)
print 'And the winners are...', selected
result = selected
#gtk.main_quit()
def setValues(self):
# the rest is just window boilerplate
#win = gtk.Window()
#win.connect('destroy', lambda win: gtk.main_quit())
self.win.set_title('GtkListStore demo')
self.win.set_border_width(8)
vbox = gtk.VBox(gtk.FALSE, 8)
self.win.add(vbox)
label = gtk.Label('Choose patterns to use')
vbox.pack_start(label, gtk.FALSE, gtk.FALSE)
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)
sw.add(self.treeview)
self.win.set_default_size(280, 250)
button = gtk.Button('OK')
button.show()
button.connect("clicked", self.ok_clicked )
vbox.pack_end(button,gtk.FALSE)
self.win.show_all()
def main(self):
self.setValues()
gtk.main()
cw = ComboBoxSelectPattern()
cw.main()
You should find a new Window with title: GtkListStore demo
Go there and chose more than one Item, Shift and Ctrl (W10 Laptop) work too in choosing!!!
My last Console lines:
...
>>> cw = ComboBoxSelectPattern()
>>>
>>> cw.main()
And the winners are... ['alpha-tile_1', 'alpha-tile_1 #1', 'c1', 'Kachel_1', 'tile_2']
>>>
>>> result
['alpha-tile_1', 'alpha-tile_1 #1', 'c1', 'Kachel_1', 'tile_2']
>>>
After OK and using Close of the Console!
(I am aware of not best way of doing this, but you may see with what problems "beginners" are confronted).
Ideas?