gimp python plug in: how to trigger another user input - python

Situation:
My gimp python plug-in shows the user a drop down box with two options [".jpg", ".png"].
Question:
How to show a second input window with conditional content based on first input?
.jpg --> "Quality" range slider [0 - 100]
.png --> "Compression" range slider [0 - 9]
In different words:
How to trigger a (registered) plug-in WITH user-input-window from within the main function of a plug-in?

Either you build a full GUI with PyGTK (or perhaps tkinter) or you find another way. Typically for this if you stick to the auto-generated dialogs you have the choice between:
a somewhat clumsy dialog that asks for both parameters and will ignore one or the other depending of the image format,
two menu entries for two different dialogs, one for PNG and one for JPG.
On the other hand, I have always use compression level 9 in my PNGs (AFAIK the only benefit of other levels is CPU time, but this is moot in modern machines) so your dialog could only ask for the JPEG quality which would mak it less clumsy.
However... JPEG quality isn't all there is to it and there are actually many options (chroma sub-sampling being IMHO at least as important as quality), and to satisfy all needs you could end up with a rather complex dialog. So you could either:
Just save with the current user's default settings (gimp_file_save())
Get these settings from some .ini file (they are less likely to change than other parameters of your script)
Not save the image and let the user Save/Export to his/her liking (if this isn't a batch processing script)

Related

Change desktop wallpaper on certain monitor? [duplicate]

I'm using:
ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,
0, "picturefile", 0)
To change the wallpaper.
But I'm wondering if there's any simple way to put different wallpapers on each screen.
This feature isn't standard in windows though, but there are external applications like ultramon that do this. Anyone know how that works?
The way I thought it might work if I join the two images together into one and then make that the wallpaper, but then I still need a way to span one image accross both screens.
Also, how could I grab some info about the monitor setup, the resolution of each screen and their placement? Like what you see in the gui display settings in windows, but in numbers.
After joining the images together into a big image, you have to set the wallpaper mode to tiled to make it so the image spans the desktop (otherwise it will restart on each monitor).
Couple of ways to do this:
a) Using IActiveDesktop (which does not require Active Desktop to be used, don't worry). This is nicest as on Win7 the new wallpaper will fade in.
You create an IActiveDesktop / CLSID_ActiveDesktop COM object and then call SetWallpaper, SetWallpaperOptions and finally ApplyChanges. (As I'm not a Python dev, I'm not sure exactly how you access the COM object, sorry.)
OR:
b) Via the registry. This isn't as nice, but works well enough.
Under HKEY_CURRENT_USER\Control Panel\Desktop set:
TileWallpaper to (REG_SZ) 1 (i.e. the string "1" not the number 1)
WallpaperStyle to (REG_SZ) 0 (i.e. the string "0" not the number 0)
Then call SystemParameterInfo(SPI_SETDESKTOPWALLPAPER...) as you do already.
.
By the way, the code I'm looking at, which uses IActiveDesktop and falls back on the registry if that fails, passes SPIF_UPDATEINIFILE | SPIF_SENDCHANGE as the last argument to SystemParameterInfo; you're currently passing 0 which could be wrong.
EnumDisplayMonitors is the Win32 API for getting details on the monitors, including their screen sizes and positions relative to each other.
That API returns its results via a callback function that you have to provide. (It calls it once for each monitor.) I am not a Python developer so I'm not sure how you can call such a function from Python.
A quick Google for "Python EnumWindows" (EnumWindows being a commonly-used API which returns results in the same way) finds people talking about that, and using a Lambda function for the callback, so it looks like it's possible but I'll leave it to someone who knows more about Python.
Note: Remember to cope with monitors that aren't right next to each other or aren't aligned with each other. Your compiled image may need to have blank areas to make things line up right on all the monitors. If you move one of the monitors around and do a PrtScn screenshot of the whole desktop you'll see what I mean in the result.

Creating GIMP interface plugins

So basically I'm looking for a way to write a GIMP plugin in Python that would create some additional user interface elements and allow me to add some functionality on top of what the GIMP has.
Question(s) are:
Is this even possible?
If yes then where is it best to look for a guide?
(or perhaps which source files would I be recomended to read upon, or maybe somebody could point me to a good example plugin I could get use of)
To let you get a better glimpse of what I need is I want create a custom tool-like plugin, a path editor, that would be able to display them in the editing viewport and list in and additional window. I welcome even any tips on the topic.
So -
It is possible to create plug-ins for GIMP in Python, C, Scheme and some other languages with varying levels of support, as no one maintains the binds for them.
However, these plug-ins interact with GIMP only exchanging data and issuing commands to GIMP through a GIMP-only "wire" protocol - it is not possible for a GIMP plug-in, in Python or otherwise, to create additional UI elements in GIMP but what they create by themselves on their own windows.
Also, it is not possible to receive events from GIMP's UI on the plug-in itself. Up to today, the workaround for plug-ins that need user input on the image itself is to draw an image preview on the plug-in window (which some plug-ins that ship with GIMP 2.8 do) - or, for example, to ask the user to create an specific Path, using the path nodes as markers that can be retrieved from the plug-in.
Due to this constraints, it is not possible to create a custom tool or path editor. You can however do these things in GIMP's main code itself and propose a patch to the project - but them, you have to use C + gobject.

