' BaCon / HUG Hello World
' hello.bac
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT


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


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

' 3.) Attach the label to the main window
ATTACH( Mainwin, My_label, 50, 20 )

' 4.) Create a button
My_btn = BUTTON( "I'm done", 80, 25)

' 5.) Attach button to the main window
ATTACH( Mainwin, My_btn, 10, 60 )

' 6.) Make button do something
CALLBACK( My_btn, QUIT)

'7.) Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 155, 60 )

'8.)Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY

Back to top of document




STATIC TEXT


[image]

Example code: static.bac


' static.bac
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT


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


' 2. ) Create a label Hello BaCon! with text, 150 x 30
My_label = MARK( "This is static text", 150, 30 )

' 3.) Attach the label to the main window
ATTACH( Mainwin, My_label, 50, 20 )

' 4.) Create a button
My_btn = STOCK( "gtk-yes", 80, 25)

' 5.) Attach button to the main window
ATTACH( Mainwin, My_btn, 10, 60 )

' 6.) Make button do something
CALLBACK( My_btn, QUIT)

'7.) Create a button.
My_chk = STOCK("gtk-cancel", 80, 25)
ATTACH( Mainwin, My_chk, 155, 60 )

'8.)Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY



Back to top of document



MARKUP

[image]


Example code:  markup-01.bac

' markup-01.bac
' equivilent gtkdialog 00.01-text_attributes
' With SUB routine example

INCLUDE "hug.bac"
INIT


' -------------------------------
SUB LAUNCH_APP
' ------------------------------
    ' TEXT changes the text of a widget/My_label
    TEXT( My_label, result$)
END SUB


' Create your main working window, 275 pixels wide x 100 pixels high
Mainwin = WINDOW( " BaCon Using markup", 275, 100 )
result$ = CONCAT$("<u>This is underlined text</u>")

 ' Create a label with text, 180 x 30

My_label = MARK( "<span color=\"blue\">Color can be used too</span> ", 180, 30 )
My_label2 = MARK( "<b>Use-markup</b> , which is cool.", 180, 30 )

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

' --- BUTTONS ---
My_btn = BUTTON( "Launch", 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, LAUNCH_APP)
CALLBACK( My_close, QUIT)

DISPLAY


Back to top of document




INPUT2

[image]


Example code: text_input-02.bac

' text_input-02.bac
' just view a file
' Include the files for making a GUI.

INCLUDE "hug.bac"
INIT


' 1.) Create your main working window,400 pixels wide x 300 pixels high
Mainwin = WINDOW( "BaCon input file ", 400, 300 )


EDIT_BOX = EDIT(370, 250)
ATTACH( Mainwin, EDIT_BOX, 10, 10 )


' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 295, 265 )

' Make button do something
CALLBACK( My_chk, QUIT)


'--- get the display info using a system call ---'
'--- the bash command "date" is used as input ---'


result_input$ = EXEC$("cat /etc/hosts.allow")
result_input2$ = EXEC$("date")
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, "---------input from file /etc/hosts.allow------------")
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, result_input$)
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, "---------input from command date------------")
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, result_input2$)

DISPLAY

BUTTON1

[image]

Example code: button-1.00.bac

' buttons-1.00.bac
' equivalent gtkdialog 01.00-button
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which button was pressed
' this could launch another app


'--------------------'
SUB demo1
'--------------------'
    PRINT "Label"
END
SUB


'--------------------'
SUB demo2
'--------------------'
    PRINT "yes"
END SUB


'--------------------'
SUB demo3
'--------------------'
     PRINT "no"
END SUB


'--------------------'
 SUB demo4
'--------------------'
     PRINT "ok"
END SUB


'--------------------'
 SUB demo5
'--------------------'
     PRINT "cancel"
END SUB


'--------------------'
SUB demo6
'--------------------'
     PRINT "help"
END SUB



' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon buttons", 250, 100 )


' Create a button
My_btn = BUTTON( "Label", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 5, 10 )

' Make button do something
CALLBACK( My_btn, demo1)

' Create a button
My_btn = STOCK( "gtk-yes", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 85, 10 )

' Make button do something
CALLBACK( My_btn, demo2)

' Create a button
My_btn = STOCK( "gtk-no", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 165, 10 )

