Page 7 of 27

Re: Raio buttons

Posted: Tue 16 Nov 2010, 15:57
by jpeps
jpeps wrote:
vovchik wrote:Dear jpeps,

In my tests, radio buttons in HUG work exactly as advertised. Try this code:

Code: Select all

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("On", 50, 30, my_radio2)
my_radio2 = RADIO("Off", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
DISPLAY
With kind regards,
vovchik
Thanks vovchik,

And for a group? Specifically, I was looking at:

FUNCTION RADIO (STRING text$, int xsize, int ysize, NUMBER group)

(I did something similar using checkbuttons with a reset function)
This seems to work:

Code: Select all

INCLUDE "hug.bac"

win_width = 200
win_height = 100
mainwin = WINDOW("Radio test", win_width, win_height)
my_radio1 = RADIO("One", 50, 30, my_radio3)
my_radio2 = RADIO("Two", 50, 30, my_radio1)
my_radio3 = RADIO("Three", 50, 30, my_radio1)
ATTACH(mainwin, my_radio1, 20, 20)
ATTACH(mainwin, my_radio2, 20, 50)
ATTACH(mainwin, my_radio3, 20, 80)    

DISPLAY 

radio buttons

Posted: Tue 16 Nov 2010, 16:35
by vovchik
Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

With kind regards,
vovchik

Re: radio buttons

Posted: Tue 16 Nov 2010, 17:22
by jpeps
vovchik wrote:Dear jpeps,

I was hoping you would do just that. After posting and seeing your reply, I wrote the EXACT same code.

With kind regards,
vovchik
:D

Here's revised code for MyFavorites loader:
(note: points to my own programs, so edit)

http://jpeters.net/apps/MyPrograms2.txt

Posted: Tue 16 Nov 2010, 19:25
by 2lss
I gave the source code editor on basic-converter.org a shot and I liked it. So I decided to try adding a few features to make it more like an ide (similar to tinyide)

I added the ability to compile the code (Menu > Build > Compile) and the ability to execute the code ( Menu > Build > Execute).

There are a few issues with each though. When "compile" is clicked, it prompts the user to save the file. If the user clicks yes and the file has not been saved before it will bring up the 'save_as' dialog however, it will compile the code before the 'save' or 'cancel' button is clicked giving an error .

Clicking "execute" will launch xterm (if TERM=xterm) and execute the program. I'm not sure how to make this work with rxvt since it does not have a '-hold' option.

I originally wanted to pipe stdout into a text box widget instead of calling xterm but I was unable to get the pipe to work. Maybe someone else could find the problem. (lines 825 - 846)

Posted: Thu 18 Nov 2010, 12:29
by BarryK
Maybe you guys who are BaCon experts can see how this can be done elegantly....

In many shell scripts we have:

. /etc/rc.d/PUPSTATE

Where PUPSTATE is a file, which has something like this in it:

Code: Select all

PUPMODE=12
PDEV1='sr0'
DEV1FS='iso9660'
PUPSFS='sda7,ext3,/w0981011.143/wary_098.sfs'
PUPSAVE='sda7,ext3,/warysave-098.2fs'
PMEDIA='usbcd'
#kernel with libata pata has both sata and pata drives in ATADRIVES...
ATADRIVES='sda '
#these directories are unionfs/aufs layers in /initrd...
SAVE_LAYER='/pup_rw'
PUP_LAYER='/pup_ro2'
#The partition that has the warysave file is mounted here...
PUP_HOME='/mnt/dev_save'
#(in /initrd) ...note, /mnt/home is a link to it.
#this file has extra kernel drivers and firmware...
ZDRV='sda7,ext3,/w0981011.143/zw098114.sfs'
#complete set of modules in the initrd (moved to main f.s.)...
ZDRVINIT='no'
#Partition no. override on boot drive to which session is (or will be) saved...
PSAVEMARK=''
So the problem is how to read in each line in a BaCon program, ignoring comments, and assign those variables so they can be used in the program.

Unlike the INCLUDE operation in BaCon, this has to be a run-time evaluation. I can't quite see how to do it. I suppose an associative array? ...but I would really like to assign each variable independently.

Perhaps there is some obvious way to do it, and I just can't see the obvious.

Posted: Thu 18 Nov 2010, 12:34
by PjotAwake
Hi 2lss,

Thanks for your contributions. In fact, I have plans for this editor - I would like to add the BaCon converter itself, as a whole, to the program, so it's all embedded in one. We would have a fourth incarnation of BaCon but completely graphical based on GTK.

For the conversion progress, this is something I would rewrite using a Progress Bar.

Furthermore I would add a configuration panel where it is possible to fill in which type of output terminal is being used: xterm, rxvt, Terminal, gnome-terminal. Also in which size it has to appear.

The 'hold' of the terminal, you could embed the execution of the resulting program in a script which simply finishes with a 'read' - this will wait for input from the keyboard.

Tabbing should be added as well.

Syntax completion would be nice but I could not get that to work.

Your additions are a valuable step to these ideas, thanks! So, lots to do, wish there was more time! :-)

