It is currently Thu Mar 28, 2024 3:30 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  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: 36
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 215 times
File comment: works only for python 2.7, 32 bit
win32.7z [1.31 MiB]
Downloaded 229 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
 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: 36
my next step is very ambitious:
to create a plugin browser, with filter/effect/image previews, searchable with keywords.


Top
 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: 4726
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
 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: 4827
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
No matter how much you push the envelope, it'll still be stationery.


Top
 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: 150
Image

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


Top
 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: 4827
Location: Bendigo Vic. Australia
If I make a wx dir in my userfiles/plug-ins what do I put in it?

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 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: 150
i did not put anything in it.


Top
 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: 4827
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
No matter how much you push the envelope, it'll still be stationery.


Top
 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: 150
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
 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: 4827
Location: Bendigo Vic. Australia
I am using a 64bit gimp to test, is this only compatible with 32bit

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 1:51 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Strange.
I had to download the win32.7z file as a win32.zip file and open with 7 zip application. Otherwise it showed an empty 7z file download. (empty archive).

I placed the win32 folder in plug-ins along with a new wx directory (empty) and it initialized save as and open as python modules.

Image

Though selecting either did not open a save as dialog or open as dialog.

Windows 8.1 64 bit GIMP. Perhaps the python modules should be in the 32 bit folder?
AHHA! I had to make sure the tree wasn't ".gimp-2.8/plug-ins/win32/win32/python files". I simply made sure the tree was ".gimp-2.8/plug-ins/win32/python files" and all worked as they should.

Image

However shouldn't there be some sort of way to browse for the file you want to open? Same with save as. There should be a way to browse to a save directory.
The way this works now it attempts to use the already open drawable or image but upon selecting save as i get no response.
I am a little confused. Why would you want to open an already opened image in a windows dialog to open it again? Or perhaps i am miss-understanding the purpose of the plug-in?

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


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

Joined: Feb 17, 2013
Posts: 36
Thank you, ofnuts, i implemented your other answers

ofnuts wrote:
2) Register a plugin that takes no parameters (no even an image)

a) The register commands don't take any parameters now (lines 161, 146), but it still pops up the dialog
b) The dialog is shown only when there are no other images; it doesn't show when i have other images opened.

Can you help me on this?

ofnuts wrote:
The GTK dialog is more user-friendly (...), especially (...) where all apps use it. For instance it remembers the last files saved using it, (...) I wouldn't see much purpose in importing the WIndows-style dialog on Linux or OSX.

For me, the main concern is (not) having to use the mouse, or navigating too much in the dialog.
In Windows (and KDE?), when the dialog shows, i just write the path and press ENTER. For me this is the most important behavior. I just wish i had written the plugin 14 years ago, when i really needed it :)

Rod wrote:
AHHA! I had to make sure it was ".gimp-2.8/plug-ins/win32/python files" and all worked

thank you! I added it in the README.

Rod wrote:
However shouldn't there be some sort of way to browse for the file you want to open?

this is a bug; not a feature :) see my correspondance with ofnuts about it.
it will work if there are other open images (strange...)
I didn't understand your comment about the "save as windows"? Does it work for you?

Mikechat wrote:
it dose show, have to make wx dir in plug-ins.
thanks keshef, good work

So you work with the WX version? nice! mine stopped working :( so i'm using pywin32

Graechan
I added install instructions;
can you tell me what is your PYTHON.EXE version & bits?
where is your "plug-ins" folder?
(I guess I will not be using windows 8 in the next several years but it should be the same as 7)


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 12:26 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Feb 17, 2013
Posts: 36
for anyone who still reads this, i've updated the scripts and solved the bugs.


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

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
keshef wrote:
For me, the main concern is (not) having to use the mouse, or navigating too much in the dialog.
In Windows (and KDE?), when the dialog shows, i just write the path and press ENTER. For me this is the most important behavior. I just wish i had written the plugin 14 years ago, when i really needed it :)

If you do not have a "Location:" text entry in your GTK Open dialog, you can use the CTRL-L keyboard shortcut to have one added. Once added, it should be available for all subsequent usages.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Sun Mar 23, 2014 6:42 pm  (#15) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Still to much confusion with install the win32 folder should only contain whats necessary so that the instruction could read place 32 folder in plugins folder and in your save as windows zip what is easygui.py for

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Mon Mar 24, 2014 1:00 am  (#16) 
Offline
GimpChat Member
User avatar

Joined: Mar 18, 2011
Posts: 283
Location: Lusaka, Zambia
Hi,

Why can't we just have a better/standard image browse dialogue such as already proposed here?

Is it the intention of this thread?

Still :gimp

joseph


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Mon Mar 24, 2014 2:10 am  (#17) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 5128
Location: Metro Vancouver, BC
josephbupe wrote:
Hi,

Why can't we just have a better/standard image browse dialogue such as already proposed here?

Is it the intention of this thread?

Still :gimp

joseph
I like that idea Joseph.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Mon Mar 24, 2014 2:39 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: Feb 17, 2013
Posts: 36
josephbupe wrote:
Why can't we just have a better/standard image browse dialogue such as already proposed ?


i think modern systems now has thumbnail view already built in.
i don't know about GTK, but for Windows it either happens automatically or you need to click a button and "view as thumbnails" or something

josephbupe wrote:
Is it the intention of this thread?


no.
My personal intention is to have fastest, easiest, and most similar look and feel.

Since i'm using anyway Windows (95, 98, NT, 2000, xp, 7, 2003), and prefer the KDE environment, i'm more "fluid" with non-gtk style of dialogs.

Saulgoode gave us a tip about using current dialog more efficiently, and i'm going to try it
(viewtopic.php?f=9&t=10017&start=10#p131080)

Also, i don't use GIMP as a file browser.
for that I use Total commander (on windows) / Double Commander (on linux) - both have built-in thumbnail preview.

the same way I don't use emacs as an operating system... ;)


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Mon Mar 24, 2014 3:21 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
I re downloaded and installed all the newer python modules in the first post.
I opened a recent image and tried "Open As Windows Dialog2" and all works well.
Image

I installed the wxPython to my Python27 application folder. I copied the entire wx folder to my .gimp-2.8/plug-ins folder and launched Gimp-2.8 64 bit installed Gimp.org version.

Results for Save As Windows Dialog -
I select the "Save Windows Dialog" in the File menu and nothing happens.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: my first plugin - Windows save/open dialog instead of GTK
PostPosted: Mon Mar 24, 2014 11:43 am  (#20) 
Offline
GimpChat Member
User avatar

Joined: Feb 17, 2013
Posts: 36
Rod wrote:
I re downloaded and installed all the newer python modules in the first post.
I opened a recent image and tried "Open As Windows Dialog2"
...
Results for Save As Windows Dialog -
I select the "Save Windows Dialog" in the File menu and nothing happens.


i uploaded new script version.
please update "save-as-windows.py",
and DELETE "open-as-windows.py" from your plugins script, since it's not needed anymore (i unified both files into 1 script)


Top
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How to tab to an open dialog, i.e. Scale Tool dialog?

1

No new posts Attachment(s) Save For Web Gimp 2.8 Windows

5

No new posts Attachment(s) Gimp tries to save a composed image to windows system32 by default

1

No new posts I could use some help getting started with a plugin on Windows

2

No new posts Where did GIMP save my file, & how do I change default save location

5



* Login  



Powered by phpBB3 © phpBB Group