' Make button do something
CALLBACK( My_btn, demo3)
'-----------------------------'
'--- second row of buttons ---'
'-----------------------------'

' Create a button
My_btn = STOCK( "gtk-ok", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 5, 35 )

' Make button do something
CALLBACK( My_btn, demo4)

' Create a button
My_btn = STOCK( "gtk-cancel", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 85, 35 )

' Make button do something
CALLBACK( My_btn, demo5)

' Create a button
My_btn = STOCK( "gtk-help", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 165, 35 )

' Make button do something
CALLBACK( My_btn, demo6)


'-----------------------------'
'--- the real cancel ---'
'-----------------------------'

' Create a button. the real cancel quit
My_chk = STOCK("gtk-cancel", 80, 25)
ATTACH( Mainwin, My_chk, 165, 60 )

' Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY


Back to top of document


CHECKBOX

[image]

Example code: checkbox.bac
' checkbox.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which checkbox was pressed
' this could launch another app

'--------------------'
SUB checkbox_demo
'--------------------'
     PRINT "check_boxdemo"
END SUB

' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon checkbox", 250, 100 )

' remember create, ATTACH ,CALLBACK ,SUB

My_checkbox = CHECK("checkbox here", 120, 25)
ATTACH( Mainwin, My_checkbox, 10, 10 )
CALLBACK(My_checkbox, checkbox_demo)

DISPLAY

Back to top of document


ENTRY

[image]

Example code: bacon-entry.bac

' bacon-entry.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" text in the entry

'--------------------'
SUB entry_demo
'--------------------'
     PRINT "entry_demo"
END SUB

' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon entry", 250, 100 )

' remember create, ATTACH ,CALLBACK ,SUB

My_entry = ENTRY("entry here", 120, 25)
ATTACH( Mainwin, My_entry, 10, 10 )
CALLBACK(My_entry, entry_demo)

DISPLAY



Back to top of document







ACTION-TYPES

[image]
equivalent gtkdialog 01.02-button_action_types

Example code: bacon-action-types.bac


' bacon-action-types.bac
' equivalent gtkdialog 01.02-button_action_types
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT


' we want to "echo out" text in the entry
'--------------------------------
SUB entry_demo
'--------------------------------
    PRINT "entry_demo"
END SUB



' we want to "echo out" which button was pressed
' this could launch another app

'--------------------------------
SUB checkbox_demo
'--------------------------------
    PRINT "check_boxdemo"
END SUB


'--------------------------------
SUB demo1
'--------------------------------
    PRINT "enable"
    ENABLE(My_entry)
END SUB


'--------------------------------
SUB demo2
'--------------------------------
    PRINT "disable"
    DISABLE(My_entry)
END SUB

'--------------------------------
SUB demo3
'--------------------------------
    PRINT "yes"
END SUB

'--------------------------------
SUB demo4
'--------------------------------
    PRINT "refresh"
    result_input2$ = EXEC$("date")
    ' remember create, ATTACH ,CALLBACK ,SUB
    My_entry = ENTRY(result_input2$, 205, 25)
    ATTACH( Mainwin, My_entry, 5, 50 )
END SUB

'--------------------------------
SUB demo5
'--------------------------------
    PRINT "clear"
    My_entry = ENTRY("", 205, 25)
    ATTACH( Mainwin, My_entry, 5, 50 )
END SUB

'--------------------------------
SUB demo6
'--------------------------------
    PRINT "fileselect"
    My_file = FILEDIALOG("select file", "ok", 0, 0, 0)
    SHOW (My_file)
END SUB



' 1.) Create your main working window, 260 pixels wide x 170 pixels high
Mainwin = WINDOW( "BaCon action_types ", 260, 170 )



' remember create, ATTACH ,CALLBACK ,SUB

My_checkbox = CHECK("This is a checkbox", 150, 25)
ATTACH( Mainwin, My_checkbox, 5, 0 )
CALLBACK(My_checkbox, checkbox_demo)



' place a label for the entry to say what it does notice negative number
My_label = MARK( "<span color=\"blue\">The date in the entry</span> ", 180, 30 )
ATTACH( Mainwin, My_label, -10, 25 )


result_input2$ = EXEC$("date")
' remember create, ATTACH ,CALLBACK ,SUB

