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 Fri 19 Sep 2014, 07:57
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
C programming with gtk using glade and glade-2
Post new topic   Reply to topic View previous topic :: View next topic
Page 3 of 3 [44 Posts]   Goto page: Previous 1, 2, 3
Author Message
disciple

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

PostPosted: Tue 21 Feb 2012, 23:01    Post subject:  

Quote:
as what just happened with CUPS attests

What's that? I obviously missed it.

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


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 21 Feb 2012, 23:37    Post subject:  

Basically, they are planning to drop a bunch of linux stuff and focus on osx.
Fork is already planned, but I hope they revert most of the C++ code introduced in 1.4 .... It's silly to have cupsd requiring libstdc++ (i hacked it out once, but cups is a difficult beast that I try to avoid)

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

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

PostPosted: Wed 22 Feb 2012, 05:32    Post subject:  

Thanks, now that I've read up on what's happening, it could be a fantastic development, if it spawns the right type of fork. But I guess CUPS is such a monster it could need someone BIG to sponsor it... here's hoping.
_________________
DEATH TO SPREADSHEETS
- - -
Classic Puppy quotes
- - -
Beware the demented serfers!
Back to top
View user's profile Send private message 
disciple

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

PostPosted: Sun 26 Feb 2012, 04:49    Post subject:  

amigo wrote:
"I consider C++ disgusting"
+1
Thanks very much for sharing your educated opinion about gtk1 and other commnets above Smile

Speaking of C++, it seems to me that both QT and wxWidgets apps tend to become unbuildable very quickly once they become unmaintained. Have you guys noticed this? Is it something to do with being written in C++, or is it because g++ or the toolkits or something just have poor backward compatibility?

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

Joined: 02 Apr 2007
Posts: 2247

PostPosted: Sun 26 Feb 2012, 08:32    Post subject:  

Yes it is because of frequent changes in the C++ standard and/or lack of binary-compatibility between different versions of the C++ libs.

If you have a program written in C and compile it against a certain version glibc it will usually run on a machine with an older version of glibc within some limits or on a machine with a newer glibc. With programs that use libstdc++ this is rarely true. At compile-time, the differences in the code show up. Since I don't like or read much C++, these kinds of erros get on my nerves -I try to avoid stuff that uses C++ whenever possible.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Sun 26 Feb 2012, 16:03    Post subject:  

If you look at the release notes for gcc (where libstdc++ originates), it becomes apparent. In nearly every release, there is some deprecation(s) and new compliant behavior that breaks code.

I'm not a C++ fan either ... Note its absence in the title
Glib has object code if that is all you want, but I have found uclibc++ without rtti or exceptions (otherwise you need parts of libstdc++) to be a good alternative for building C++ code to be much smaller.

Edit: my biggest complaint about gtk (all versions) is addressed in this excellent video on immediate mode gui
http://mollyrocket.com/861

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


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 29 Feb 2012, 02:38    Post subject:  

I want to allow the gui interface to act as a server by only doing a printf to stdout for callbacks (callbacks are functions that get called when the user does something, or something occurs) and monitoring stdin for action events from the client.

This will allow a single generic interface to manipulate internal widgets from any programming language that supports streams (I can't think of any that don't)

The problem is that in C everything reads in as a long string, but I wanted a snippet that could read from stdin (user input or pipe or redirection) and parse the string into the same format as main's argc and argv so that I could use some of the same functions to operate on them.

Here is a snippet of what I came up with so far (note that multiple separators will cause the next arg to get skipped ... todo - until then only use 1 space, tab or newline)
Code:
#include <string.h>
#include <stdio.h>
#define write1(s) write(1, s, strlen(s))

int main(int argc, char *argv[]){
char s[255],  av[255][255];
unsigned char i=0, pos=0, ac=0;

//open a file ./apipe and store its file descriptor in variabla apipe
//use mkfifo /tmp/apipe to create it ... or you can use stdin
//FILE * apipe = fopen("/tmp/apipe","r");;
fgets(s,255,stdin);

while (i<strlen(s)) {
   switch ( s[i] ) {
   case ' ':
   case '\t' :
   case '\n' :
   av[ac][pos] = '\0';
      ac++;
      pos = 0;
   break;
   default :
      av[ac][pos] = s[i];
      pos++;
   break;
   }
   i++;
}
//printf("%d, %s\n",ac, av[ac-1]);
//printf("%d, %s\n",argc, argv[argc-1]);
}

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


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Wed 29 Feb 2012, 10:21    Post subject:  

