BaCon - Bash-based Basic-to-C converter/compiler

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#451 Post by L18L »

e_mattis wrote:Thanks sunburnt,

i'll look a little more and see about the GTK import. I think i'm going to like the idea about the combo boxes better though.

Maybe the best way to say what i am looking for is that I want it to open the full display width and height. fullscreen is the ideal, but full display would work. where would i find the dimension- which file?

thanks!

E
I have found my screen size 1920x180 in /var/log/Xorg.0.log
my console wrote: # grep ' HDisplay:' /var/log/Xorg.0.log
[ 33.159] (II) CHROME(0): HDisplay: 1920
# grep ' VDisplay:' /var/log/Xorg.0.log
[ 33.159] (II) CHROME(0): VDisplay: 1080
#

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#452 Post by sunburnt »

Property commands for width and height from a popup menu I wrote:

Code: Select all

PROPERTY(win_, "width-request", winW)
PROPERTY(win_, "height-request", winH)
Some of us like it use "win_, btn_, lst3_, file_" for object variables.
The underline shows that the variable is a handle for the object type.
It helps a lot to clearly see a variable`s purpose when looking at the code.

L18L shows a good way to get the screen resolution.
This is the command way to get it:

Code: Select all

RES=`xrandr | grep '*' | awk '{print $1}'
I find BaCon to be very useful, many cudos to Peter for it`s creation and maintaining.
Being as BaCon uses C, and HUG uses GTK+ it should work on most Linux distros.
So apps. you write are more portable compared to GtkDialog which only Puppy uses
GtkDialog does have more controls ( menu bar I think...) and more properties also.

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#453 Post by e_mattis »

Thanks guys!

I seem to be having trouble declaring win_, winW, and winH. I've tried 'DECLARE win_, winW, winH' and 'GLOBAL winW, winH TYPE int' but keep getting errors after compile @ run. . .
GLib-GObject-critical**:g_object_set:assertion ....
with no declaration, it tell me the win_, winW, winH are not declared.

I'm probably jumping the gun and need to read more before trying this but I've just got excited about the possibilities...sorry :D

Just want you guys to know I appreciate your patience and assistance - it is good to have people who know to confer with. Thanks so much!

Thanks!

E

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#454 Post by sunburnt »

I should show full code examples... I apologize.

Code: Select all

win_ = WINDOW("My App.", 300, 200)

OR:
OPEN File$ FOR READING AS file_
You don`t need to declare control object`s ID variables.!

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#455 Post by e_mattis »

yea, lot different than what i'm used to. Gonna have to re-learn a lot.

@sunburnt
to clarify - when setting 'win_=WINDOW("my win", 300,200) - you set the dimensions of the window there, so the max winW would be 300, not the max width of the viewable screen. Am I correct in that assumption?

When I enter the 'RES = 'xrandr | grep '*' | awk '[print $1]' it gives me an error of "character constant too long for its type [enabled by default]". I am thinking this is due to asking for an int rather than a long int. correct?

thanks!

E

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#456 Post by sunburnt »

Like this example the exact size is set in the control`s ( or widget`s ) statement.

Code: Select all

win_ = WINDOW("My App.", 300, 200) 
btnExit_ = BUTTON("Exit", 60, 25) : ATTACH(win_, btnExit_, 10, 10) : CALLBACK(btnExit_, EXIT)
This places the button on the window at 10 x 10 and it calls a SUB named EXIT.

I didn`t explain again, sorry. If you notice the command used grep, so it`s a Linux shell command.
Here`s the command called from BaCon, CHOP$ removes the shell`s LineFeed so Res$ has just text.:

Code: Select all

cmd$ = CONCAT$("xrandr | grep '*' | awk '{print $1}'")
Res$ = CHOP$(EXEC$(cmd$))
You can also read or write a file in one shell command too:

Code: Select all

File$ = EXEC$(CONCAT$("cat FileToRead"))

SYSTEM "echo Text >  FileToWrite"
SYSTEM CONCAT$("echo ", Text$, " > ", FileToWrite$)
The top-bottom example writes "Text" to the file FileToWrite.
The bottom one uses variables for the text and the file.
Notice the spaces in the " literal " parts to separate the command parts.

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#457 Post by e_mattis »

Thaks sunburnt,

I'll play around with it a while and see what I figure out. Bad part is that it makes sense to me, but getting it to work when i write it....lol

thanks !

E

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#458 Post by e_mattis »

Hey All,

I'm working with combo boxes in bacon/HUG. From what I can tell, this is the syntax to set up the box:

com_btn=COMBO("File",100,25)
ATTACH(mainwin,com_btn,1,1)
TEXT(com_btn,"Backup")
TEXT(com_btn,"Restore")
TEXT(com_btn,"Exit")

In order to make the program exit when 'exit' is chosen, i tried this:

CALLBACK(com_btn,"Exit",QUIT)

That did not work. :x So my question is, once a selection is chosen, how do you initiate an action for (or how do you associate an action with) that selection? :?

Also, I am wondering if there is a means of changing the text color on-screen? I tried the COLOR FG TO WHITE but it had no effect. The text as I have it atm is:

label_title=MARK("test line",80,20)
ATTACH(mainwin,label_title,20,20)

Also tried PROPERTY(label_title,"color","white") to no avail. :(

Observation: There isn't really an in-depth 'how-to' for Bacon that I can find. :cry:

Any help is very much appreciated!

Thanks!

E
.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#459 Post by L18L »

e_mattis wrote:... i tried this:

CALLBACK(com_btn,"Exit",QUIT)

That did not work. ...
With me it worked this way:
Compiler emits messages!

Cause:
too many arguments to function 'CALLBACK'
file:///usr/share/doc/BaCon/hugdoc.html wrote:CALLBACK

CALLBACK(widget, function)

Type: directive

Defines a self-defined <function> where HUG should jump to when an event for <widget> occurs.
Hope that helps :)

-------
edited

or this:

Code: Select all

INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT

SUB myaction
 SELECT GET(com_btn)
  CASE 0
   PRINT "File chosen"
  CASE 1
   PRINT "Backup chosen"
  CASE 2
   PRINT "Restore chosen"
  CASE 3
   QUIT
  DEFAULT
   PRINT "Value not found"
 END SELECT
END SUB

mainwin=WINDOW("combo example", 250, 100)
com_btn=COMBO("File", 100, 25)
ATTACH(mainwin, com_btn, 1, 1)
TEXT(com_btn, "Backup")
TEXT(com_btn, "Restore")
TEXT(com_btn, "Exit") 

CALLBACK(com_btn, myaction)

DISPLAY
---
edited:

this works without TIMEOUT
Last edited by L18L on Sat 23 Feb 2013, 18:46, edited 1 time in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#460 Post by sunburnt »

e_mattis; The Bacon ( GTK+ ) COMBO box doesn`t use CALLBACK, you must use the TIMEOUT.
Paste, save, and compile this:

Code: Select all

INCLUDE "/root/0_BaCon/BaCon/hug.bac",INIT,DISPLAY,WINDOW,COMBO,MARK,ATTACH,TIMEOUT,SET,GET,TEXT,GRAB$
INIT

SUB Set_Choice
	SET(cboTest_, GET(cboTest_))
	TEXT(lblTest_, GRAB$(cboTest_))
	PRINT GRAB$(cboTest_)
END SUB

win_ = WINDOW(" Combo Test", 100, 100)

lblTest_ = MARK("Test", 80, 25)
ATTACH(win_, lblTest_, 10, 10)

cboTest_ = COMBO("", 80, 25)
ATTACH(win_, cboTest_, 10, 50)

FOR i = 1 TO 5
	TEXT(cboTest_, CONCAT$("Item #", STR$(i)))
NEXT

SET(cboTest_, 1)

TIMEOUT(1000, Set_Choice)

DISPLAY
A _ "handle" on the end of the widget variables makes them easy to see.
.

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#461 Post by e_mattis »

Thanks guys,

Tried both ways. The method L18L gave is a little more familiar to me. I also was able to get the method sunburnt gave me to work, but it read a little confusing to me. Thank both of you for helping me through it. :D

One thing I found is that the 'callback' must come before the 'display'. that was one thing I had wrong in my original. :oops: (ima still learning :) )