My_entry = ENTRY(result_input2$, 205, 25)
ATTACH( Mainwin, My_entry, 5, 50 )
CALLBACK(My_entry, entry_demo)


' Create a button
My_btn = BUTTON( "enable", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 5, 90 )

' Make button do something
CALLBACK( My_btn, demo1)


' Create a button
My_btn = STOCK( "disable", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 85, 90 )

' Make button do something
CALLBACK( My_btn, demo2)


' Create a button
My_btn = STOCK( "gtk-yes", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 165, 90 )

' Make button do something
CALLBACK( My_btn, demo3)
'-----------------------------'
'--- second row of buttons ---'
'-----------------------------'

' Create a button
My_btn = BUTTON( "refresh", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 5, 115 )

' Make button do something
CALLBACK( My_btn, demo4)


' Create a button
My_btn = BUTTON( "clear", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 85, 115 )

' Make button do something
CALLBACK( My_btn, demo5)


' Create a button
My_btn = BUTTON( "fileselect", 80, 25)

' Attach button to the main window
ATTACH( Mainwin, My_btn, 165, 115 )

' Make button do something
CALLBACK( My_btn, demo6)


'-----------------------------'
'--- the real cancel ---'
'-----------------------------'

' Create a button. the real cancel quit
My_chk = STOCK("gtk-cancel", 80, 25)
ATTACH( Mainwin, My_chk, 165, 145 )

' Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY


Back to top of document




ICON-MATE

[image]


*This uses mate icons so may not work with your desktop * I used the distro mint 18.2 so that's what it was tested on
just point the icons to ones you have the idea is what is important
it has tool-tips also
updated code for mate


' Note you may not have mate installed so use other icons for images

'/usr/share/icons/default

Example code: bacon-icon-mate.bac

' BaCon
' Add images as buttons and tool-tips 3x5 format using 32x32 pixel icons
' bacon-icon-mate.bac
' Note you may not have mate installed so use other icons
' TESTED on mint 18.2

INCLUDE "hug.bac"
INIT


SUB application_exit_clicked
    PRINT "application_exit"   
END SUB


SUB color_picker_clicked
    PRINT "color_picker"   
END SUB


SUB go_previous_clicked
    PRINT "go_previous"   
END SUB



SUB bookmark_new_list_clicked
    PRINT "bookmark_new_list"   
END SUB



SUB go_down_clicked
    PRINT "go_down"   
END SUB

'second row

SUB edit_cut_clicked
    PRINT "edit_cut"   
END SUB


SUB dialog_ok_apply_clicked
    PRINT "dialog_ok_apply"   
END SUB


SUB list_add_clicked
    PRINT "list_add"   
END SUB



SUB view_refresh_clicked
    PRINT "view_refresh"   
END SUB



SUB configure_clicked
    PRINT "configure"   
END SUB


'third row


SUB draw_eraser_clicked
    PRINT "draw_eraser"   
END SUB


SUB run_build_clicked
    PRINT "run_build"   
END SUB


SUB edit_redo_clicked
    PRINT "edit_redo"   
END SUB



SUB tools_wizard_clicked
    PRINT "tools_wizard"   
END SUB



SUB view_preview_clicked
    PRINT "view_preview_clicked"   
END SUB





Mainwin = WINDOW( "BaCon image-mate", 240, 170 )


application_exit = IMAGE("/usr/share/icons/mate/32x32/actions/application-exit.png" ,30,30)
ATTACH(Mainwin, application_exit, 15, 30)
CALLBACK( application_exit , application_exit_clicked)
PROPERTY( application_exit, "tooltip-text", "application-exit")


color_picker = IMAGE("/usr/share/icons/mate/32x32/actions/color-picker.png" ,30,30)
ATTACH(Mainwin, color_picker, 50, 30)
CALLBACK(color_picker ,color_picker_clicked)
PROPERTY(color_picker, "tooltip-text", "color_picker")


go_previous = IMAGE("/usr/share/icons/mate/32x32/actions/go-previous.png" ,30,30)
ATTACH(Mainwin, go_previous, 90, 30)
CALLBACK(go_previous ,go_previous_clicked)
PROPERTY(go_previous, "tooltip-text", "go_previous")


