The time now is Sat 25 May 2013, 01:09
All times are UTC - 4 |
| Author |
Message |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Fri 28 May 2010, 11:32 Post subject:
Simple GUI building with vala and glade Subject description: Using Gtkbuilder in vala: a JWM configuration example |
|
Hi,
Here is an example of a gui build with gtkbuilder.
http://ljfr2.perso.neuf.fr/test/jlexp100609-0.0.0.pet
md5sum: 472979eb1d61fe00ec1bac5d31d1f599 jlexp100609-0.0.0.pet
Take care, this pet will also overwrite your tray file /root/.jwmrc-tray, so if you have any custom feature in it, make a copy, ...
I just followed the example on http://live.gnome.org/Vala/GTKSample, built interface files with glade and included in the vala code some bash functions linked to widgets'signals as in gtkdialog. This is just an experiment but it seems a simple alternative to gtkdialog in case you need some widgets like spinbuttons, combobox, ...
this pet will create a folder /root/jlexp100609 containing program files, try the trayconfig and paramconfig scripts, they are two examples.
It also includes a small utility to parse/read/modify a xml file.
Read the file: /root/jlexp100609/README for more information.
regards,
Last edited by ljfr on Wed 09 Jun 2010, 04:33; edited 1 time in total
|
|
Back to top
|
|
 |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6866 Location: Perth, Western Australia
