Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 01 Sep 2014, 09:50
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog1-1.3
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 14 [207 Posts]   Goto page: Previous 1, 2, 3, 4, ..., 12, 13, 14 Next
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Tue 07 Feb 2012, 17:54    Post subject:  

Note: some of these may be off by a line or 2 because I added #include "config.h" to all of the .c files, so I didn't need all of the -D... stuff to compile

Edit -- approximate eqivalent to locate (for the purposes of gtkdlg)
Code:
#!/bin/sh
find /usr $HOME /opt -iname ${1##*/}


I did a bit of comparison shopping using thunor's patches from here:
http://code.google.com/p/gtkdialog/source/list?num=320&start=320

In no particular order, except that I took note of them...

to help with using shells other than bash, he replaced
Code:
source %s
with
Code:
. %s

http://code.google.com/p/gtkdialog/source/detail?r=4#
I grepped them to be at
~246 of actions.c
~330 of widgets.c

this commit fixes the slow reading of vars (using -p / --program) compared to stdin (-s)
http://code.google.com/p/gtkdialog/source/detail?r=308#
I think this corresponds to ~152 of main.c

Quote:
Fixed the longstanding issue with expand and fill being FALSE when packing
widgets into boxes. A message said that the original author couldn't get it to
work, but I can't see anything wrong with it.

many of these are ifdef gtk2, but Thunor's patch seems gtk1 doable:
http://code.google.com/p/gtkdialog/source/detail?r=296#

btw more gtk1/2 apps to scrape:
minimum profit 3
gftp <2.19
mtpaint
wireshark?
jpilot?
freeciv?
classicladder?
kmd (komodo manchester debugger)
http://www.web100.org/download/
http://mahjong.julianbradfield.org/Source/
http://ftp.eenet.ee/gentoo-portage/media-sound/aylet/files/aylet-0.5-gtk.patch

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Wed 08 Feb 2012, 13:00    Post subject:  

amigo wrote:
Keep up the good work. At some point I might work on patching the full sources so that config-time option for gtk1 can be used.

Text and tree code is the hardest to convert. For tips and example code, look at older source which allowed using either gtk1 or gtk1. rox-1.2.2 is one example. I'll have to dig to make more suggestions. even if you never get every possible widget working, having a few of the basics working will be great in order to use the same scripts with either toolkit.

Thank you amigo - your offer is much appreciated - and your input on the tree/text widgets have convinced me that at least the tree should be left out. Concerning using the gtk-pixbuffer: I have no clue how to do it. For me the main thing missing right now is to be able to use more image-types - not just xpm - so if that can be done easily (with or without) gtk-pixbuffer...?

Technosaurous: Thanks for the pointers - I will add those!

There are other low hanging fruits: word-wrap to the edit-widget + default value and the geometry switch also seems easy done.

I have not been making a lot of shell gtk scripts until now - and begin to understand your blended feelings about the "xml-syntax". Maybe a more stringent structure is needed. Haven't thought this totally through but it seems that some of the tags means different things depending on which widget they are serving. I have done a lot of html and do not find that hard to write/read and maybe a clean up of the tags are needed? Maybe only "clean" tags (<button> and no <button ok>, <input> and no <input file>)? Some of the tags express both what I would call state and value (ex: <default>)...

At least a mapping of the present hierarchy of widgets, childs, childs child, attributes and actions should be done.

As for other programs to "scrape" the Xdialog-2.3.1 is quite relevant.
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Wed 08 Feb 2012, 14:23    Post subject:  

would it be easier to develop something from scratch?
I used code from glade to help implement this:

Code:
#include <stdio.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

/* TODO use these for switch case(s) in main loop */
#define FIVE_CHARS(x1,x2,x3,x4,x5)   (((((((((x5)<<8)|(x4))<<8)|(x3))<<8)|(x2))<<8)|(x1))

void on_button_clicked(GtkButton *button, char *user_data){printf("action=\"%s\"\n",user_data);}
void on_checkbutton_toggled(GtkToggleButton *togglebutton, char *user_data){
   if (GTK_TOGGLE_BUTTON(togglebutton)->active){
      printf("%s=\"on\"\n",user_data);
   }else{
      printf("%s=\"off\"\n",user_data);
   }
}

int main(int argc, char *argv[]){
GtkWidget *widgets[99],packers[9];
char *button_action[0];
int widget=1, packer=0 ,i=1;

gtk_set_locale ();
gtk_init (&argc, &argv);

/* TODO shift this into main loop and add title support */
widgets[0] = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (widgets[0]), "window", widgets[0]);
gtk_window_set_title (GTK_WINDOW (widgets[0]), "title");

/* TODO shift this into main loop and add hbox support - need packer stack */

/* TODO shift stuff into this loop and add widgets */
while (i<argc){ /* loop through args to make widgets - buttons with actions */
switch ( FIVE_CHARS(argv[i][0],argv[i][1],argv[i][2],argv[i][3],argv[i][4]) ) {
case FIVE_CHARS('-','v','b','o','x')   :
   widgets[widget] = gtk_vbox_new (FALSE, 0);
   gtk_widget_ref (widgets[widget]);
   gtk_object_set_data_full(GTK_OBJECT(widgets[0]), "box", widgets[widget],
      (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (widgets[widget]);
   gtk_container_add(GTK_CONTAINER (widgets[0]), widgets[widget]);
   i++;widget++;
break;

case FIVE_CHARS('-','h','b','o','x')   :
   widgets[widget] = gtk_hbox_new (FALSE, 0);
   gtk_widget_ref (widgets[widget]);
   gtk_object_set_data_full(GTK_OBJECT(widgets[0]), "box", widgets[widget],
      (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (widgets[widget]);
   gtk_container_add(GTK_CONTAINER (widgets[0]), widgets[widget]);
   i++;widget++;
break;

case FIVE_CHARS('-','b','u','t','t')   :
   i++;
/* TODO make this a switch case here for widgets */
   widgets[widget] = gtk_button_new_with_label(argv[i]);
   gtk_widget_ref (widgets[widget]);
/* TODO? is widget 0 always correct? */
   gtk_object_set_data_full(GTK_OBJECT (widgets[0]), argv[i], widgets[widget],(GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show(widgets[widget]);
/* TODO replace hardcoded packer with a "stack" */
   gtk_box_pack_start(GTK_BOX (widgets[1]), widgets[widget], FALSE, FALSE, 0);
/* TODO replace button_action with generic char array */
   i++;
   button_action[widget] = argv[i];
   if (button_action[widget] != NULL){
      gtk_signal_connect(GTK_OBJECT (widgets[widget]), "clicked",
         GTK_SIGNAL_FUNC(on_button_clicked),button_action[widget]);
      i++;
      }
   widget++;
break;

case FIVE_CHARS('-','c','h','e','c')   :
   i++;
   widgets[widget] = gtk_check_button_new_with_label (argv[i]);
   gtk_widget_ref (widgets[widget]);
   gtk_object_set_data_full (GTK_OBJECT (widgets[0]), argv[i], widgets[widget],
      (GtkDestroyNotify) gtk_widget_unref);
   gtk_widget_show (widgets[widget]);
   gtk_box_pack_start (GTK_BOX (widgets[1]), widgets[widget], FALSE, FALSE, 0);
   i++;
   gtk_signal_connect (GTK_OBJECT (widgets[widget]), "toggled",
      GTK_SIGNAL_FUNC (on_checkbutton_toggled), argv[i]);
   i++;widget++;
break;

default   :
   printf("usage:\n%s -{v,h}box [-button label action] [-checkbox label variable]\n",argv[0]);
   goto END;
   break;
}
}

gtk_signal_connect(GTK_OBJECT (widgets[0]), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit),NULL);
gtk_widget_show(widgets[0]);
gtk_main();
END:
return 0;
}

_________________
Web Programming - Pet Packaging 100 & 101

Last edited by technosaurus on Wed 08 Feb 2012, 22:10; edited 4 times in total
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2238

PostPosted: Wed 08 Feb 2012, 15:29    Post subject:  

For an example of stacking widgets, see greq:
http://distro.ibiblio.org/pub/linux/distributions/amigolinux/download/DeskTop/MsgDialog/greq-0.9.4/

It uses a little known feature of bash -PIPE_STATUS to return the results. It also lets you add a checkbutton after any normal widget.

As for re-inventing the wheel, it might be best to just hack one of the existing programs, but that's just me thinking. I'd really like to see a gtk1 version of gtkdialog which implements as many of the features of the gtk2 version as possible, using the same syntax. The dual-toolkit compatibility is the magic of it.

I think most of problem you are having with the includes must come from not having configuration done properly at the top-level of the sources. Most gtk1/gtk2 capable programs manage to live in the same files without having to do major re-writes -just some -maybe lots, of ifdefs.

I wish I could be more helpful but my hands are tied right now with other things.

I have built lots of small 'programs' using scriptable widgets made from Xdialog, greq, gtk-shell and the other things found here:
http://distro.ibiblio.org/pub/linux/distributions/amigolinux/download/DeskTop/MsgDialog/greq-0.9.4/

I like the ability to create more complex UI's that is possible with gtkdialog, but do not like the startup latency of any gtk2 apps. The libxml overhead is probably livable...

gdk-pixbuf should load any of the common types of images/icons -png-support would be the best choice if only one is to be supported. rox has good example of gdk-pixbuf support -if you look through my rox-1.2.2.x sources you'll find a patch where I made it use png toolbar icons instead of xpm's. I still think it might be a good idea to run the whole idea by thunor as he may be able to get some things going which are harder for you -maybe the whole enchilada...
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Fri 10 Feb 2012, 16:51    Post subject:  

technosaurus & amigo: Thanks for input! Might be difficult to make it gtk2 compatible as this include hacking the parser as far as I can see (to accept the newer script syntax). To start from scratch is tempting when one view the simple structure of the possible coding...but may be too big a project for now...
Spend some time in hacking the edit and fileselect to play well with a menu-driven small text-editor but hit a problem with interference with the event-triggers trying to implement a "save as..." function...
I miss the ability to assign values to internal variables from script, run an external function (script) to change/add values...or just an invisible widget or two that act as the normal widgets...
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Fri 10 Feb 2012, 17:27    Post subject:  

I am working on "sdialog" ... just to learn C really ... I have it set up to use simple templates for each widget. I did study the api enough to use an array of widgets so that they remain available for modification (it would be smaller/simpler to use a single widget pointer to temporarily store non-container type widgets, but then we couldn't reference them for change) , but correct me if this is wrong. It may be possible to emulate zenity/yad in this manner (syntactically, not necessarily graphically), but I was thinking more along the line of gtkdialog's ability to manipulate the interface.

I was considering using a pipe based interface such that we could pipe the output out to a fifo that could be read by a while-read-case loop that can output to another fifo that is used for interacting (via input from the fifo)



I know this seems ridiculous to write yet another dialog program, but none of them seem to be simple _and_ versatile.
Code:
 
mkfifo /tmp/useractions
mkfifo /tmp/scriptactions

sdialog -args... </tmp/scriptactions >/tmp/useractions &

while read LINE; do
case "$LINE" in
...
esac
done </tmp/useractions >/tmp/scriptactions &

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Sat 11 Feb 2012, 08:59    Post subject:  

The different action possibilities for the widget are a nice feature but we might have to modify/adjust them. The present problem with making a simple text editor for example seems to be that the <action>fileselect>/action> spawns the filedialog but does not wait for it to complete before running next action. The present code is below and I have tried to implement a wait for child process but without succes. Any hints are welcome:
Code:
if (strncasecmp(str, "fileselect:", 11) == 0) {
   action_fileselect(button, &((char *) str)[11]);
   //GN how to wait here for this to close before running further actions?
   return;
   }
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Sat 11 Feb 2012, 12:54    Post subject:  

did you try something like
while ( ! fd ) usleep (1000);

I haven't messed much with fselect yet, but it must change some other values too, because the user may choose not to select a file and it would freeze... perhaps its return value

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Sat 11 Feb 2012, 13:10    Post subject:  

Thanks - yes I did try that. After some more hours I think I got the answer: It might not be possible... The actions are fired by the
Code:
gtk_signal_connect(GTK_OBJECT(Widget), "clicked", GTK_SIGNAL_FUNC (button_pressed), (gpointer) act);

where act is the command and this is initially set to the button-actions...
Therefore it seems impossible to put execution on wait in any of the loops before or after the fileselect call. sleep just stops the execution at the specific point in the loop.

I guess that the signals for the other actions (after a button press) are just sitting there waiting to be fired (or already are starting execution) and the only thing one put to sleep is the actual fileselect call.

What was needed was a fileselect-call and after that an update-call (from the same button press) - but if you try to sleep and wait for the fileselect the dialog box never shows up and program "hangs". Crying or Very sad
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Sat 11 Feb 2012, 14:40    Post subject:  

the tutorial talks about timeouts and idle functions, which seem like they could be used for a hack, but I haven't played with them yet.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Mon 13 Feb 2012, 15:57    Post subject:  

Edit 200212: Uploaded new snapshot. Most warnings gone, deactivated tree. A lot of edits in sources...
Now an editor can be made, example in source. Modified afishe2000´s pmenu to test tables/buttons/actions ect. also attached in examples.
Now with build in images for the stock buttons to ease use.
Maybe a small comment on the fileselect action: Every call to fileselect widget causes the main loop to continue after gtk_signal_connect is run in the fileselect window. The ideal solution would be a capture of all actions meant to run after fileselect and then run them when file select done. To overcome some of this I hard coded capture of 1 instance of action save and 1 instance of action refresh. Also implemented an internal variable named OUTFILE that will hold last selected file and the value is exported as OUTFILE=$OUTFILE - so it can be used in the script globally (view some usage in the edit_test example).
Would have liked to include notebook but I just cant understand the parser system.
Below image of the modified pmenu running...
snap0004.png
 Description   
 Filesize   59.71 KB
 Viewed   579 Time(s)

snap0004.png

Back to top
View user's profile Send private message Visit poster's website 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Thu 23 Feb 2012, 15:44    Post subject:  

Fixed list widget so now should be working as intended.
Word-wrap now default for text. gvim widget compiles...have not testet as I do not have gvim.
Added gtkrc-file support.
Examples of pmenu, bootmanager, wideowizard and wakepup in examples.
Found that scripts for gtkdialog sometimes use the "export -f" leaving ash-people in the dark...

To convert the export -f the below is quite simple to do:
The bash version:
Code:
#!/bin/bash

my_func () { echo $1; }
export -f my_func

export MAIN_DIALOG='
<vbox>
 <frame List>
  <list>
   <variable>LIST</variable>
   <input>ls</input>
   <action>my_func "${LIST}"</action>
  </list>
 </frame>
</vbox>
'
.././gtkdlg1 --program=MAIN_DIALOG

...and the ash-version (updated according to Technosaurous post below):
Code:
#!/bin/ash
echo '
my_func () { echo $1; }
#export -f my_func
' > /tmp/ashfunc

export MAIN_DIALOG='
<vbox>
 <frame List>
  <list>
   <variable>LIST</variable>
   <input>ls</input>
   <action>my_func "${LIST}"</action>
  </list>
 </frame>
</vbox>
'
.././gtkdlg1 --program=MAIN_DIALOG -i  /tmp/ashfunc

...the last could be the default method.

Last edited by goingnuts on Fri 24 Feb 2012, 02:21; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4348

PostPosted: Thu 23 Feb 2012, 16:03    Post subject:  

yeah, I had a similar workaround, but don't remember what script it is in. It went something like this though

export Myfunction='..... \
.....'

then use eval $Myfunction

btw, the whole premise of my bashbox stuff was to make this easier - you can call a function by
Code:
bashbox <function>
... or just
Code:
function
if there is a symlink to bashbox

that was before I discovered the -i argument (to include files)
just put all of your functions in a function file and use
Code:
. functionfile
and
Code:
gtkdlg1 -i functionfile ...
(no need to generate it on the fly if that is working)
(I swore I saw that in the gtkdlg1 sources but maybe I am misremembering ... that was the source vs. 'dot' patch I mentioned right?)
source_gtklauncher.patch.gz
Description  I guess I missed one
gz

 Download 
Filename  source_gtklauncher.patch.gz 
Filesize  272 Bytes 
Downloaded  379 Time(s) 

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6430
Location: Auckland, New Zealand

PostPosted: Fri 24 Feb 2012, 02:03    Post subject:  

Guys, this is fantastic!
If you got this up to gtkdialog4 compatibility then a gtk1-only distro would be a really good proposition again.

_________________
DEATH TO SPREADSHEETS
- - -
Classic Puppy quotes
- - -
Beware the demented serfers!
Back to top
View user's profile Send private message 
goingnuts

Joined: 07 Dec 2008
Posts: 780

PostPosted: Fri 24 Feb 2012, 02:30    Post subject:  

technosaurus: Thanks - the "-i" method is really sweet. Updated example above accordingly.
disciple: Guess that gtkdialog4 compatibility would be to hard/much work. If gtkdlg1 can run most scripts by (gentle) editing the script-syntax of scripts meant for younger gtkdialog versions - I am satisfied. Seems that the missing notebook-widget and the ability to use other image formates that xpm is the big missing things for now...
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 2 of 14 [207 Posts]   Goto page: Previous 1, 2, 3, 4, ..., 12, 13, 14 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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
[ Time: 0.2369s ][ Queries: 13 (0.1188s) ][ GZIP on ]