bookmark_new_list = IMAGE("/usr/share/icons/mate/32x32/actions/bookmark-new-list.png" ,30,30)
ATTACH(Mainwin, bookmark_new_list, 130, 30)
CALLBACK(bookmark_new_list ,bookmark_new_list_clicked)
PROPERTY(bookmark_new_list, "tooltip-text", "bookmark_new_list")


go_down = IMAGE("/usr/share/icons/mate/32x32/actions/go-down.png" ,30,30)
ATTACH(Mainwin, go_down, 170, 30)
CALLBACK(go_down ,go_down_clicked)
PROPERTY(go_down, "tooltip-text", "go_down")

' second row


edit_cut = IMAGE("/usr/share/icons/mate/32x32/actions/edit-cut.png" ,30,30)
ATTACH(Mainwin, edit_cut, 15, 70)
CALLBACK( edit_cut , edit_cut_clicked)
PROPERTY( edit_cut , "tooltip-text", " edit_cut")


dialog_ok_apply = IMAGE("/usr/share/icons/mate/32x32/actions/dialog-ok-apply.png" ,30,30)
ATTACH(Mainwin, dialog_ok_apply, 55, 70)
CALLBACK(dialog_ok_apply ,dialog_ok_apply_clicked)
PROPERTY(dialog_ok_apply, "tooltip-text", "dialog_ok_apply")


list_add = IMAGE("/usr/share/icons/mate/32x32/actions/list-add.png" ,30,30)
ATTACH(Mainwin, list_add, 90, 70)
CALLBACK(list_add ,list_add_clicked)
PROPERTY(list_add, "tooltip-text", "list_add")



view_refresh = IMAGE("/usr/share/icons/mate/32x32/actions/view-refresh.png" ,30,30)
ATTACH(Mainwin, view_refresh, 130, 70)
CALLBACK(view_refresh ,view_refresh_clicked)
PROPERTY(view_refresh, "tooltip-text", "view_refresh")


configure = IMAGE("/usr/share/icons/mate/32x32/actions/configure.png" ,30,30)
ATTACH(Mainwin, configure, 170, 70)
CALLBACK(configure ,configure_clicked)
PROPERTY(configure, "tooltip-text", "configure")

'third row



draw_eraser = IMAGE("/usr/share/icons/mate/32x32/actions/draw-eraser.png" ,30,30)
ATTACH(Mainwin, draw_eraser, 15, 110)
CALLBACK( draw_eraser , draw_eraser_clicked)
PROPERTY( draw_eraser , "tooltip-text", " draw_eraser")


run_build = IMAGE("/usr/share/icons/mate/32x32/actions/run-build.png" ,30,30)
ATTACH(Mainwin, run_build, 55, 110)
CALLBACK(run_build ,run_build_clicked)
PROPERTY(run_build, "tooltip-text", "run_build")


edit_redo = IMAGE("/usr/share/icons/mate/32x32/actions/edit-redo.png" ,30,30)
ATTACH(Mainwin, edit_redo, 90, 110)
CALLBACK(edit_redo ,edit_redo_clicked)
PROPERTY(edit_redo, "tooltip-text", "edit_redo")


tools_wizard = IMAGE("/usr/share/icons/mate/32x32/actions/tools-wizard.png" ,30,30)
ATTACH(Mainwin, tools_wizard, 130, 110)
CALLBACK(tools_wizard ,tools_wizard_clicked)
PROPERTY(tools_wizard, "tooltip-text", "tools_wizard")


view_preview = IMAGE("/usr/share/icons/mate/32x32/actions/view-preview.png" ,30,30)
ATTACH(Mainwin, view_preview, 170, 110)
CALLBACK(view_preview ,view_preview_clicked)
PROPERTY(view_preview, "tooltip-text", "view_preview")



' Create a label "click on an image" with text, 100 x 30
My_label = MARK( "click on an image", 130, 165 )

' Attach the label to the main window
ATTACH( Mainwin, My_label, 0, 75 )

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

'--- CALLBACKS ---
CALLBACK(Close_btn, QUIT)

DISPLAY



Back to top of document



RADIOBOX

[image]

Example code: radio-box.bac

' radio-box.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which radiobox was pressed
' this could launch another app

SUB radiobox_demo
PRINT "radiobox_demo"
END SUB



' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon radiobox", 250, 100 )

' remember create, ATTACH ,CALLBACK ,SUB
' remember radiobox has an extra field at the end than the checkbox



