BaCon Bits

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

Extending "Hello BaCon"

#21 Post by GatorDog »

To add a couple of elements to the example.

- STOCK(.....) creates a button using the built in 'icon and text' buttons. ex Quit, Close, etc.
List of built in buttons Built in buttons

- Create a SUB routine()

- Execute the SUB when the button is clicked

Code: Select all

' BaCon / HUG  Hello World
' With SUB routine example

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

' ******************
' SUBS & FUNCTIONS
' ******************
SUB CHANGE_MY_TEXT()
	' TEXT changes the text of a widget/My_label
	TEXT( My_label, "Goodbye BaCon")
END SUB

' ******************
' END SUBS & FUNCTIONS
' ******************

' Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "Hello Title Bar", 250, 100 )

' Create a label with text, 150 x 30
My_label = MARK( "Hello BaCon!", 150, 30 )

' Attach the label to the main window 
' at coordinates 50x 20y from top left corner
ATTACH( Mainwin, My_label, 50, 20 )

' --- BUTTONS ---
My_btn = BUTTON( "Change text", 100, 25)
ATTACH( Mainwin, My_btn, 5, 60 )

' Make an exit button
My_close = STOCK("gtk-close", 100, 25)
ATTACH(Mainwin, My_close, 140, 60)

' --- CALLBACKS ---
CALLBACK( My_btn, CHANGE_MY_TEXT)
CALLBACK( My_close, QUIT)

' Make it so! (A little Star Trek lingo :-)
DISPLAY
rod
Attachments
hello_bacon.png
(25.48 KiB) Downloaded 1132 times

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

#22 Post by sunburnt »

Excellent !!!
Q: Is there a good IDE or editor, I noticed several at BaCon.

Also I saw that a compiled version of BaCon can run the Basic files directly.
This means a Visual Basic type of IDE to make GUIs could be built !!!

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

BaConGUI - IDE

#23 Post by GatorDog »

Q: Is there a good IDE or editor, I noticed several at BaCon.
I think the answer to that is BaconGUI.
- Write/edit/compile/execute etc.
- Keyword highlighting
- etc.

I haven't tried TinyIDE. Looks like a good option if you're working with limited
system resources.

rod

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

#24 Post by sunburnt »

Thanks Rod; I downloaded both, but thought I`d ask.

Terry

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

#25 Post by sunburnt »

Hey Rod; I posted for help getting Puppy to load the devx file, no answers.
I`m wondering what`s in it that`s needed. The dir.: /usr/lib/gcc ?
I noticed that Puppy already has the file: /lib/libgcc_s.so.1
( Maybe it`s not what`s needed at all... )

It appears I have no choice but to try to cobble the compiler together myself.

I downloaded the package for Debian as it has compiled files: bacon and bacongui.
Also the file bacon.bash.
Instead of the library: hug.so it has ".bac" files in: /lib/bacon.

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#26 Post by GatorDog »

sunburnt

afaik, you need the bacon packages and a compiler such as gcc.

I think you'll want the bacon packages that I posted above. They
should have the latest features and updates. Although they're beta
I personally have not had any issues with them.

You can create hug.so from hug.bac. With bacongui it is very easy.
There is a bacon -option to do that but I haven't used it.

I'll attach a compiled bacon 1.0.24beta, which should work on puppy.
You'll probably need gcc available. Then you can roll you own with
bacon bacongui.bac etc.

rod
Attachments
bacon-1.0.24beta.tar.gz
(100.79 KiB) Downloaded 751 times

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

#27 Post by sunburnt »

Thanks Rod; I have the bacon executables: bacon and bacongui in /bin
The gui comes up and I loaded your example, click: tools > execute. Nothing.

As I said, Puppy already has: /lib/libgcc_s.so.1 ... Is this the C compiler?
And then there`s: /usr/lib/gcc/libgcc_s.so ... a link to the library above.

I just got it to convert your example but it errors with:

WARNING: 'cc' not found on this system!
Generated source code cannot be compiled.

Obviously the compiler is missing. Where is it in the SFS file and I can copy it?

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

#28 Post by sunburnt »

Got the devx file to load with the boot manager, use to be it`d load automatically.
So now theres cc but I see no sign of BaCon, good thing I installed it manually.

Your example now runs and compiles from bacongui !!! Thanks again!

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

#29 Post by sunburnt »

Rod; Q: Where can I get a list of the widgets supported by hug and docs on usage?
Of special interest is the TabPanel widget, it`s great at keeping GUI`s small.

Looks like this is a very good setup for Puppy dialogs.
Nice small executables that run much faster than Bash scripts!

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

Bacon & HUG Docs

#30 Post by GatorDog »