Display GUI component In Ignition dynamically using Python/Jython Script

Currently I am showing a number of user-defined GUI components (templates) (let's give it a name: signal) in some of my main windows. Those GUI components are spread around the windows and are quite a lot in number (>50 per window) and I have multiple of such windows.
I have created all those windows using Ignition GUI and so far they are done... but... Now, there is a requirement to make whatever signal is displayed in the GUI window to be shown in a list of GUI.
My questions are:
How to obtain list of GUI component (template) of the same type (signal) using Ignition Python/Jython Script?
How to get its custom properties (such as customDisplayName)
How to draw the GUI component (template) dynamically?
As of now, it is possible for me to drag and drop components (making exact copy of the displayed signals) in the container list I use to display the signal template. But since it is possible for new signal to be added in the GUI, I am looking for a more automated solution (if there is any).
Ignition supports obtaining of the GUI components by .components from the container type component using Jython script.
So in the end, the implementation of my solution for this question was:
for comp in rootcontainer.components: #looping through every component in the root container
if 'MySignal' in comp.name: #check the name of the component, see if it matches
#do the logic here

Python-spawned subprocess jpgs in new window and exit on completion

I have a file containing thus far some 1800 jpegs (it will grow) which I have to search manually for specific features. This requires that I enter a code (1 or 0) to say whether or not the features that I am looking for exist.
Because the features are difficult to define, the images of low quality and as far as we are aware no non-deterministic approach exists to deal with this satisfactorily it has to be coded.
The idea is to open the large_file containing the jpegs, open each of them in a new window one-by-one (so that I can see them), read in data from the screen and then close the new window.
Roughly this looks something like this:
large_file = open (xxxxxx, rb) # contains info identifying jpeg
for jpeg in large_file: # 1800 items now more later
open jpeg in separate window
does image meet the criterion?: # Enter 1 or 0 (say) at console
if (1 or 0):
close window and move to next image
else:
go back and ask for sensible input
large_file.close()
I am running Kubuntu 14.04 with lightdm as the display manager and Python 2.7.6. Browsing Stackoverflow doesn't really get me what I need.
Implementing using Image cause problems because I am not using xv, but lightdm. Several strategies have not worked properly. Clearly the core issue is spawning the new window and then closing it.
Any suggestions? In an ideal world I would prefer not to have to close images manually...
Many thanks

What signals should I catch when scrolling in a Gtk ScrolledWindow?

I'm developing a python plugin for Rhythmbox - this contains a GtkScrolledWindow with a child which is a GtkIconView. The IconView is fed from a Gtk.TreeModel.
It looks like this:
Currently - and somewhat inefficient, every icon is drawn for every row in the tree-model - each icon is a GdkPixbuf from a file. If you have thousands of rows, it can take quite a while for the whole iconview to be fully updated with every picture icon.
What I am trying to achieve is to only update the icons that are in the current drawing area - when the user scrolls and releases the scrollbar (or navigates via the keyboard), the icons in the new drawing area should be updated with relevant pictures.
N.B. - the tree-model would be fully populated at this point - only the icons would not have been loaded.
This is not really my area of expertise - I'm looking for pointers for the best approach I should use to achieve the above.
Specifically - which Gtk+3 drawing-area signal (or signals) can be exposed (Gtk.ScrolledWindow / Gtk.IconView ?) to write python code to calculate what icons should be updated?
You should profile you application to see what takes time.
Is that loading the images ? If it is, then loading a default image and adding it everywhere in your view would be quick enough, as you'd load only one image. You'd then load and update the images on-demand using idle_add, based on the images that should appear in the viewport.
If what takes times is adding the images to the model, then you'd need to do the adding on-demand, by checking what is visible on the viewport in your idle_add callback.
If both are slow, you'd need a mix of both solutions: loading and adding on-demand.
Think also about the proxy design pattern that can be useful to create a fake cover object that will load in the background, and contain the loading policy.
For the signals, your GtkIconView widget implements GtkScrollable, which explains how to implement scrolling. You'd set your vertical adjustment and check when it has changed by connecting to its value-changed signal. This would mean the user scrolled up or down, and you'd need to fire up a timer with timeout_add. If after a short timeout (between 0.5 and 1s I think, but needs testing), the adjustment hasn't changed, this means the user stopped scrolling, and you can update what is displayed. Otherwise, it would be updated during the scrolling, slowing everything down. You then just need to figure out how to find which items appear in the viewport, to update their cover.
I've never done this before though, but I know GTK a bit and just tried to figure out how it would be done, so read that with a bit of caution. Anyway, the answer to reactivity is "on-demand".
But on the other hand if you have to scroll completely down, you would have to wait for every page to be build. So i guess you should better consider the idle_add function of the event loop.
This way your screen doesn't lock up and your pc doesn't have to wait for the user to load the view page for page. Win-Win for you and your application. ;-)

Categories