My_radiobox = RADIO("This is a radiobox", 150, 25,0)
ATTACH( Mainwin, My_radiobox, 5, 0 )
CALLBACK(My_radiobox, radiobox_demo)

DISPLAY

Back to top of document





LISTBOX

[image]

Example: listbox.bac

' listbox.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which listbox was pressed
' this could launch another app use GRAB$

SUB My_listbox_demo
Listbox_selected$ = GRAB$(My_listbox)
PRINT Listbox_selected$
END SUB



' 1.) Create your main working window, 250 pixels wide x 130 pixels high
Mainwin = WINDOW( "BaCon listbox", 250, 130 )

' remember create, ATTACH ,CALLBACK ,SUB

Menu_label = MARK("Select an option from the Menu" , 220, 30)
ATTACH( Mainwin, Menu_label, 5, 0 )

My_listbox = LIST(180, 75)
TEXT(My_listbox ,"First choice" )
TEXT(My_listbox ,"Second choice" )
TEXT(My_listbox ,"Third choice" )
ATTACH( Mainwin, My_listbox, 5, 30 )
CALLBACK(My_listbox, My_listbox_demo)



DISPLAY
 

Back to top of document


 

COMBO-BOX


[image]

Example: combobox.bac

' combobox.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which combobox was pressed
' this could launch another app use GRAB$

SUB My_combobox_demo
Combobox_selected$ = GRAB$(My_combobox)
PRINT Combobox_selected$
END SUB



' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon combobox", 250, 100 )

' remember create, ATTACH ,CALLBACK ,SUB

Menu_label = MARK("Select an option from the Menu" , 220, 30)
ATTACH( Mainwin, Menu_label, 5, 0 )

My_combobox = COMBO("First choice", 180, 30)
TEXT(My_combobox ,"Second choice" )
TEXT(My_combobox ,"Third choice" )
ATTACH( Mainwin, My_combobox, 5, 30 )
CALLBACK(My_combobox, My_combobox_demo)



DISPLAY

Back to top of document


MSGDIALOG

[image]

clicking the Help button launches this

Example: msgdialog.bac
' msgdialog.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT


' ------------------
SUB close_dialog(NUMBER widget)
' ------------------
SYSTEM "true"
FOCUS(Mainwin)
HIDE(widget)
END SUB


' ------------------
SUB SHOW_HELP
' ------------------
SHOW(msgbox1)
END SUB



' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon MSGDIALOG", 275, 100 )


Help_btn_ = STOCK("gtk-help", 100,30)
ATTACH(Mainwin, Help_btn_,5 ,0 )
CALLBACK(Help_btn_, SHOW_HELP )

'--- Help Dialog
msgbox1 = MSGDIALOG(CONCAT$("First line \n", \
"Second line\n", \
"Third line\n", \
"Fourth line"), \
350, 200, 0, 2)

CALLBACK(msgbox1, close_dialog)
DISPLAY

Back to top of document



EDIT


[image]


Note there are two examples here
this is like the input file example but has a call back to grab the text in the box
and take input from a file


Example: edit.bac


' edit.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

SUB TEXT_OUT
PRINT GRAB$(EDIT_BOX)
ENDSUB

' 1.) Create your main working window, 350 pixels wide x 200 pixels high
Mainwin = WINDOW( "BaCon EDIT ", 350, 200 )

My_label = MARK( "Type or paste something in the box ", 300, 30 )
ATTACH( Mainwin, My_label, 10, 10)
FONT(My_label, "sans 12")

' formatting changes if you use another label name
My_label = MARK( "Press Text out when done ", 300, 30 )
ATTACH( Mainwin, My_label, -20 ,30)
FONT(My_label, "sans 12")


EDIT_BOX = EDIT(310, 100)
ATTACH( Mainwin, EDIT_BOX, 20, 60 )

My_btn = BUTTON("Text out", 80, 25)
ATTACH( Mainwin, My_btn, 140, 165 )
CALLBACK( My_btn, TEXT_OUT)


' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 255, 165 )

' Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY


EDIT2

get input from a file

[image]


Example: bacon-edit2.bac
' edit2.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

SUB TEXT_OUT
PRINT GRAB$(EDIT_BOX)
ENDSUB