Regards
Peter

Posted: Thu 18 Nov 2010, 13:00
by PjotAwake
So the problem is how to read in each line in a BaCon program, ignoring comments, and assign those variables so they can be used in the program.

Unlike the INCLUDE operation in BaCon, this has to be a run-time evaluation.
Well that is a difficult thing to do as the program will be compiled - C cannot evaluate strings into actual variable names. An interpreter is needed for that. So you probably end up with a program like the below, which probably can be optimized.

Regards
Peter

Code: Select all

OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle

WHILE NOT(ENDFILE(handle))

    READLN line$ FROM handle

    SPLIT line$ BY "=" TO item$ SIZE dim
    
    IF dim > 0 THEN
        SELECT item$[0]
            CASE "PUPMODE"
                PUPMODE = VAL(item$[1])
            CASE "PDEV1"
                PDEV1$ = item$[1]
            CASE "DEV1FS"
                DEV1FS$ = item$[1]
            CASE "PUPSFS"
                PUPSFS$ = item$[1]
            CASE "PUPSAVE"
                PUPSAVE$ = item$[1]
            CASE "PMEDIA"
                PMEDIA$ = item$[1]
            CASE "ATADRIVES"
                ATADRIVES$ = item$[1]
            CASE "SAVE_LAYER"
                SAVE_LAYER$ = item$[1]
            CASE "PUP_LAYER"
                PUP_LAYER$ = item$[1]
            CASE "PUP_HOME"
                PUO_HOME$ = item$[1]
            CASE "ZDRV"
                ZDRV$ = item$[1]
            CASE "ZDRVINIT"
                ZDRVINIT$ = item$[1]
            CASE "PSAVEMARK"
                PSAVEMARK$ = item$[1]
        END SELECT
    END IF

WEND

CLOSE FILE handle

Posted: Thu 18 Nov 2010, 14:28
by vovchik
Dear Barry,

This isn't elegant or pretty, but it works. If the varnames are known in advance (and they are), this is one easy way of getting the assignments done.

Code: Select all

OPTION BASE 1
myfile$ = "PUPSTATE"
mygrep$=CONCAT$(" | grep -v ", CHR$(34),"#",CHR$(34))
mycmd$ = CONCAT$("cat ", myfile$, mygrep$)
mypupstate$ = CHOP$(EXEC$(mycmd$))
SPLIT mypupstate$ BY NL$ TO mypuplines$ SIZE pupline_entries
FOR i = 1 TO pupline_entries
	valvar$ = ""
	varname$ = ""
	mypuplines$[i] = REPLACE$(mypuplines$[i],"'","") 
	varname$ = LEFT$(mypuplines$[i], INSTR(mypuplines$[i], "=") - 1)
	valvar$ = MID$(mypuplines$[i], INSTR(mypuplines$[i], "=") + 1)
	SELECT varname$
		CASE "PUPMODE"
			PUPMODE$ = valvar$
		CASE "PDEV1"
			PDEV1$ = valvar$
		CASE "DEV1FS"
			DEV1FS$ = valvar$
		CASE "PUPSFS"
			PUPSFS$ = valvar$
		CASE "PUPSAVE"
			PUPSAVE$ = valvar$
		CASE "PMEDIA"
			PMEDIA$ = valvar$
		CASE "ATADRIVES"
			ATADRIVES$ = valvar$
		CASE "SAVE_LAYER"
			SAVE_LAYER$ = valvar$
		CASE "PUP_LAYER"
			PUP_LAYER$ = valvar$
		CASE "PUP_HOME"
			PUP_HOME$ = valvar$
		CASE "ZDRV"
			ZDRV$ = valvar$
		CASE "ZDRVINIT"
			ZDRVINIT$ = valvar$
		CASE "PSAVEMARK"
			PSAVEMARK$ = valvar$
	END SELECT
