It is currently Sat Dec 20, 2014 2:54 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 7:19 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Feb 17, 2013
Posts: 38
instead of the non-standard, non-compatible, often annoying GTK window,
use a Windows standard/native dialog.

EDIT:
I have edited ALL this post; Thank you for testing it!
download temporarily removed due to a bug


save_as_windows.py
plugin for GIMP
---------------------

THIS IS STILL WORK IN PROGRESS.
DON'T EXPECT IT TO BE EASY TO INSTALL

rationale:
----------
Instead of the non-standard, non-compatible, often annoying GTK window,
this plugin shows a Windows standard/native save/open dialog.

GTK dialog has nice features, but it still annoys me very much. I'm sure that windows users, esp. beginners and power users will find this dialog useful.

Also,
I really don't like to have 2 separate menus for SAVE and EXPORT.
Since i know enough about graphics and formats, I can actively decide when and why to choose XCF or JPG each time I see a "save" dialog...
So this plugin has 1 menu entry for both XCF and other types, as it used to be several years ago.



NOTE:
-----
The plugin depends on external library (either pywin32, wxpython, or tkinter)
- wxPython (best, cross-platform, but 30MB is not shippable, i cant attach here even wx.7z file)
- tk (cross-platform, but I couldn't make it work)
- win32 (only on windows, 7mb, not easy to install?)
- kde (i didn't try, but they have a very usable dialog with similar look and feel)

(i implemented both, because i don't mind the extra MBs, and because i have both windows and linux)


Bugs:
-------
see "questions" below


Installation:
-------------
1. INSTALLATION IS NOT ORGANIZED, AND IS NOT EASY.
2. it's just quick-and-dirty, certainly not the correct way of installing python plugins
3. this plugin was not (yet) developed for linux. it might even work out of the box (without the next steps)

4. choose if you're going to use pywin32, wx, or tkiner(incomplete!). I recommend on wxpython.
5. find out which python version, and architecture (32bit/64bit)
in my portable-gimp, i found "python.exe", double-click it, and it printed the version.
in my case it was "Python 2.7.5 (May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]"
which means i have a python version 2.7, 32bit.

6. copy save-as-windows.py to your plug-ins folder

7. once you (re)start Gimp, There are 2 new menu items:
File > Open as windows, File > Save as windows

8. you might want to change save/keyboard bindings to this plugin.



installing pywin32 (for Windows only):
-----------------------------------------
1. download pywin32 for python 2.7 (depends on your gimp version), must be 32 bit
2. extract its contents (using total commander or 7zip or something)
3. create a sub-folder in gimp's \plug-ins\ called "win32"
4. copy some* files from pywin32 package to your \plug-ins\win32\ it looks like:
gimp\plug-ins\win32\*.py
gimp\plug-ins\win32\*.pyd
gimp\plug-ins\win32\lib\(...)
gimp\plug-ins\win32\pywin32_system32\(*.dll)
gimp\plug-ins\win32\win32com\client\(...)
gimp\plug-ins\win32\win32com\(...)
gimp\plug-ins\win32\win32comext\(...)

But this is WRONG: .gimp-2.8/plug-ins/win32/win32/*.py

installing wx:
1. download wxPython for python 2.7 (depends on your gimp version), 32 bit
2. copy the wxPython's library "wx" directory to the plug-ins\ dir*
so you see something like:
gimp\plug-ins\wx\*.py
gimp\plug-ins\wx\*.pyd
gimp\plug-ins\wx\py\*.py

* most of them are NOT necessary, but i haven't checked which.

Questions
---------
1. ANSWERED: can i replace gimp's default menu entries?
2. ANSWERED: f I run the plugin while there's no image opened in Gimp, gimp shows me a parameters dialog.
3. ANSWERED: why the image is not shown
4. ANSWERED: how to combine 2 menu entries in 1 plugin
5. ANSWERED: when saving the image, the window's title doesn't change according to the new name.
6. How to add my recently saved file to the "File > Open Recent" list?

Full answers (with help from ofnuts):
2. the menu label must also be defined as "<Toolbox>". If it is defined as <Image>, gimp passes automagically 2 parameters (img, drawable) to my function, and shows a dialog
4. nothing is "simple";) you have to know which menu prefix (as above) to use, and to use very particular value to "imagetypes". See my code for very ilustraded call to "register()"
5. pdb.gimp_image_set_filename(active_image, f)

Ideally,
--------
There should be system-wide GTK flag that chooses between native and gtk dialog.
This is probably will never happen, so GTK recommend using the same method for native dialogs
http://faq.pygtk.org/index.py?req=edit& ... 21.013.htp

Todo:
------
- on open, add preview (i am not going to implement it on my own)
- remember directory or use current image's directory
- create a list or zip of the depedencies (wx or win32) with only the necessary files
- add a filter with possible extensions (i use almost always gif, jpg, png and xcf, so i don't need this feature)


Attachments:
File comment: updated, 23-march-2014, most bugs solved
save-as-windows.zip [74.87 KiB]
Downloaded 58 times
File comment: works only for python 2.7, 32 bit
win32.7z [1.31 MiB]
Downloaded 67 times


Last edited by keshef on Sun Mar 23, 2014 12:19 pm, edited 5 times in total.
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 7:23 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Feb 17, 2013
Posts: 38
my next step is very ambitious:
to create a plugin browser, with filter/effect/image previews, searchable with keywords.


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 7:54 pm  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 2527
1) None I know of, within the reach of a plugin. Remember, you are doing a plugin, not a fork of the main code.
2) Register a plugin that takes no parameters (no even an image)
3) You have to give a display to you image:
image=pdb.gimp_file_load(filename, raw_filename)
display=gimp.Display(image)

4) Yes, just have two register() calls, one for each function. Btw, since Gimp automatically prefixes "python-fu-" to your names you can register more simply as "open-windows-dialog".

The GTK dialog is more user-friendly than you think, especially in environment where all apps use it. For instance it remembers the last files saved using it, so if you need to open them in another app shortly after (frequent use case for me: export a screenshot in Gimp, and upload it in Firefox), they are easy to find. I wouldn't see much purpose in importing the WIndows-style dialog on Linux or OSX.

_________________
Image


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 8:55 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 3807
Location: Bendigo Vic. Australia
keshef it's hard to even know what to comment on I've installed 2 python files in my plugins directory 'open_as_windows.py' and 'save_as_windows.py' they are in my File Menu but do nothing
I also downloaded the Win32.7Z package but it doesn't contain the wxPython's library "wx" directory

_________________
Image


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 11:13 pm  (#5) 
Offline
GimpChat Member

Joined: May 23, 2012
Posts: 175
Image

i have not tested yet but
it dose show, have to make wx dir in plug-ins.
thanks keshef, good work


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 11:55 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 3807
Location: Bendigo Vic. Australia
If I make a wx dir in my userfiles/plug-ins what do I put in it?

_________________
Image


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sat Mar 22, 2014 11:59 pm  (#7) 
Offline
GimpChat Member

Joined: May 23, 2012
Posts: 175
i did not put anything in it.


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 12:19 am  (#8) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 3807
Location: Bendigo Vic. Australia
Instead of empty "wx" folder I downloaded and inserted the win32 folder but it gave this error

Traceback (most recent call last):
  File "C:\gimp_2_8_10-64bits-Portable\32\lib\gimp\2.0\python\gimpfu.py", line 699, in response
    dialog.res = run_script(params)
  File "C:\gimp_2_8_10-64bits-Portable\32\lib\gimp\2.0\python\gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "C:\gimp_2_8_10-64bits-Portable\Preferences\plug-ins\open_as_windows.py", line 102, in python_fu_open_windows_dialog
    f = open_as_win32(initial_dir, default_file_name, title="Open", types='*.*')
  File "C:\gimp_2_8_10-64bits-Portable\Preferences\plug-ins\open_as_windows.py", line 50, in open_as_win32
    from win32 import win32gui, win32con
ImportError: DLL load failed: The specified module could not be found.

_________________
Image


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 12:46 am  (#9) 
Offline
GimpChat Member

Joined: May 23, 2012
Posts: 175
my gimp is 2.8.10 32bit

i put the win32 folder in plug-ins
because of the python execute and sub folders
inside the win32 folder.
gimp has a hard time finding .exe files,
more than one level below plug-ins dir.
but as i said i have not tested it yet.


Top
 Profile  
 
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 12:59 am  (#10) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 3807
Location: Bendigo Vic. Australia
I am using a 64bit gimp to test, is this only compatible with 32bit

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login  

* Subscribe to Gimp Chat's RSS Feed    * Subscribe to Gimp Chat's Tutorial Feed    * Subscribe to Gimp Chat's G'MIC Feed


Powered by phpBB3 © phpBB Group