Hi Terry,
In Bacongui, click on Help / Documentation. Bacongui keeps a copy of the
bacon doc in /root/.bacon/documen...... It opens up in a browser tab.

I usually keep firefox up with these two urls opened.

Bacon doc http://www.basic-converter.org/documentation.html
HUG doc http://www.basic-converter.org/hugdoc.html

rod

Edit, I do not know what the difference is between cc an gcc, but I've been using gcc.

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

#31 Post by sunburnt »

Thanks again GatorDog; I don`t know why I didn`t find it the first time.
Looking at the docs it looks like it`s much more capable than gtkDialog.
It even has the old Basic drawing commands: circle, square, and pixel.
Can you say... Custom controls? :wink:

I signed up at the BaCon forum, see you there!

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

Hello Bacon (World)

#32 Post by GatorDog »

A project to demo some of the BaCon HUG widgets.
This program demos the COMBO widget ie. drop down box.

This is the naming convention that I've started using.
It should prevent collisions with items used in the compiler.
  • ALL_UPPER_CASE ( All uppercase for SUB's and FUNCTIONs )
    Unnnn_nnnn_ ( Uppercase first letter, end with "_" for widget handles )
    Unnnn_nnnn ( Variable names )
    Unnnn_nnnn$ ( String variables )
NEW -
The GLOBAL statement.
Although not strictly necessary, declaring variables becomes
more useful the bigger a program gets. The "TYPE NUMBER" declares
these variables to be numbers. We can have as many GLOBAL statements
as we want.

COMBO
The COMBO widget is initialized like this:
Widget_handle_ = COMBO( "first item", size-x, size-y )

Items are added to the COMBO widget with the TEXT method:
TEXT( Widget_handle_, "2nd item" )
TEXT( Widget_handle_, "3rd item" )
TEXT( Widget_handle_, "4th item" )

Then the COMBO is added to the widow in the same way the buttons
were in the previous example.
ATTACH(Mainwin_, Widget_handle_, x-coord, y-coord )

rod

Code: Select all

' BaCon / HUG  Hello BaCon (World)
' Add a Combo widget (drop down)

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

GLOBAL Mainwin_, Menu_label_, Drink_label_, Drink_combo_, My_close_ TYPE int

' ******************
' SUBS & FUNCTIONS
' ******************

' ------------------
SUB MAKE_GUI
' ------------------
	Mainwin_ = WINDOW( "Hello BaCon", 400, 400 )

	Menu_label_ = MARK( "Please choose items from Menu", 200, 28 )
	ATTACH( Mainwin_, Menu_label_, 100, 0 )

	Drink_label_ = MARK("Select Drink", 100, 28)
	ATTACH( Mainwin_, Drink_label_, 10, 25)

	'--- Add a COMBO widget with 4 items
	Drink_combo_ = COMBO("Coffee", 100, 28 )
	TEXT( Drink_combo_, "Tea")
	TEXT( Drink_combo_, "Milk")
	TEXT( Drink_combo_, "O,J.")
	ATTACH( Mainwin_, Drink_combo_, 10, 50 )


	'--- BUTTONS ---
	Close_btn_ = STOCK("gtk-close", 100, 28)
	ATTACH(Mainwin_, Close_btn_, 290, 365)

	'--- CALLBACKS ---
	CALLBACK(Close_btn_, QUIT)
END SUB

' ******************
' END SUBS & FUNCTIONS
' ******************


' ******************
' MAIN PROGRAM
' ******************

MAKE_GUI

DISPLAY
Attachments
hello_bacon.png
(9.68 KiB) Downloaded 1396 times
hello_bacon_combo.tar.gz
source file
(641 Bytes) Downloaded 596 times

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

#33 Post by sunburnt »

Hey GatorDog; Thanks for the help at the BaCon forum, mucho appreciato!

Thoughts; I dislike the underscore "_", after years of Visual Basic I like the period.

And the Visual Basic convention for control naming, "winMain" or "btnOk".
The lower case first part ids the control type, the next part ids it`s purpose.
This is very sensible and easy to understand.

I liked your idea of using the underscore at the end of handles, it`s like a little handle.
So the handle for the button control "btnOk" would be "btnOk_".

Qs ( of course ).
Can a variable list be used for the combo items? Example:

Code: Select all

   TEXT( Drink_combo_, "$cboMonths_list") 
So there would be only one TEXT statement for the combo box.
I`d hope there`s a method of doing this some way.

Keep the tutorials coming GatorDog, I think Barry`s behind you.

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#34 Post by GatorDog »

Can a variable list be used for the combo items? Example:
Code:
TEXT( Drink_combo_, "$cboMonths_list")