Dear technosaurus,

Have you thought about using Peter van Eerten's gtk-server? It supports any programing language that can write and read fifo - and a slew of ther interfaces, including TCP. It also compiles to a gtk1 version. All gtk widgets are available. You just have to know how to call them. The URL is here: http://www.gtk-server.org/.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Wed 29 Feb 2012, 11:35    Post subject:  

I have and I even ported some of the ksh and bash srcipt to work with busybox ash and hush, but you must know a lot about gtk in order to program with it. You may have noticed that I like to simplify things to the point where they are usable by the masses. The other side to what I am trying to do is abstract the basic widgets in such a way that I can use multiple backends (gtk1,2,3 and libagar are planned so far)

BTW agar is written in C, cross-platform and has a permissive bsd license (which works well for me since I do a lot of static multicall binaries and I am licensing all of my work as permissively as possible)

Edit: updated snippet for parsing args from stdin
Code:
#include <stdio.h>

void argsfromstdin(void){   /* TODO accept a function pointer to run ac, av */
char s[255],  av[255][255];
unsigned char i=0, pos=0, ac=0;
enum quotes_t{QUOTED=0,UNQUOTED}quotes=UNQUOTED;

//open a file ./apipe and store its file descriptor in variable apipe
//use mkfifo /tmp/apipe to create it ... or you can use stdin
//FILE * apipe = fopen("/tmp/apipe","r");;
fgets(s,255,stdin);

while (i<strlen(s)) {
   /* '!'=33, 'ÿ'=-1, '¡'=-95 outside of these are non-printables */
   if ( quotes==UNQUOTED && ((s[i] < 33) && (s[i] > -1) || (s[i] < -95))){
      av[ac][pos] = '\0';
      if (av[ac][0] != '\0')   ac++;
      pos = 0;
   }else{
      if (s[i]=='"'){  /* support quoted strings */
         if (pos==0){
            quotes=QUOTED;
         }else{      /* support \" within strings */
            if (s[i-1]=='\\'){
               av[ac][pos-1] = '"';
            }else{   /* end of quoted string */
               quotes=UNQUOTED;
            }
         }
      }else{         /* printable ascii characters */
         av[ac][pos] = s[i];
         pos++;
      }
   }
   i++;
}
/* TODO accept a function pointer to run ac, av */
#ifdef DEBUG
#include <string.h>
#define write1(s) write(1, s, strlen(s))
while (ac-->0) {write1(av[ac]);write1("\n");}
#endif

}

int main(int argc, char *argv[]){
argsfromstdin();
}

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

Joined: 06 Jun 2008
Posts: 32

PostPosted: Thu 26 Apr 2012, 08:05    Post subject:  

I can certainly understand glade users wanting to use xml files rather than compiling C code. XML allows us to separate the program's behavior from the program's appearance. It allows the coding team to work concurrently with the GUI team. It also makes visual changes a breeze.

I played around with bacon a bit, but found that I just hated the old basic syntax. But even old basic was better than trying to write GTK in proper C, with its horrid pointer syntax and casts. (for example, *(char***) yuck!)

So I reworked one of the bacon example programs (glade_demo.bac) into C, without the miles of wrapping code that bacon includes. Instead I abused the preprocessor and made an easy-to-read almost python-like syntax that anyone can live with. The bacon/tcc compiled executable for this program was 40K. The plain tcc version executable was 4K. (tcc also compiled it in less than a second)

Though if you're so concerned with speed and size of GTK, why not just use John Murga's murgaLua? FLTK is super fast and Lua's syntax and extensibility is first rate.
glade-demo.zip
Description  glade_demo.bac from bacon website, written in a simplified C
zip

 Download 
Filename  glade-demo.zip 
Filesize  5.21 KB 
Downloaded  249 Time(s) 
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Thu 26 Apr 2012, 22:18    Post subject:  

mjaksen wrote:
I can certainly understand glade users wanting to use xml files rather than compiling C code. XML allows us to separate the program's behavior from the program's appearance. It allows the coding team to work concurrently with the GUI team. It also makes visual changes a breeze.