Now to get the subs for the actions working properly. I'll probably be back soon for more assistance!

Thanks

E

.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#462 Post by sunburnt »

Okay... Apparently GTK+ reworked the ComboBox.

If you look way back in this thread you`ll see how it use to only work with TIMEOUT.
It`s good to see changes like this, I always thought TIMEOUT was a stupid way to do it.

I just made a download: mirror, distro., and arch. selector GUI with ComboBoxes.

# The Bacon site needs to point out these changes to it`s patrons.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#463 Post by L18L »

e_mattis wrote:... One thing I found is that the 'callback' must come before the 'display'. that was one thing I had wrong in my original. :oops: (ima still learning :) )
Nothing after DISPLAY is executed.
...after DISPLAY don't forget a new line

We all are learning...
... and continue :)

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#464 Post by vovchik »

Dear L18L,

If you are using HUG - and you are - and you need the screen size in pixels, there is no need to call xrandr or another external utility. HUG has this command:

Code: Select all

SCREENSIZE(dimension)
Type: function
Gets the current screensize in pixels. If <dimension> is 0 then the horizontal size is retrieved, and if <dimension> is 1 the vertical size.
Example:

Code: Select all

x = SCREENSIZE(0)
y = SCREENSIZE(1)
If you use it and have a list of keywords after the INCLUDE "hug.bac" business, don't forget to include SCREESIZE in that list.

