Simple GUI building with vala and glade

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

Simple GUI building with vala and glade

#1 Post by ljfr »

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, 08:33, edited 1 time in total.

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#2 Post by BarryK »

Very interesting!

Would you mind also posting your source?
[url]https://bkhome.org/news/[/url]

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

Source files are included

#3 Post by ljfr »

Hi,

Source files are included,
a brief description is made in the README file:
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#Lo ... m_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,

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

New examples and remarks

#4 Post by ljfr »

Hi, I updated my previous examples, You will find some screenshots bellow.
Image
Image
Image
Image
Image

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/cr ... ade-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.
Attachments
jlexp100609-0.0.0.pet
(47.09 KiB) Downloaded 824 times

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#5 Post by abushcrafter »

This looks very promising :D. Though I have not tested it. I am judging by the pictures. Do you have plans to add the ability to have unlimited trays?

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

Multiple trays

#6 Post by ljfr »

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,

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

multiples trays ...

#7 Post by ljfr »

Hi,

I have added multiple trays support, and put everything in this small gui:
Image

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: Select all

    [CCode (cname = "GTK_WIDGET_IS_SENSITIVE")]
		public bool is_sensitive ();
...just add the first line with the CCode.
Attachments
jlexp100721-0.0.0.pet
(51.9 KiB) Downloaded 776 times

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#8 Post by abushcrafter »

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: Select all

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.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
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/

2byte
Posts: 353
Joined: Mon 09 Oct 2006, 18:10

#9 Post by 2byte »

nevermind


ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

thanks for feedbacks

#10 Post by ljfr »

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,

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#11 Post by BarryK »

ljfr,
Thanks for the clarification about those other files in the PET pkg.
[url]https://bkhome.org/news/[/url]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#12 Post by technosaurus »

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.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

Calling a bash script

#13 Post by ljfr »

Yes it is possible to call a bash script, I used the function:

Code: Select all

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.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#14 Post by 8-bit »

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: Select all

#!/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

User avatar
way12go
Posts: 66
Joined: Thu 24 Apr 2014, 14:09
Location: Rajahmundry, India.
Contact:

JWM Configuration Manager binary files please

#15 Post by way12go »

JWM Configuration Manager binary files please

Need to compile a deb package
Heaven is positive thinking.

User avatar
way12go
Posts: 66
Joined: Thu 24 Apr 2014, 14:09
Location: Rajahmundry, India.
Contact:

Re: JWM Configuration Manager binary files please

#16 Post by way12go »

way12go wrote:JWM Configuration Manager binary files please

Need to compile a deb package
You can download the .pet file on
http://www.murga-linux.com/puppy/viewtopic.php?t=56153 and then change the extension to .tar.gz. That's all a pet file is. The source files should be in there.
Heaven is positive thinking.

Post Reply