' 1.) Create your main working window, 350 pixels wide x 200 pixels high
Mainwin = WINDOW( "BaCon EDIT ", 350, 200 )

My_label = MARK( "Type or paste something in the box ", 300, 30 )
ATTACH( Mainwin, My_label, 10, 10)
FONT(My_label, "sans 12")

' formatting changes if you use another label name
My_label = MARK( "Press Text out when done ", 300, 30 )
ATTACH( Mainwin, My_label, -20 ,30)
FONT(My_label, "sans 12")


EDIT_BOX = EDIT(310, 100)
ATTACH( Mainwin, EDIT_BOX, 20, 60 )

My_btn = BUTTON("Text out", 80, 25)
ATTACH( Mainwin, My_btn, 140, 165 )
CALLBACK( My_btn, TEXT_OUT)


' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 255, 165 )

' Make button do something
CALLBACK( My_chk, QUIT)


'--- get the display info using a system call ---'
'--- the bash command "date" is used as input ---'
result_input2$ = EXEC$("date")
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, NL$)
TEXT(EDIT_BOX, result_input2$)
DISPLAY

Back to top of document

RESIZE-WINDOW

[image]

Here is a resizable window using the PROPERTY option.
P.S simple but I didn't know you could do this so easily



'resize-window.bac

INCLUDE "hug.bac"
INIT

    win = WINDOW("resize", 200, 100)    
    PROPERTY(win, "resizable", TRUE)
    
DISPLAY

Back to top of document



SPINBOX

[image]


Example: bacon-spin.bac

 bacon-spin.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT



SUB My_SPINBOX
PRINT GET(SPIN_STR)
END SUB



' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "BaCon SPINBOX ", 250, 100 )

FRAME_STR = FRAME(225, 50)

ATTACH( Mainwin, FRAME_STR, 10, 10 )

' SPIN uses GET to see the value in the SUB
SPIN_STR = SPIN(100,30, 1, 10, 1)
ATTACH( Mainwin, SPIN_STR, 15, 20 )


' Create a button.
GET_NUMBER = BUTTON("get number", 100, 25)
ATTACH( Mainwin, GET_NUMBER , 40, 65 )



' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 155, 65 )

' Make button do something
CALLBACK( My_chk, QUIT)
CALLBACK(GET_NUMBER, My_SPINBOX)


DISPLAY

Back to top of document


VSLIDER

[image]



Example: bacon-vslider.bac

' bacon-vslider.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT



SUB My_VSLIDER
PRINT GET(VSLIDER_STR)
END SUB




' 1.) Create your main working window, 250 pixels wide x 200 pixels high
Mainwin = WINDOW( "BaCon VSLIDER ", 220, 200 )

FRAME_STR = FRAME(195, 150)

ATTACH( Mainwin, FRAME_STR, 10, 10 )



' VSLIDER uses GET to see the value in the SUB
VSLIDER_STR = VSLIDER(100,130, 1, 10, 1)
ATTACH( Mainwin, VSLIDER_STR, 15, 15 )



' Create a button.
GET_NUMBER = BUTTON("ok", 80, 25)
ATTACH( Mainwin, GET_NUMBER , 10, 165 )



' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 125, 165 )

' Make button do something
CALLBACK( My_chk, QUIT)
CALLBACK(GET_NUMBER, My_VSLIDER)


DISPLAY

Back to top of document




HSLIDER


[image]

Example: bacon-hslider.bac

' bacon-hslider.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT



SUB My_HSLIDER
PRINT GET(HSLIDER_STR)
END SUB




' 1.) Create your main working window, 250 pixels wide x 200 pixels high
Mainwin = WINDOW( "BaCon HSLIDER ", 220, 200 )

FRAME_STR = FRAME(195, 150)

ATTACH( Mainwin, FRAME_STR, 10, 10 )



' HSLIDER uses GET to see the value in the SUB
HSLIDER_STR = HSLIDER(100,130, 1, 10, 1)
ATTACH( Mainwin, HSLIDER_STR, 15, 15 )



' Create a button.
GET_NUMBER = BUTTON("ok", 80, 25)
ATTACH( Mainwin, GET_NUMBER , 10, 165 )



' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 125, 165 )

' Make button do something
CALLBACK( My_chk, QUIT)
CALLBACK(GET_NUMBER, My_HSLIDER)


DISPLAY

