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 18 Apr 2014, 01:48
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
BaCon Bits
Post new topic   Reply to topic View previous topic :: View next topic
Page 3 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, 4, 5, ..., 10, 11, 12 Next
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Mon 01 Aug 2011, 14:11    Post subject:  

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!
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 08 Aug 2011, 03:45    Post subject: Hello Bacon (World)
Subject description: Using a COMBO widget
 

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:
' 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
hello_bacon.png
 Description   
 Filesize   9.68 KB
 Viewed   935 Time(s)

hello_bacon.png

hello_bacon_combo.tar.gz
Description  source file
gz

 Download 
Filename  hello_bacon_combo.tar.gz 
Filesize  641 Bytes 
Downloaded  309 Time(s) 
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Mon 08 Aug 2011, 14:39    Post subject:  

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:
   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.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 08 Aug 2011, 15:11    Post subject:  

Quote:
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:
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:
SPLIT Drink$ BY ":" TO Drink_array$ SIZE Drink_Count
FOR Count = 1 to Drink_count
   TEXT( Drink_combo_, Drink_array$[Count] )
NEXT
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 08 Aug 2011, 15:19    Post subject: Hello Bacon (World)
Subject description: FRAME & RADIO Buttons
 

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:

   '--- 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 )

hello_bacon.png
 Description   
 Filesize   11.66 KB
 Viewed   814 Time(s)

hello_bacon.png

hello_bacon-frame.tar.gz
Description  source
gz

 Download 
Filename  hello_bacon-frame.tar.gz 
Filesize  788 Bytes 
Downloaded  302 Time(s) 
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Mon 08 Aug 2011, 16:31    Post subject:  

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?
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Mon 08 Aug 2011, 16:56    Post subject:  

Quote:
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 Smile

rod
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Mon 08 Aug 2011, 19:46    Post subject:  

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.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Mon 08 Aug 2011, 22:34    Post subject:  

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.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Tue 09 Aug 2011, 02:18    Post subject:  

Quote:
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:
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:
Quote:
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
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Tue 09 Aug 2011, 07:09    Post subject:  

So then I assume the combo will use the callback event?
It`s the only way I can think of to know when a selection is made.
The button callback event can use the GRAB method of course.

I think I`m going to make a complete set of widget test files.
Then it`ll be easy to try out all the different HUG possibilities.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Tue 09 Aug 2011, 18:15    Post subject: Hello Bacon (World)
Subject description: CHECK box, LIST, SPINner
 

For both of you who are following along, I hope you're
trying out these examples. Make changes, move things around,
add to, etc.

A "CONST" (constant) is a variable that is not going to change value
during the course of the program run. I want a carriage return
ie. NewLine in the text so that the text for the CHECKbox
isn't stretched out. We'll use the CONCAT$ command to
concatinate (string together) three string$. "NL$" is
a reserved word for the "New Line" character. CONST doesn't
really buy us much in a program of this size. But in larger
programs it'll help us keep track of variable names we're using
and save memory space. (This is my opinion/thought on CONST).
Since the CONST declares a variable of fixed length, it is static.
The program sets it up and leaves it alone. A variable length
variable can be dynamic, changing length, memory location and
how much memory it occupies. That means the program has to spend
some amount of resources keeping track of it, moving it around,
making sure there is memory available. etc. So I suggest using
CONST where appropriate. For GLOBAL variables, in addition to
helping you keep track of the variables you're using, it gives
the compiler a "heads up" on the variables to come.
(Or I may just be full of it Wink ) At any rate, we'll use this
CONST in our program. Look at the screen shot to see the effects of NL$.
Code:
CONST Egg_checkbox$ = CONCAT$("Check if you", NL$, " want eggs")

Introducing three more widgets AND going to add a tad bit of logic in to boot.

We'll add a section for ordering Eggs, putting a FRAME around it.
Nothing new here:
Code:
   '--- Add FRAME for eggs
   Eggs_frame_ = FRAME(380, 130)
   TEXT(Eggs_frame_, " How about those Eggs ")
   ATTACH(Mainwin_, Eggs_frame_, 10, 85)


The first widget is the CHECKbox.
Code:
   '--- CHECK box for eggs
   Eggs_or_not_ = CHECK(Egg_checkbox$, 100, 45)
   ATTACH(Mainwin_, Eggs_or_not_, 20, 130)

Next up is a LIST widget. Items are added to the LIST widget
in the same way we added items to the COMBO widget; with
the TEXT method. I deliberately added more items to the
list than will fit in the LIST window. This to show that
the list window will automatically add a scrool bar. If
an item in the list is too wide to fit the window, a
horizontal scrool bar will be added. Note the DISABLE
method is used, the list is "grayed out" and not accessable.
(We'll do the same for the egg count).
Code:
   '--- Add a LIST widget for cooking eggs
   Eggs_list_ = LIST(120, 100)
   TEXT(Eggs_list_, "Sunny Side Up")
   TEXT(Eggs_list_, "Over Easy")
   TEXT(Eggs_list_, "Scrambled")
   TEXT(Eggs_list_, "Poached")
   TEXT(Eggs_list_, "Runny")
   TEXT(Eggs_list_, "Hard Boiled")
   ATTACH(Mainwin_, Eggs_list_, 150, 105)
   DISABLE(Eggs_list_)

The SPIN widget is just an up/down counter. It's set up
like this:
Handle_ = SPIN( xsize, ysize, start_count, end_count, step)
Throw in a label so the user knows what the count is for.
This SPINner allows the user to pick from 1 to 4 eggs.
Code:
   '--- Label/MARK for egg count
   Tmp$ = CONCAT$("How Many", NL$, "    Eggs")
   How_many_label_ = MARK(Tmp$, 75, 40)
   ATTACH(Mainwin_, How_many_label_, 300, 120)

   '--- Add SPINner widget for how many eggs
   How_many_eggs_ = SPIN(40, 26, 1, 4, 1)
   ATTACH(Mainwin_, How_many_eggs_, 320, 160)
   DISABLE(How_many_eggs_)
   SET(How_many_eggs_, 2)

Now we'll add in some logic. If the CHECK box is blank, then
the user doesn't get to make selections about the eggs.
ie. DISABLE'd. If the box is checked, we need to ENABLE the
egg selection widgets. We'll do the actual enable-ing with a
call to a SUBroutine; get to that in a moment.

There are two parts to the logic here. First, watch the
CHECK box for a change. Second, do something if the CHECK box
status changes. We'll set up a CALLBACK function to watch for
an "event" (in this case anything) to happen to the CHECK box.
We gave the CHECK box the widget handle "Eggs_or_not_". And
we'll write a subroutine named "ENABLE_EGGS" to execute when
an event occurs to "Eggs_or_not_".
Code:
CALLBACK(Eggs_or_not_, ENABLE_EGGS)

About the IF/THEN construct. In simplest form-
Code:
IF this_is_true THEN
   do_this
END IF
The "this_is_true" just needs to evaluate to a non zero
result. In our case, GET(.....) gets the value of the CHECK box
widget. "0" if not checked, "1" if checked. So if our CHECK box
is checked, GET(Eggs_or_not_) evaluates to "1" ie TRUE, and the
following commands are executed. Otherwise it must be FALSE, so
execute the commands after the "ELSE" statement. For more in-depth
info on IF/THEN, Google-it.
Code:
' ------------------
SUB ENABLE_EGGS
' ------------------
   IF GET(Eggs_or_not_) THEN
      ENABLE(Eggs_list_)
      ENABLE(How_many_eggs_)
   ELSE
      DISABLE(Eggs_list_)
      DISABLE(How_many_eggs_)
   END IF
END SUB

Check out the whole program to see how the widgets are used, and the
CALLBACK and SUB routine are setup.

rod

(how did I get the text at the top bigger and thicker ?)
hello_bacon.png
 Description   
 Filesize   26.94 KB
 Viewed   785 Time(s)

hello_bacon.png

hello_bacon.tar.gz
Description  hello_bacon source
gz

 Download 
Filename  hello_bacon.tar.gz 
Filesize  1.24 KB 
Downloaded  302 Time(s) 
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Tue 09 Aug 2011, 23:10    Post subject:  

Rob; Next make the combo auto put the selection into a entry.
And add a button that puts the combo`s current selection into a label.

