It is currently Fri Mar 29, 2024 8:19 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 2:45 am  (#1) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
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?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 7:51 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I would appreciate it if you took a step backwards and explained what you are trying to achieve with this post, because I am puzzled.

Is it a request for help? A tutorial? An example of PyGTK programming? Something else?


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 7:54 am  (#3) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4039
Kevin, I'm under the impression they (PKHG and MareroQ) are looking for more GTK resources to help them understand what all the possibilities are. As of now, they only have one plugin to go on to use as a template for testing.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 9:04 am  (#4) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
mahvin wrote:
Kevin, I'm under the impression they (PKHG and MareroQ) are looking for more GTK resources to help them understand what all the possibilities are. As of now, they only have one plugin to go on to use as a template for testing.


Indeed correct understood, the reason of this thread.
The example is meant to show, that you can adjust examples to be found on the internet and check them out in the Gimp Python Console :yes

At the top of the example is the link, inspiring me to build a class to checkout FIRST.
Being busy to build a plugin to fill a picture with several random 'tile' patterns. And the user should be able to select those, he likes to be used.

So if you know how to do that, differently, meaning BETTER then my example let me/us know.

This thread is meant to let gtk knowing Gimp users let us poor beginners help with creating nice suitable GUI's ;)


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 10:28 am  (#5) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Thank you for the explanation.

I can't help much as I've not done much with PyGTK, just the one simple Python script to place guides interactively.

Kevin


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 1:31 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4726
See http://www.python-forum.io , there is even a GUI section.

In addition you'll learn proper Python coding techniques :)

_________________
Image


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Fri Nov 04, 2016 3:29 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Mar 16, 2015
Posts: 613
Location: On Earth,specifically Queensland,Australia
ofnuts wrote:
See http://www.python-forum.io , there is even a GUI section.

In addition you'll learn proper Python coding techniques :)

Thanks Ofnuts for the link.

_________________
Image


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Sun Nov 06, 2016 1:48 pm  (#8) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
ofnuts wrote:
See http://www.python-forum.io , there is even a GUI section.

In addition you'll learn proper Python coding techniques :)


import Tkinter works in PythonFu of Gimp 2.8.18 , will have a look ;-)


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Sun Nov 06, 2016 1:50 pm  (#9) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
ofnuts wrote:
See http://www.python-forum.io , there is even a GUI section.

In addition you'll learn proper Python coding techniques :)


import Tkinter works in PythonFu of Gimp 2.8.18 , will have a look ;-)

My tries are now able to create something like this with only som "clicks" ;)

Used the "kachel" part ... adjusted guidelab (from Arakne)

Attachment:
guidelabextra_12.jpg
guidelabextra_12.jpg [ 121.72 KiB | Viewed 9852 times ]


Attachments:
ui_11oct.jpg
ui_11oct.jpg [ 77.86 KiB | Viewed 9818 times ]
Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Sat Nov 26, 2016 2:24 am  (#10) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
Meanwhile I found a lot of suitable Gtk examples
e.g. this one https://www.tutorialspoint.com/pygtk/pygtk_treeview_class.htm

My problem is, my Python versions do not know gtk or I am not clever enough to use what is available via Gimp.

So I am forced to use the Python console to learn gtk mean while I know what to adjust, change to see all those examples 'working' .

Mostly it suffices, if not otherwise done, this code at the end of an example class:
    def main(self):
        gtk.main()
        return


AND realizing, that the Python console of Gimp has difficulties, if there are not correctly indented empty lines, happens often by copy past from the www !!!

Attachment:
SEVERAL_SELECTIONS.JPG
SEVERAL_SELECTIONS.JPG [ 20.19 KiB | Viewed 9706 times ]


Had to figure out to get the indices of the via ctrl-select items, several ones at once, but found out ... ;-)


Top
 Post subject: Help, help pygtk strange, not understood
PostPosted: Mon Nov 28, 2016 5:54 am  (#11) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
RRRR ???? W10 64 bit Gimp 2.8.18
look at code please:
                clearbutton = gtk.Button("clear the selections done")
                clearbutton.connect("clicked", self.clear_selections)
                vbox.pack_end(clearbutton, gtk.FALSE)
                button = gtk.Button('OK (simple shapes choices done?!)')
                button.connect("clicked", self.ok_clicked)
                vbox.pack_end(button, gtk.FALSE)
               
                vbox.show_all()               
                t.attach(vbox, 0, 1, 0, 1)

t is a gtk.Table(2, 2, False)

Both buttons are shown, no error message ,

ok_clicked works if button is clicked (via gimp.message)
BUT
clearbutton.connect("clicked", self.clear_selections)
does NOT work if clearbutton is clicked ?????? (gimp.message used but does not show up)

What do I miss????


Top
 Post subject: Re: Help, help pygtk strange, not understood
PostPosted: Mon Nov 28, 2016 7:24 am  (#12) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
PKHG wrote:
RRRR ???? W10 64 bit Gimp 2.8.18
Both buttons are shown, no error message ,

ok_clicked works if button is clicked (via gimp.message)
BUT
clearbutton.connect("clicked", self.clear_selections)
does NOT work if clearbutton is clicked ?????? (gimp.message used but does not show up)

What do I miss????


Impossible to help unless you provide ALL the relevant parts of your code.


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Mon Nov 28, 2016 9:18 am  (#13) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
working of the part:
Attachment:
tab4toselectseveralandclear.jpg
tab4toselectseveralandclear.jpg [ 49.73 KiB | Viewed 5898 times ]


If a selection is done, I would like to clear it for next ... actions.

OK, here the plugin of today ... not yet totally finished , must be polished up and ...

EDIT : zip file deleted (see below my stupid error in it) ... Will come a bit later into github ;-)

Maybe you should get too from
https://github.com/PKHG/guidelab_paint/tree/master
Simple path shapes.py
then the simple shapes should be to be seen too,

if you install it it is the plugin it will be under Images => Guides => paint with guidelab

Greets
Peter


Last edited by PKHG on Tue Nov 29, 2016 3:14 am, edited 1 time in total.

Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Mon Nov 28, 2016 9:35 am  (#14) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I've taken a tip from Ofnuts and added this to your code:
import os
import sys
sys.stderr = open("C:\\tmp\\gimp_errs.txt",'a')


Then when I press the Clear Selections button and close the dialog, I get this in the gimp_errs.txt file:

Traceback (most recent call last):
  File "C:\Users\xxxx\Downloads\audit\python\guidelab_paint.py", line 210, in clear_selections
    debug(("L209", self.selected_items,self.selected_items_shapes,selected_items_patterns),1)
NameError: global name 'selected_items_patterns' is not defined


You need a self. in front of selected_items_patterns


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Tue Nov 29, 2016 3:12 am  (#15) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
Thanks a lot, what a stupid error of myself.
did not saw(?!) this message in an mysys shell , where I start Gimp to see compilation errors from the Python console ...

Greets
Peter


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Tue Dec 27, 2016 3:27 am  (#16) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
At github my latest version is in the master-branch:
Added history of guides: save, view, insert old history, delete a history.


Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Sun Feb 14, 2021 11:07 am  (#17) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
If the zip is really attached it contains two plug-ins working together
It is (by the way via thanks to Ofnuts !) an old arakneguideLab.py made a lot more things possible.

Gimp 2.10.22 on W10 laptop you may have to unpack the zip into
***/Appdata/Roaming/Gimp/2.10/plug-ins

A big change I found out lately: a plugin xxx.py needs a subdirectory ******/plug-ins/xxx with content xxx.py
The zip file contains TWO plugins they work together the

If installation works as is by me: there will be a tab PKHG in Gimp right of Filters tab with content Guides ==> paint with guidelab

Let me know if it works with your Gimp 2.10 ;-)


Attachments:
File comment: example the guides are saved and reset
after loading the origin

voorGimpForrum.jpg
voorGimpForrum.jpg [ 442.23 KiB | Viewed 5235 times ]
File comment: a zipfile to be expanded in ***/plug-ins
guidelabpaintshapescentered.zip [73.11 KiB]
Downloaded 62 times
Top
 Post subject: Re: Beginners and PyGtk, Plugins
PostPosted: Tue Feb 16, 2021 3:18 pm  (#18) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
Ofnuts, if I am right you are the creator of
ofn_path_to_shapes plugin.
Would you be so kind and let me know how to use the addon in Gimp 2.10 Windows?
Greets
Peter (PKHG)


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Having trouble with plugins

2

No new posts Attachment(s) I can't see the whole plugins menu

7

No new posts Attachment(s) Plugins don't work

2

No new posts Attachment(s) Ulead Plugins

3

No new posts Attachment(s) Brian plugins for Gimp-2.10

129



* Login  



Powered by phpBB3 © phpBB Group