So there would be only one TEXT statement for the combo box.
I`d hope there`s a method of doing this some way.
In pFontSelect (earlier post) I populated the list of fonts with a FOR/NEXT loop.
So if the list of items are already in Some_array$[] of length Number_of_items, then
you can add these items to the list or combo with something like this:
(assuming you have OPTION BASE 1 set up, you can start count with 1)

Code: Select all

FOR Count = 1 to Number_of_items
	TEXT( Drink_combo_, Some_array$[Count] )
NEXT
If you don't have an array$[] yet, but have the items in a string, say seperated by ":",
ex Drink$ = "Coffee:Tea:Milk:Water:O.J."
Then use the SPLIT command to create an array, then populate the list/combo.

Code: Select all

SPLIT Drink$ BY ":" TO Drink_array$ SIZE Drink_Count
FOR Count = 1 to Drink_count
	TEXT( Drink_combo_, Drink_array$[Count] )
NEXT

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

Hello Bacon (World)

#35 Post by GatorDog »

NEW -

FRAME widget
The FRAME widget lets you visually group items together.
Here we'll use it to group the radio buttons. First
give the FRAME a Handle_ and size. Optionally give the
frame a title with the TEXT command. Then attach it to
our main window.



RADIO buttons widget
The RADIO buttons are usually used when you need the
user to select one of several options. The group name
assigns the radio button to a specific group of buttons.
See [html=http://www.basic-converter.org/hugdoc.html]HUG[/html] doc for further information about group name.
Handle_1_ = RADIO( "First item", x-size, y-size, group_name )
Handle_2_ = RADIO( "Second item", x-size, y-size, group_name )
Handle_3_ = RADIO( "Third item", x-size, y-size, group_name )


SET method
Use the SET method to "set" the default to the third radio button.
SET( Handle_3_, TRUE )

TRUE and FALSE are reserved keywords.
Basically FALSE is defined as "0" zero, and TRUE anything other than
zero, but you'll probably find that TRUE is "1".

Here is the code to add the FRAME and RADIO buttons. The download has
the complete program so far.

rod

Code: Select all

	'--- Add a FRAME for slice size
	Slice_frame_ = FRAME( 265, 50 )
	TEXT( Slice_frame_, " Slice My Bacon: " )
	ATTACH( Mainwin_, Slice_frame_, 120, 32 )

	'--- Add RADIO buttons for slice size selection
	Slice_size_1_ = RADIO( "Thin"  , 70, 28, Slice_size_1_ )
	Slice_size_2_ = RADIO( "Medium", 70, 28, Slice_size_1_ )
	Slice_size_3_ = RADIO( "Thick" , 70, 28, Slice_size_1_ )
	ATTACH( Mainwin_, Slice_size_1_, 130, 50 )
	ATTACH( Mainwin_, Slice_size_2_, 220, 50 )
	ATTACH( Mainwin_, Slice_size_3_, 310, 50 )
	SET( Slice_size_3_, TRUE )

Attachments
hello_bacon.png
(11.66 KiB) Downloaded 1043 times
hello_bacon-frame.tar.gz
source
(788 Bytes) Downloaded 587 times

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

#36 Post by sunburnt »

Thanks GatorDog; Would you prefer that I ask Qs in another thread or maybe at the BaCon forum?

Q; You ATTACH the radio buttons to MainWin, not the frame.
So I assume the frame is just a visual widget and not a widget container?

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#37 Post by GatorDog »

Q; You ATTACH the radio buttons to MainWin, not the frame.
So I assume the frame is just a visual widget and not a widget container?
I just tried a quick test. It does not seem to be a container. But if push comes to
shove, it might be best to get it straight from Peter :)

rod

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

#38 Post by sunburnt »

I tested it using the frame`s handle and it doesn`t show the widget.
Changing the X, Y position I placed the radio button half over the frame edge.
That settles it, the frame is not a widget container, it`s just a visual widget.

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

#39 Post by sunburnt »

I`m working with a combo and I wondered, how to get the item selected?
Need to do this both by making a combo selection and also by a button.

Need to modify my HUG library so the combo will use an array.

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

#40 Post by GatorDog »

I`m working with a combo and I wondered, how to get the item selected?
Need to do this both by making a combo selection and also by a button.
If you mean you want to get the currently selected COMBO item, do that with GRAB$.

Code: Select all

Picked_item$ = GRAB$( Combo_widget_ )
If you mean that you want to set the default value, use the SET method
SET( Combo_widget_ , 3) . To set it with a button, do a callback to a
function/sub that then does a SET. :wink:

From HUG doc:
SET(widget, value)
"Depending on the widget, sets a value into the widget. The current behavior is shown in the table below."
Combo - Select entry in combo

rod

Post Reply