GtkDialog File Selector Work Around 0.1

Miscellaneous tools
Post Reply
Message
Author
User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

GtkDialog File Selector Work Around 0.1

#1 Post by LazY Puppy »

Hi.

Yes, it's me. Today I have changed my User Name to LazY Puppy and also established a E-Mail Adress, lazy-puppy@xxx.xx. Just for some conceptional continuity.

Ok, here we go...

For my GDAM Builder, a all new, complex Application, also huge in functionality I had the need to reduce Buttons inside of the GtkDialog Program. Since I really do like Menus, I decided to put all Buttons to open and/or save Files into a Menu instead. As soon as I began to rework this Application, I ran into the Problem, that one can't use the GtkDialog File Selector Widget from a Menu Entry. The only thing that works is the Chooser Widget, which is really uncomfortable and should be deprecated (i.m.o.).

So I did some research in some Applications but found only the use of the Chooser Widget by Menu Entry - even in Zigbert's PMusic(!). Again I did start some Work to get the Problem solved.

My Solution depends on xdotool!

I have packaged this into the attached .pet Package for all GtkDialog Programmers, that may find it somehow useful. Also I have integrated Zigbert's Solution into this Package.

Files inside the Package:

/usr/sbin/file_chooser
/usr/sbin/file_saver
/usr/sbin/my_RSH_gtk_fileselect_workaround
/usr/sbin/my_RSH_gtk_fileselect_workaround_hit_return


Usage:

# Examples for a call:

my_RSH_gtk_fileselect_workaround "Load" "/usr/bin" "*.cfg" "filename" "/tmp/my_return_file_containing_the_results.txt"
my_RSH_gtk_fileselect_workaround "Save as" "/usr/bin" "*.cfg" "savefilename" "/tmp/my_return_file_containing_the_results.txt"


Note: filename and savefilename are Modi for the File Selector - NOT File Names!

One could add an additional Parameter submitted at the last of all Parameters.

- MODE

Example:

my_RSH_gtk_fileselect_workaround "Save as" "/usr/bin" "*.cfg" "savefilename" "/tmp/my_return_file_containing_the_results.txt" "0"

which could be 0 or any else Numeric Char. Submitted Parameter = 0 will use the File Selector Solution of my_RSH_gtk_fileselect_workaround any else submitted Parameter will bypass to either file_chooser or to file_saver, which then will be just the Chooser Widget in use.

Important:

Do use it only from a Menu Entry - NOT by a Button.

As for Keyboard Shortcuts used, like Strg-O: the File Selector will appear after the Strg (or Alt or Shift) Key is released.

How is this working?

It just creates a GtkDialog Window sized to 1x1 Pixel, containing a Entry Widget, invisible and sized to 1x1 Pixel plus a Button Widget sized 1x1 Pixel without Relief. The Button widget has: has-focus="true", has-default="true" and can-default="true", so it will definitely grab any Retrun Key pressed/submitted.

Right before the GtkDialog GUI appears on the Screen a different Script is executed: my_RSH_gtk_fileselect_workaround_hit_return.

This Script just waits 0.2 Seconds and sends Command xdotool key Return to the Window Manager. Since the sending of Return is useless while Pressing Strg, Alt or Shift, it is looped until a File is detected, which will only exist, if the 1x1 Pixel Button of the GtkDialog GUI has grabbed xdotool's sending of key Return.

So, the File Selector appears after releasing key Strg etc.pp.

Known issues:

When using this from a GUI Button the Loop will rarely come to an End if the Button is accidentally clicked twice. But just clicked once it works smoothly. Though, don't use it that way.

RSH
Attachments
GtkDialog-FileSelector-WA-0.1.pet
(3.53 KiB) Downloaded 129 times

Post Reply