so does gui-gtk.c but then you can also have gui-agar.c, gui-qt.cpp and gui-fltk.cpp... a proper make file will only rebuild the changed code, so recompiling is quick (one file is recompiled - the slow part, and then all the objects are linked - fast in comparison) one side effect is that the young programmers that typically get stuck with the gui parts learn "actual programming" through exposure - they actually can see the callback functions etc... and may realize - "hey all of these on_button<*>_clicked are basically doing the same thing - I could just use a generic on_button_clicked callback"
Quote:
I played around with bacon a bit, but found that I just hated the old basic syntax. But even old basic was better than trying to write GTK in proper C, with its horrid pointer syntax and casts. (for example, *(char***) yuck!)
.
So I reworked one of the bacon example programs (glade_demo.bac) into C, without the miles of wrapping code that bacon includes. Instead I abused the preprocessor and made an easy-to-read almost python-like syntax that anyone can live with. The bacon/tcc compiled executable for this program was 40K. The plain tcc version executable was 4K. (tcc also compiled it in less than a second)


Yes, pretty much every C programmer has the same complaint and the determined ones create their own form of low-level object system out of macros and/or a small library of functions

Quote:
Though if you're so concerned with speed and size of GTK, why not just use John Murga's murgaLua? FLTK is super fast and Lua's syntax and extensibility is first rate.

from my experience, fltk is not very good at building dynamic guis (kind of important for a gui toolkit, but maybe I just overlooked something) - it is left to the programmer to deal with low level stuff like resizing on a resize event, so it appears to be targeted at embedded environments where this is uncommon - except that fltk and libstdc++ would be much larger than glib+gtk1 or libagar (if you want to use xml, check out goingnuts' backport of gtkdialog to gtk1 - its extremely small and fast and should work in any scripting language, I use a multicall bash script - there is also a C example)

My personal reason for wanting as much as possible in C (besides it being a good learning tool), was that I wanted to build a large project of multicall binaries for the desktop. With gtk1, tinyx11 and uclibc, we can get all the default desktop apps into a single static binary in ~2-3mb (maybe less with some code refactoring and a single shell script for support) Compilers do not know what is in your XML, so any decent optimizations will lose code that is only used in the gui - so clicking a button may do nothing (unless you go through a lot of hoops). Compilers also can't automatically refactor common layout code used in every single XML file, nor have I seen any tool that does so.... I guess you could use the same UI file for all of them and only load a particular set of objects ... but then it would read unnecessary XML (unless there is some way to #include a file in XML?) The underpowered PCs that I have (I have several DECTops with the geode gx2 w/ 128mb ram) take a while to do anything, so even parsing large amounts of XML makes them sluggish. To me, its just simpler if it is all in C... its hard(er) for my 5 and 6 yr old to mess up a file system with a single statically compiled binary, and easier for me to restore if they do. (I also use it as my fall-back in case some part of my shared lib tool chain breaks while I am updating libraries)[/quote]

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

Joined: 02 Apr 2007
Posts: 2247

PostPosted: Fri 27 Apr 2012, 13:46    Post subject:  

technosaurus, I also have a couple of DECTOP units -one of them is still virgin with the winCE system. The other one has Slackware installed. I adapted the original DOS system used for 'unlocking' the BIOS, so that you can restore the original locked system or unlock it.
In case you are interested, you can find my decTOP stuff here:
http://distro.ibiblio.org/amigolinux/download/AmigoProjects/decTOP/

I still have in mind to try installing my KISS linux on one of the decTOP boxes -I chose the i586 kernel and toolchain architecture just to be able to use the system with geode CPU, but have never checked to see if it was working...
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Mon 16 Jul 2012, 12:32    Post subject:  

Mark Tyler (the mt in mtpaint) forked gtk1 (as mtk) to use Xft and some other bugfixes/improvements here:
https://sites.google.com/site/mtpaint2/
however, the only version I can find is the latest version (mtk-0.5), which for whatever reason, he relicensed gpl3 (not lgpl3) but maybe someone has v0.3/4 around somewhere otherwise its not quite as useful.

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

Joined: 02 Apr 2007
Posts: 2247

PostPosted: Mon 16 Jul 2012, 13:00    Post subject:  

Nice find there -maybe. Perhaps wjaguar would know or could find out where older copies of the sources are. Barring that, scanning the ChangeLog or diffs against original gtk1 sources might point to some good stuff...
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 3 of 3 [44 Posts]   Goto page: Previous 1, 2, 3
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.1098s ][ Queries: 13 (0.0130s) ][ GZIP on ]