Back to top of document








 
PROGRESSBAR

[image]


Pjot has made a new progress bar demo that he has added to the Hug documentation

This is a more advanced widget and a little more complex for those getting started
with BaCon because it uses some new commands SET, GET, TIMEOUT and RETURN TRUE/FALSE


[image]
-------------------------------------------------------------------------------
some help to explain code and other options
TEXT(widget, "text")

Widget ......................... Behavior
Progressbar .................. Sets the text in the progressbar

*not used but this allows numbers to be seen instead of the word "demo"
TEXT(pb, STR$(x))



SET(widget, value)
SET(pb, x) this gets the value of x in the progressbar

GET
PRINT GET(pb) this echos out to the terminal the number value


Example: bacon-progressbar.bac

'progressbar-demo.bac
INCLUDE "hug.bac"
DECLARE pb, x, offset
offset = 1

FUNCTION set_value
INCR x, offset
IF x >= 100 OR x <= 0 THEN offset = -1*offset
SET(pb, x)
PRINT GET(pb)
RETURN TRUE
END FUNCTION

INIT
win = WINDOW("Progressbar", 200, 30)
pb = PROGRESSBAR("demo", 200, 30)
ATTACH(win, pb, 0, 0)
TIMEOUT(100, set_value)
DISPLAY



Back to top of document





CANVAS

[image]

Example: bacon-canvas.bac

'bacon-canvas.bac
INCLUDE "hug.bac"

canvas_x = 450
canvas_y = 380

'----------------------
SUB CLEAN_SCREEN
'----------------------
    'clear terminal output
    CLEAR
    'redraw canvas again
    canvas = CANVAS(canvas_x, canvas_y)
    ATTACH(win, canvas, 0,0)
    CALLBACK(clean, CLEAN_SCREEN)
    CALLBACK(canvas, HandleMouse)
    CALLBACK(myquit, QUIT)
END SUB

'----------------------
SUB HandleMouse
'----------------------
    cursor_x = MOUSE(0)
    cursor_y = MOUSE(1)
    IF MOUSE(2) = 1 THEN
        PRINT
        PRINT cursor_x, " cursor_x"
        PRINT cursor_y, " cursor_y"
        PRINT

        DRAW(canvas)
        LINE("blue", 0, cursor_y, 400, cursor_y)
        LINE("yellow", cursor_x, 0, cursor_x, 440)
    END IF
END SUB

'----------------------
'MAIN GUI
'----------------------
INIT

    HUGOPTIONS("NOSCALING")

    win = WINDOW("Get x and y positions", 450, 440)
    canvas = CANVAS(canvas_x, canvas_y)
    ATTACH(win, canvas, 0, 0)

    mark1 = MARK("Left click to start", 300, 15)
    ATTACH (win, mark1, 42, 400)

    clean = BUTTON("Clean", 70, 30)
    myquit = BUTTON("Quit", 70, 30)

    ATTACH(win, clean, 10 ,390)
    ATTACH(win, myquit, 318, 390)

    CALLBACK(clean, CLEAN_SCREEN)
    CALLBACK(canvas, HandleMouse)
    CALLBACK(myquit, QUIT)

DISPLAY




Back to top of document


SPINNER

[image]
The next example comes from Pjot
I asked Peter to convert the other two functions of the spinner demo (vovchik did) to 100% HUG




spinner_INCLUDE.bac  doesn't get compiled it is a compile time dependency
just have it in the same place as spinner-HUG-convertered.bac when
you compile

'spinner_INCLUDE.bac
'INCLUDE "hug.bac", INIT, WINDOW, BUTTON, HUGLIB$, METHOD, REGISTER, SET, ATTACH, CALLBACK, QUIT, DISPLAY
CONST gtk$ = HUGLIB$("gtk")

' ------------------
' spinner GTK functions
' ------------------
IMPORT "gtk_spinner_new" FROM gtk$ TYPE long
IMPORT "gtk_spinner_start(long)" FROM gtk$ TYPE void
IMPORT "gtk_spinner_stop(long)" FROM gtk$ TYPE void

'spinner_INCLUDE.bac
' ------------------
' The self-defined method for SET
' ------------------
SUB spin_set(NUMBER hug_widget, int value)
' ------------------
IF value THEN
gtk_spinner_start(hug_widget)
ELSE
gtk_spinner_stop(hug_widget)
END IF