NEXT i
With kind regards,
vovchik

Posted: Thu 18 Nov 2010, 14:57
by BarryK
I actually did do this in another compiled language ...I don't recall which one, it might have been Genie. On that occasion I think that I used an associative array.

I just tried it in BaCon:

Code: Select all

GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 IF NOT(ENDFILE(handle1)) THEN
  first$=LEFT$(line$,1)
  IF NOT(EQUAL(first$,"#")) THEN
   SPLIT line$ BY "=" TO array$ SIZE dimension
   val$=CHOP$(array$[1],"' ")
   pupstate$(array$[0])=val$
  ENDIF
 ENDIF
WEND
CLOSE FILE handle1

REM test result:
REM retrieves all elements of assoc array:
LOOKUP pupstate$ TO c$ SIZE d
FOR x=0 TO d-1
 PRINT c$[x]
NEXT
REM print one variable:
PRINT pupstate$("PUPSFS")
...yep, that works. It just means that the variable PUPSFS has to be referrred to in the program as pupstate$("PUPSFS") ...I can live with that.

Much better

Posted: Thu 18 Nov 2010, 15:22
by vovchik
Dear Barry,

Nicer solution, to be sure....

With kind regards,
vovchik

Posted: Thu 18 Nov 2010, 15:35
by BarryK
Thanks to Peter who has implemented CONTINUE, I have tidied up the program. It now checks for blank lines and indented '#' comment lines (doesn't test for comments on the end of lines, but that could be done):

Code: Select all

GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 chopped$=CHOP$(line$)
 IF EQUAL(chopped$,"") THEN CONTINUE
 first$=LEFT$(chopped$,1)
 IF EQUAL(first$,"#") THEN CONTINUE
 SPLIT chopped$ BY "=" TO array$ SIZE dimension
 val$=CHOP$(array$[1],"' ")
 pupstate$(array$[0])=val$
WEND
CLOSE FILE handle1

Can't we just let BASIC die already.......

Posted: Thu 18 Nov 2010, 23:03
by Ted Dog
:twisted: Can't we just let BASIC die already.......

Slightly kidding..

I know it works with tcc according to the website, would be nice to chain them together. so we would not need dev.sfs

Another version of assoc arrays

Posted: Thu 18 Nov 2010, 23:19
by mechanic
BarryK wrote:I actually did do this in another compiled language ...I don't recall which one, it might have been Genie. On that occasion I think that I used an associative array.

I just tried it in BaCon:

Code: Select all

GLOBAL pupstate$ ASSOC STRING

REM read /etc/rc.d/PUPSTATE and evaluate vars...
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS handle1
WHILE NOT(ENDFILE(handle1)) DO
 READLN line$ FROM handle1
 IF NOT(ENDFILE(handle1)) THEN
  first$=LEFT$(line$,1)
  IF NOT(EQUAL(first$,"#")) THEN
   SPLIT line$ BY "=" TO array$ SIZE dimension
   val$=CHOP$(array$[1],"' ")
   pupstate$(array$[0])=val$
  ENDIF
 ENDIF
WEND
CLOSE FILE handle1

REM test result:
REM retrieves all elements of assoc array:
LOOKUP pupstate$ TO c$ SIZE d
FOR x=0 TO d-1
 PRINT c$[x]
NEXT
REM print one variable:
PRINT pupstate$("PUPSFS")
...yep, that works. It just means that the variable PUPSFS has to be referrred to in the program as pupstate$("PUPSFS") ...I can live with that.
Hi Barry, here is an alternate version that I played with when testing the assoc arrays. Yours may be faster, I haven't checked.

Code: Select all


DECLARE prop$ ASSOC STRING

infile$ = "/etc/rc.d/PUPSTATE"
OPEN infile$ FOR READING AS fh
WHILE NOT(ENDFILE(fh)) DO
    READLN txt$ FROM fh
    txt$ = CHOP$(txt$)
	IF EQUAL(LEFT$(txt$, 1), "#") THEN CONTINUE
	l$ = LEFT$(txt$,INSTR(txt$,"=")-1)
	r$ = RIGHT$(txt$,LEN(txt$)-INSTR(txt$,"="))
	prop$(l$) = r$ 
WEND

PRINT prop$("DEV1FS")
PRINT prop$("ZDRV")
PRINT prop$("PUPSAVE")

PS. Thanks for Puppy Linux!

Posted: Fri 19 Nov 2010, 01:45
by seaside
BarryK wrote:Thanks to Peter who has implemented CONTINUE, I have tidied up the program. It now checks for blank lines and indented '#' comment lines (doesn't test for comments on the end of lines, but that could be done):
Barry,

This user added contribution function on the website-

Code: Select all

ExtractStr(STRING Main$,STRING Delim$)
might work to return everything to the left of #

Code: Select all

val$=ExtractStr(array$[1],"#")
Regards,
s

(I'm afraid there's probably nothing quite as simple and eloquent as

Code: Select all

 .  VARFILE
) :D

Posted: Fri 19 Nov 2010, 05:09
by 2lss
PjotAwake wrote:Hi 2lss,

Thanks for your contributions. In fact, I have plans for this editor - I would like to add the BaCon converter itself, as a whole, to the program, so it's all embedded in one. We would have a fourth incarnation of BaCon but completely graphical based on GTK.

For the conversion progress, this is something I would rewrite using a Progress Bar.

Furthermore I would add a configuration panel where it is possible to fill in which type of output terminal is being used: xterm, rxvt, Terminal, gnome-terminal. Also in which size it has to appear.

The 'hold' of the terminal, you could embed the execution of the resulting program in a script which simply finishes with a 'read' - this will wait for input from the keyboard.

Tabbing should be added as well.

Syntax completion would be nice but I could not get that to work.

Your additions are a valuable step to these ideas, thanks! So, lots to do, wish there was more time! :-)

Regards
Peter
Glad I could offer some help. I'll keep plugging away at it when I get time.

As far as the terminal "hold" I had a similar thought, but figured the extra script would confuse things. Unless the editor creates/downloads the script when run (similar to the syntax file).....

What do you think about a FIND/HIGHLIGHT option? I found some example C code that might work.

Posted: Fri 19 Nov 2010, 08:56
by BarryK
2lss wrote:
PjotAwake wrote:Hi 2lss,

Thanks for your contributions. In fact, I have plans for this editor - I would like to add the BaCon converter itself, as a whole, to the program, so it's all embedded in one. We would have a fourth incarnation of BaCon but completely graphical based on GTK.

For the conversion progress, this is something I would rewrite using a Progress Bar.

Furthermore I would add a configuration panel where it is possible to fill in which type of output terminal is being used: xterm, rxvt, Terminal, gnome-terminal. Also in which size it has to appear.

The 'hold' of the terminal, you could embed the execution of the resulting program in a script which simply finishes with a 'read' - this will wait for input from the keyboard.

Tabbing should be added as well.

Syntax completion would be nice but I could not get that to work.

Your additions are a valuable step to these ideas, thanks! So, lots to do, wish there was more time! :-)