|
Posted: Fri 28 May 2010, 20:52 Post subject:
|
|
Very interesting!
Would you mind also posting your source?
_________________ http://bkhome.org/blog2/
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Sat 29 May 2010, 02:39 Post subject:
Source files are included |
|
Hi,
Source files are included,
a brief description is made in the README file:
| Quote: | FILE DESCRIPTION
-------------------------------------------------------------------------------
xmltool (source file: xmltool.c):
A small command line program to read and modify node values of an xml file.
It uses libxml, and xpath syntax, for more information see:
http://www.xmlsoft.org/
An introduction on xpaths:
http://www.w3schools.com/XPath/xpath_syntax.asp
It is inspired by the --shell option of the xmllint utility. Alternatively
you could try the command "xmllint --shell" and then navigate your xml file
with xpaths.
http://xmlsoft.org/xmllint.html
You can look at paramconfig and trayconfig to get few examples.
------------------------------------------------------------------------------
uibuilder (source file: uibuilder.vala):
The file uibuilder is a small programm building an interface with gtkbuilder,
it is inspired by this vala example:
http://live.gnome.org/Vala/GTKSample#Loading_User_Interface_from_XML_File
and the way gtkdialog (http://linux.pte.hu/~pipas/gtkdialog) works with
glade files.
to use it, you need:
-an xml user interface file, with a defined window named "window".
-2 bash functions or program, named bash_init and bash_action, available
through the current environement (exported or linked/added in PATH ...).
bash_init is used to get initial value for widgets with types:
Entry, SpinButton, ComboBox, CheckButton
bash_action is made available as a callback method for any signal.
Widgets value for Entry, SpinButton, ComboBox, CheckButton widgets are
exported to environment, you can use then through your script.
------------------------------------------------------------------------------- |
regards,
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Wed 09 Jun 2010, 04:51 Post subject:
New examples and remarks |
|
Hi, I updated my previous examples, You will find some screenshots bellow.
I added a basic support for treeview, filechooser button.
For using treeview inside glade 3, this is a good introduction:
http://tadeboro.blogspot.com/2009/04/creatin-gtktreeview-with-glade-3.html
Once the treeview is built, the liststore can be filled via a bash function.
Regarding size:
-Original glade files are quite big, but they can be stripped -just delete properties you don't need- you may
achieve to reduce the size by ~50%. I kept original glade files in the 'src' folder, and the compile file is used to build the stripped versions in the 'ui' folder.
-A pet without sources would be ~36k, compared to a ~30k jwmconfig2, but there is no need for gtkdialog3 (the binary is included).
You will find a pet including sources in attachment.
What could be easy to add:
-More widgets: Scale buttons, Radio buttons, Icon view, Link button,
Scale buttons ...
-More signal handlers: show_all, hide_all, set_sensitive, ...
NB:
The traycontent gui is buggy: signals are not blocked when a child window is opened, so if you click in the parent window while a child window is open, you could achieve wild action.
 |
| Description |
|

Download |
| Filename |
jlexp100609-0.0.0.pet |
| Filesize |
47.09 KB |
| Downloaded |
445 Time(s) |
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Wed 09 Jun 2010, 07:35 Post subject:
|
|
This looks very promising . Though I have not tested it. I am judging by the pictures. Do you have plans to add the ability to have unlimited trays?
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Thu 10 Jun 2010, 01:34 Post subject:
Multiple trays |
|
Hi,
I have no development plan, though it should not be really difficult to add multiple tray support so I may do it. Meanwhile, the edited tray is the first one inside the /root/.jwmrc-tray file: If you need to change another tray you can change tray position inside this file.
Note that I have just made few examples to test the potential of vala/gtkbuilder as an alternative to gtkdialog - which lacks some features and is not maintained anymore (disappeared from debian/ubuntu repository).
I see some advantages: execution speed, no need for an internal lexer, simple signal connections, smaller binary...
regards,
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Wed 21 Jul 2010, 15:20 Post subject:
multiples trays ... |
|
Hi,
I have added multiple trays support, and put everything in this small gui:
To be considered as experimental.
For the vala part, I made few changes: I added GtkIconView and GtkMessageDialog in the list of widget filled via bash, used var args on callback functions, which would make them work on various signals (?, not sure yet) regardless of signatures...
The gui, including sources, is now in the folder /usr/local/bin/jlexp100721, the menu entry is "JWM conf" under the desktop category.
If you install this pet, all your JWM configuration files would be overwritten, I changed /etc/xdg/templates/_root_.jwmrc
to erase keybindings that are in /root/.jwm/jwmrc-personal already.
see the jlexp100721-0.0.0.pet attached, md5sum:
8376d14bc24c4150f3f48c7f6db37588 jlexp100721-0.0.0.pet
regards,
regards,
Note: to compile it with recent version of vala (at least with 9.2 and 9.3) , and gtk version 2.16.6, you have to change the binding of Gtk Widget is_sensitive in the /usr/share/vala/gtk+-2.0.vapi file to:
| Code: | [CCode (cname = "GTK_WIDGET_IS_SENSITIVE")]
public bool is_sensitive (); |
...just add the first line with the CCode.
| Description |
|

Download |
| Filename |
jlexp100721-0.0.0.pet |
| Filesize |
51.9 KB |
| Downloaded |
414 Time(s) |
|
|
Back to top
|
|
 |
abushcrafter

Joined: 30 Oct 2009 Posts: 1447 Location: England
|
Posted: Mon 16 Aug 2010, 13:50 Post subject:
|
|
Tried to try this on 4.3.2v3 but It needed a newer GTK version. I did tried to compile it but got these errors: | Code: | uibuilder.vala:15.26-15.44: error: The name `is_sensitive' does not exist in the context of `Gtk.Widget'
widget.set_sensitive( !widget.is_sensitive() );
^^^^^^^^^^^^^^^^^^^
uibuilder.vala:231.11-231.61: error: `GLib.Type[]' does not have a `contains' method
if( objects.nth_data(i).get_type() in this.handled_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uibuilder.vala:20.21-20.56: error: Assignment: Cannot convert from `void*' to `UIBuilder?'
unowned UIBuilder builder=object.get_data("uibuilder");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uibuilder.vala:22.33-22.39: error: The name `builder' does not exist in the context of `export_variables'
foreach(string object_name in builder.handled_object_name)
^^^^^^^
uibuilder.vala:79.21-79.56: error: Assignment: Cannot convert from `void*' to `UIBuilder?'
unowned UIBuilder builder=object.get_data("uibuilder");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uibuilder.vala:82.6-82.12: error: The name `builder' does not exist in the context of `refresh_widget'
if(builder==null)
^^^^^^^
uibuilder.vala:85.28-85.34: error: The name `builder' does not exist in the context of `refresh_widget'
if( object.get_type() in builder.handled_type ) {
^^^^^^^
Compilation failed: 7 error(s), 0 warning(s)
|
So I tried on Lupu 1.5. The GUI loaded but No other dialogues where run/shown when I clicked (I did try double clicking.) on a option. I got no errors on the console.
_________________ adobe flash is rubbish!
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
|
|
Back to top
|
|
 |
2byte
Joined: 09 Oct 2006 Posts: 356
|
Posted: Thu 26 Aug 2010, 10:45 Post subject:
|
|
nevermind
_________________
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Mon 30 Aug 2010, 03:52 Post subject:
thanks for feedbacks |
|
Hi,
to abushcrafter:
-regarding your compilation issues on version 4.3, It is because it requires a recent version of vala.
-To access other dialog it is with double-click (or one click to select and enter and space to activate), I just used the default gtkiconview behavior but I will switch to single click, it should be better.
If it doesn't work with double-click, then there is something wrong.
to barryK:
-I will correct the weird /usr/local file tree.
-For other files, you should take at least my:
/root/.jwmrc-tray
/root/.jwm/jwmrc-personal
because when some jwm options are not already defined, it would bug.
Other changes:
-In /etc/xdg/templates/_root_.jwmrc, I erased parameters that are already defined in /root/.jwm/jwmrc-personal, because when for example a key-binding is deleted,
I just want to delete it in /root/.jwm/jwmrc-personal.
-I included themes (/root/.jwm/themes) because I refomat theme preview/snapshots (with the same scale), and I think I cleaned some "corner" color attribute which generated some warnings (and may disturb the apllication since I use jwm internal check).
regards,
|
|
Back to top
|
|
 |
BarryK
Puppy Master

Joined: 09 May 2005 Posts: 6866 Location: Perth, Western Australia
|
Posted: Mon 30 Aug 2010, 20:28 Post subject:
|
|
ljfr,
Thanks for the clarification about those other files in the PET pkg.
_________________ http://bkhome.org/blog2/
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Thu 28 Jul 2011, 02:52 Post subject:
|
|
Is there a way to make the ui able to run functions from a calling bash script? Or is it limited to vala coded functions.
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
ljfr
Joined: 23 Apr 2009 Posts: 176
|
Posted: Thu 25 Aug 2011, 13:02 Post subject:
Calling a bash script |
|
Yes it is possible to call a bash script, I used the function:
| Code: | public void goto_bash(Gtk.Widget object, ...){
export_variables(object);
sync_command("bash -c 'do_action "+object.get_name()+"'");
} |
as a callback on the event to launch a single bash script named "do_action" with the gtk object caller's name as first argument.
Then in the bash function do_action a switch is made on the object's caller name (plus any conditions on others widgets'states that are exported), which get you to the given wanted scripts.
So just a single "entry" function for bash scripts ("do_action") to do more bash and less vala. Source files are in /usr/local/bin/jlexpXXXXXX/src.
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3018 Location: Oregon
|
Posted: Thu 25 Aug 2011, 18:11 Post subject:
|
|
Calling a bash script in gtkdialog, one can use:
<action>exec $shell -c 'bash_script'</action>
I found this in an example a person posted on http://code.google.com/p/gtkdialog/ updates - Last 30 days - Aug 16, 2011 - issue 24.
The complete script is | Code: |
#!/bin/bash
function now () {
date > /tmp/date
}
export -f now
export script='
<vbox>
<entry>
<variable>ENTRY_DATE</variable>
<input>cat /tmp/date</input>
</entry>
<button>
<label>Refresh</label>
<action>exec $SHELL -c 'now'</action>
<action>refresh:ENTRY_DATE</action>
</button>
</vbox>'
gtkdialog3 -p script
exit 0
|
|
|
Back to top
|
|
 |
|
|
|
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 vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|