END SUB

' ------------------
' The creation of the spinner
' ------------------
FUNCTION SPINNER(int hug_xsize, int hug_ysize)
' ------------------
LOCAL widget

' create the spinner
widget = gtk_spinner_new
' register and determine size and signal
REGISTER(widget, hug_xsize, hug_ysize, "", 0, 0, 0, 0)
' We use the SET method to let the widget spin (1) or not (0)
METHOD(widget, 4, spin_set)

RETURN widget

END FUNCTION



Example: spinner-HUG-convertered.bac  this gets compiled

'spinner-HUG-convertered.bac
'depends on spinner_INCLUDE.bac

INCLUDE "hug.bac"
INCLUDE "spinner_INCLUDE.bac"
' ------------------
SUB SPIN_STOP
' ------------------
PRINT "Stop spinner"
SET(spinner, 0)
END SUB

' ------------------
SUB SPIN_START
' ------------------
PRINT "Start spinner"
SET(spinner, 1)
END SUB

' ------------------
SUB MK_GUI
' ------------------
INIT
win = WINDOW("spinner demo", 220, 210)
start = BUTTON("Start", 70, 30)
stop = BUTTON("Stop", 70, 30)

myquit = BUTTON("Quit", 70, 30)
spinner = SPINNER(24, 24)
PROPERTY(myquit, "tooltip-text", "Exit program.")

ATTACH(win, start, 10, 10)
ATTACH(win, stop, 10, 40)

ATTACH(win, spinner, 10, 173)
ATTACH(win, myquit, 120, 170)

CALLBACK(start, SPIN_START)
CALLBACK(stop, SPIN_STOP)

CALLBACK(myquit, QUIT)

END SUB

MK_GUI
DISPLAY



Back to top of document




DYNAMIC-COMBO


[image]

reads a text file into the combobox

Example code: dynamic-combobox.bac

' dynamic-combobox.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which Combobox_selected$ was pressed


SUB combo_choices_demo
Combobox_selected$ = GRAB$(combo_choices)
PRINT Combobox_selected$
END SUB



' 1.) Create your main working window, 250 pixels wide x 130 pixels high
Mainwin = WINDOW( "BaCon combobox", 250, 130 )



Menu_label = MARK("Select an option from the Menu" , 220, 30)
ATTACH( Mainwin, Menu_label, 5, 0 )



result_input$ = EXEC$("cat boys-names.txt")

'-----------------
SUB MAKE_FILE_LIST
'-----------------

SPLIT result_input$ BY NL$ TO words$ SIZE dim

FOR i = 0 TO dim - 1

combo_choices_text$ = words$[i]

TEXT(combo_choices, words$[i])
PRINT words$[i]

NEXT

END SUB




combo_choices = COMBO("Select a name", 180, 30 )

MAKE_FILE_LIST

ATTACH(Mainwin, combo_choices,5, 30)
CALLBACK(combo_choices, combo_choices_demo)

DISPLAY


Back to top of document






DYNAMIC-LISTBOX


[image]

source the binary to see the selected from the list
place boys-names.txt in /tmp

Example code:  listbox2.bac

' bacon-listbox2.bac

' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT

' we want to "echo out" which listbox_selected$ was pressed


SUB list_choices_demo
listbox_selected$ = GRAB$(list_choices)
PRINT listbox_selected$
END SUB



' 1.) Create your main working window, 250 pixels wide x 130 pixels high
Mainwin = WINDOW( "BaCon listbox", 250, 130 )



Menu_label = MARK("Select an option from the Menu" , 220, 30)
ATTACH( Mainwin, Menu_label, 5, 0 )



result_input$ = EXEC$("cat boys-names.txt")

'-----------------
SUB MAKE_FILE_LIST
'-----------------
 
    SPLIT result_input$ BY NL$ TO words$ SIZE dim

    FOR i = 0 TO dim - 4
        list_choices_text$ = words$[i]
        TEXT(list_choices, words$[i])
        PRINT words$[i]
        PRINT i
    NEXT

END SUB




list_choices = LIST(180, 70 )

MAKE_FILE_LIST

ATTACH(Mainwin, list_choices,5, 30)
CALLBACK(list_choices, list_choices_demo)

DISPLAY




Back to top of document