Regards
Peter
Glad I could offer some help. I'll keep plugging away at it when I get time.

As far as the terminal "hold" I had a similar thought, but figured the extra script would confuse things. Unless the editor creates/downloads the script when run (similar to the syntax file).....

What do you think about a FIND/HIGHLIGHT option? I found some example C code that might work.
Puppy already has a script for xterm. All Woof-built puppies have /usr/bin/xterm which is a script, unless any particular developer has replaced it.

Wary, Quirky, and many older versions of Puppy have it, in fact if my memory serves me right, even Puppy 4.3.1 has it.

Here is the script:

Code: Select all

#!/bin/sh
#rxvt does not understand the '-hold' option.

if [ "`echo -n ${*} | grep '\-hold '`" != "" ];then
 EXECCOMMAND="`echo -n ${*} | grep -o ' \-e .*' | sed -e 's/ \-e //'`"
 if [ "$EXECCOMMAND" != "" ];then
  echo '#!/bin/sh' > /tmp/xterm_simulate_hold.sh
  echo "$EXECCOMMAND"  >> /tmp/xterm_simulate_hold.sh
  echo 'echo' >> /tmp/xterm_simulate_hold.sh
  echo 'echo -n "FINISHED. PRESS ENTER KEY TO CLOSE THIS WINDOW: "' >> /tmp/xterm_simulate_hold.sh
  echo 'read simuldone' >> /tmp/xterm_simulate_hold.sh
  chmod +x /tmp/xterm_simulate_hold.sh
  exec rxvt -e /tmp/xterm_simulate_hold.sh
 fi