With kind regards,
vovchik

PS. COMBO works fine with CALLBACK on my machine.
PPS. I also have the situation with a newline being required at the end of the code - but not on all machines![/code]

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#465 Post by e_mattis »

Hey guys,

Thanks for the input Vov - I was needing that :D

I have another dilema now :( I need to understand how to launch and run another 'script' from within a 'script'.

as example,:

Code: Select all

SUB com_btn2
   SELECT GET(com_btn)
      CASE 0
         PRINT "File Chosen"
      CASE 1
         HIDE (mainwin)
         SYSTEM "exec /opt/myProg"
      CASE 2
         PRINT "Restore Chosen"
etc, etc....

END SUB
I have looked over the docs for Bacon and Hug, this is the closet thing I've found. I am familiar with the 'RUN "program_name" ' call in other basics, but see no such function here.

Any help is very appreciated!

Thanks!

E


[update]...

ok, so I found that adding the '&' would cause the script to launch. :oops:
SYSTEM "exec /opt/myProgram &"
works. Now, is there a means to keep the window close (X) button from showing on the window?

And i'm still trying to figure out how to change font color.

Thanks!



.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#466 Post by L18L »

Dear vovchik,

thanks for your SCREENSIZE hint.
vovchik wrote:...If you use it and have a list of keywords after the INCLUDE "hug.bac" business, don't forget to include SCREESIZE in that list. ...
...and now it is first time that I use hug.bac and a list :roll:
# head -1 m_INCLUDE.bac
INCLUDE "/usr/share/BaCon/hug.bac", INIT, GET, SCREENSIZE, WINDOW, COMBO, CALLBACK, DISPLAY, QUIT, ATTACH, TEXT
#
# time bacon m_INCLUDE.bac
Converting 'm_INCLUDE.bac'... done.
Compiling 'm_INCLUDE.bac'... done.
Program 'm_INCLUDE' ready.

real 0m56.783s
user 0m20.282s
sys 0m0.617s
#
# ls -l m_INCLUDE
-rwxr-xr-x 1 root root 166924 Feb 25 10:27 m_INCLUDE
#
before, always using hug_imports (without a list) only:
# head -1 m_import.bac
INCLUDE "/usr/share/BaCon/hug_imports.bac"
#
# time bacon m_import.bac
Converting 'm_import.bac'... done.
Compiling 'm_import.bac'... done.
Program 'm_import' ready.

real 0m4.561s
user 0m1.757s
sys 0m0.190s
# # ls -l m_import
-rwxr-xr-x 1 root root 61006 Feb 25 10:29 m_import
#
Thus I do not understand why anybody should use hug.bac list
I must be missing something :roll:

With kind regards

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#467 Post by L18L »

e_mattis wrote:... Now, is there a means to keep the window close (X) button from showing on the window?..
and all the others like _
try
x = SCREENSIZE(0) / 3
mainwin = WINDOW("combo example", x, 100)
SETPROPERTY(mainwin, "decorated", FALSE)

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#468 Post by e_mattis »

AH! Thanks L18L! I hadn't thought about properties. :oops:

Have not found all the settings to go with properties, but I am familiar with decorated - I should have realized :D

You guys are the best! Thanks so much!

E

User avatar
e_mattis
Posts: 114
Joined: Fri 21 Dec 2012, 02:24
Location: Williamston, SC
Contact:

#469 Post by e_mattis »

Well, i'm back again. :shock:

I'm now trying to learn how to red/write record files using BaCon. I understand the simplest form:

Record <var>
LOCAL <member1> TYPE <type>
LOCAL <member2> TYPE <type>
END RECORD

I have been successful writing a file using this approach. :) I have tried to adapt it to be able to use for multiple records, but have not been able to figure it out. :( Below is the current state of this attempt:

Code: Select all

REM read/write data to file

REM GLOBAL Date$,Rnds$,TF$ TYPE str
GLOBAL Date$ ARRAY 3
GLOBAL Rnds$ ARRAY 3
GLOBAL TF$ ARRAY 3
GLOBAL Rec$ ARRAY 3
LOCAL TF

INCLUDE "/usr/share/BaCon/hug.bac"

FOR a = 1 TO 2


	Date$(a)= "Monday, Feb. 25.2013"

	Rnds$(a)= STR$((0+a)*100)

        TF=a

	TF$(a)= STR$(TF)
	

	RECORD Rec$(a)
		
		PUTLINE Date$(a) TO Rec$
		
		PUTLINE Rnds$(a) TO Rec$ 
		
		PUTLINE TF$(a) TO Rec$
	
	END RECORD

NEXT A
	
 
OPEN "test.dab" FOR WRITING AS handle
	
	FOR b = 1 TO 2
		
		WRITELN Rec$(b) TO handle
	
	NEXT b
 
CLOSE FILE handle



END
However, this returns the following errors at compile:

Code: Select all

# bacon recordtest.bac

Converting 'recordtest.bac'. . . done

Compiling 'recordtest.bac . . . Compiler emits messages!



Problem:
	
	file 'recordtest.bac line 16: END RECORD



Cause:
	
	paramter names (without types) in function decloration [enabled by default]
I'm kinda at a loss :oops: In the program I am working on, I will have 3 variables (date/rnds/tf) with several 'records'. In the other basic languages I am familiar with, this would be done in an csv array using the first element as the record number. So I am wondering if using the CONCAT$ would be a better alternative here, such as

Code: Select all

FOR a = 1 TO 2
...
   Rec$(a) = CONCAT$(Date$(a),":",Rnds$(a),":",TF$(a))
NEXT a

...

FOR b = 1 TO 2
   WRITELN Rec$(b) TO handle
NEXT b
I tried this method but also had an error at compile (not the same error I do not think). So I turn to the master(s) for assistance! Any help is appreciated!

Thanks

E

.

User avatar
Mobeus
Posts: 94
Joined: Thu 26 Aug 2010, 15:49

#470 Post by Mobeus »

E

This got me too when I started learning BaCon. BaCon does not support arrays of records, but it does support records of arrays.

Code: Select all

TRAP LOCAL
CATCH GOTO CATCHERROR

' One record of dynamic arrays
RECORD Rec
    LOCAL Date$ ARRAY 3
    LOCAL Rnds$ ARRAY 3
    LOCAL TF$ ARRAY 3
END RECORD


FOR a = 1 TO 2
	TF=a
	Rec.Date$[a] = "Monday, Feb. 25.2013"
	Rec.Rnds$[a] = STR$((0+a)*100)
	Rec.TF$[a] = STR$(TF)
NEXT

OPEN "test.dab" FOR WRITING AS handle

FOR b = 1 TO 2
	WRITELN CONCAT$(Rec.Date$[b], ":", Rec.Rnds$[b], ":", Rec.TF$[b]) TO handle
NEXT b

CLOSE FILE handle

REDIM Rec.Date$ TO 6
REDIM Rec.Rnds$ TO 6
REDIM Rec.TF$ TO 6

FOR a = 3 TO 5
	TF=a
	Rec.Date$[a] = "Tuesday, Feb. 26.2013"
	Rec.Rnds$[a] = STR$((0+a)*100)
	Rec.TF$[a] = STR$(TF)
NEXT

OPEN "test.dab" FOR APPENDING AS handle

FOR b = 3 TO 5
	WRITELN CONCAT$(Rec.Date$[b], ":", Rec.Rnds$[b], ":", Rec.TF$[b]) TO handle
NEXT b

CLOSE FILE handle

END

LABEL CATCHERROR
PRINT ERR$(ERROR)
END
Regards,
Mobeus

PS. It really doesn't make any sense to me to use records like this. It's less typing to use the dynamic arrays by themselves without wrapping them in a record. :?
/root for the home team

Post Reply