So combo action is demoed, and changing a label`s text is also.

Combo boxes are a real sore point of gtkDialog. Little functionality.
Back to top
View user's profile Send private message 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Wed 10 Aug 2011, 03:03    Post subject: Combo Challenge  

Quote:
Next make the combo auto put the selection into a entry.
And add a button that puts the combo`s current selection into a label.
Okie Dokie Wink
rod
Code:
'Da combo challenge
INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT

' ------------------
FUNCTION SEND_TEXT_TO_ENTRY
' ------------------
   TEXT(My_entry_, GRAB$(My_combo_))
   RETURN TRUE
END FUNCTION

' ------------------
SUB COMBO2LABEL
' ------------------
   TEXT(My_label_, GRAB$(My_combo_))
END SUB

' ------------------
SUB CLEAR_LABEL
' ------------------
   TEXT(My_label_, "")
END SUB

' ------------------
SUB MAKE_GUI
' ------------------
   Mainwin_ = WINDOW( "Combo Challenge", 200, 200 )
   PROPERTY(Mainwin_, "icon-name", "gtk-execute")

   '--- COMBO widget with 3 items
   My_combo_ = COMBO("November", 100, 28 )
   TEXT( My_combo_, "Whiskey")
   TEXT( My_combo_, "India")
   ATTACH( Mainwin_, My_combo_, 50, 10 )

   My_entry_ = ENTRY("", 100, 30)
   ATTACH(Mainwin_, My_entry_, 50, 40)

   My_frame_ = FRAME(100, 40)
   TEXT(My_frame_, " Label in here")
   FONT(My_frame_, " 9")
   ATTACH(Mainwin_, My_frame_, 50, 75)

   My_label_ = MARK("", 100, 30)
   ATTACH(Mainwin_, My_label_, 50, 80)

   My_btn_ = BUTTON("Combo2Label", 100, 30)
   ATTACH(Mainwin_, My_btn_, 50, 120)

   My_other_btn_ = BUTTON("Clear-Label", 100, 30)
   ATTACH(Mainwin_, My_other_btn_, 50, 160)

   CALLBACK(My_btn_, COMBO2LABEL)
   CALLBACK(My_other_btn_, CLEAR_LABEL)
   TIMEOUT(500, SEND_TEXT_TO_ENTRY)

END SUB

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

MAKE_GUI

DISPLAY
combo_challenge.jpg
 Description   
 Filesize   8.73 KB
 Viewed   840 Time(s)

combo_challenge.jpg

Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 4980
Location: Arizona, U.S.A.

PostPosted: Wed 10 Aug 2011, 09:46    Post subject:  

Very nice GatorDog, it took a minute for me to see the TIMEOUT.

I was puzzled by what the action was that made the combo work.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 3 of 12 [168 Posts]   Goto page: Previous 1, 2, 3, 4, 5, ..., 10, 11, 12 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.1201s ][ Queries: 13 (0.0058s) ][ GZIP on ]