fi

exec rxvt "${@}"
...it tests for '-hold' on the commandline.
[/code]

Posted: Fri 19 Nov 2010, 10:41
by vovchik
Dear Barry and Doyle,

Slightly more terse....

Code: Select all

DECLARE prop$ ASSOC STRING

infile$ = "PUPSTATE"
OPEN infile$ FOR READING AS fh
WHILE NOT(ENDFILE(fh)) DO
	READLN txt$ FROM fh
	txt$ = CHOP$(txt$)
	IF INSTR(txt$, "#") EQ 1 THEN CONTINUE
	l$ = LEFT$(txt$,INSTR(txt$, "=") - 1)
	prop$(l$) = CHOP$(MID$(txt$, INSTR(txt$, "=") + 1), "'")
WEND
PRINT prop$("DEV1FS")
PRINT prop$("ZDRV")
PRINT prop$("PUPSAVE")
With kind regards,
vovchik

Posted: Fri 19 Nov 2010, 11:29
by jpeps
Version of previously posted apps loader using arrays:

http://jpeters.net/apps/MyPrograms.bac.txt

picscale v. 0.1a - image converter/rescaler in BaCon

Posted: Sun 21 Nov 2010, 17:40
by vovchik
Dear puppians,

Here is revised picture rescaler/converter written in BaCon that makes use of gdk_pixbuf to work its magic. It is pretty small (38k compiled). Since it is a command-line prog, you can use it in bash scripts for the batch processing of image directories etc.

The help screen looks like this:

Code: Select all

picscale image resizer/converter - v.0.1a by vovchik, Puppy Linux Forum, Nov 2010

Input formats supported: pnm, pbm, pgm, ppm, tga, xpm, tiff, pcx, gif,
xbm, wmf, icns, bmp, png, jpg and ico.

Output formats supported: png, jpg, bmp, tiff and ico.

Input parameters: oldfilename newfilename height width quality/compression/depth

Example: picscale old.png new.png 128 128 9

Quality/compression/depth settings:

        bmp (N/A):               0 - 100
        jpeg (quality):          0 - 100
        png (compression):       0 - 9
        tiff (compression type): 1 - 8
        ico (depth):             16, 24 or 32

Check out BaCon at www.basic-converter.org
If you have any suggestions or code mods, please tell me or post them here. The source is in the archive and a working binary in the pet file (installs in /usr/local/bin).

With kind regards,
vovchik

Posted: Sun 21 Nov 2010, 21:04
by big_bass
Hey vovchik

fast and small
what more can you want and
compiled it in bacon 8)


I can see many good apps to follow from you

thanks for posting the app and the source

Joe