text2png
Mar 18, 2013 6:39:32 GMT 1
Post by bigbass on Mar 18, 2013 6:39:32 GMT 1
This is something I wrote originally in gtkdialog
but I wanted to port it to BaCon just as a fun exercise
to see what would be needed now in 100% BaCon!
make sure you compile both apps and put them in
the same place they are dependent on each other
*uses just pango-view as the backend to keep things light
' bacon-text2png.bac
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT
CONST Single_quote$ = CHR$(39)
CONST Double_quote$ = CHR$(34)
CONST Dollar_sign$ = CHR$(36)
' short hand also
CONST sq$ = CHR$(39)
CONST dq$ = CHR$(34)
CONST ds$ = CHR$(36)
' initiate app with markup off
SET(My_toggle, 0)
'-----------------------
SUB toggle_demo()
'-----------------------
IF GET(My_toggle) = 1 THEN
PRINT GET(My_toggle)
TEXT(My_toggle, "Enabled_Markup")
ELSE
TEXT(My_toggle, "Disabled_Markup")
END IF
PRINT GRAB$(My_toggle)
PRINT GET(My_toggle)
END SUB
'-----------------------
SUB TEXT_OUT
'-----------------------
PRINT GRAB$(EDIT_BOX)
IMAGE_TXT$ = GRAB$(EDIT_BOX)
PRINT GRAB$(My_entry)
TMP2_PNG_NAME$ = GRAB$(My_entry)
PRINT CURDIR$
' we have to get all the selected data to the system
' because pango-view will be called with these values
' use system concat to avoid exporting out
'The text color
Combobox_selected$ = GRAB$(My_combobox)
'The background color
Combobox_selected2$ = GRAB$(My_combobox2)
'Set font
Combobox_selected3$ = GRAB$(My_combobox3)
'The dpi size of fonts
Combobox_selected4$ = GRAB$(My_combobox4)
IF GET(My_toggle) = 1 THEN
PRINT GET(My_toggle)
' with markup
' carry command over several lines just to make it easier to read
SYSTEM CONCAT$("pango-view", \
" --foreground=", dq$, Combobox_selected$, dq$, \
" --background=",dq$,Combobox_selected2$,dq$, \
" --font=",dq$, Combobox_selected3$, dq$, \
" --dpi=",dq$, Combobox_selected4$, dq$, \
" --markup", " -t " , dq$,IMAGE_TXT$,dq$, " -q ", " -o " ,CURDIR$ ,"/", TMP2_PNG_NAME$ )
ELSE
' without markup
' carry command over several lines just to make it easier to read
SYSTEM CONCAT$("pango-view", \
" --foreground=", dq$, Combobox_selected$, dq$, \
" --background=",dq$,Combobox_selected2$,dq$, \
" --font=",dq$, Combobox_selected3$, dq$, \
" --dpi=",dq$, Combobox_selected4$, dq$, \
" -t " ,dq$,IMAGE_TXT$,dq$ , " -q ", " -o " ,CURDIR$ ,"/", TMP2_PNG_NAME$ )
END IF
PRINT GET(My_toggle)
' launch the viewer app here
SYSTEM CONCAT$(".", "/recent-image2"," &")
ENDSUB
'-----------------------
SUB My_combobox_demo()
'-----------------------
Combobox_selected$ = GRAB$(My_combobox)
PRINT Combobox_selected$
END SUB
'-----------------------
SUB My_combobox_demo2()
'-----------------------
Combobox_selected2$ = GRAB$(My_combobox2)
PRINT Combobox_selected2$
END SUB
'-----------------------
SUB My_combobox_demo3()
'-----------------------
Combobox_selected3$ = GRAB$(My_combobox3)
PRINT Combobox_selected3$
END SUB
'-----------------------
SUB My_combobox_demo4()
'-----------------------
Combobox_selected4$ = GRAB$(My_combobox4)
PRINT Combobox_selected4$
END SUB
' 1.) Create your main working window, 350 pixels wide x 200 pixels high
Mainwin = WINDOW( "BaCon Text to png ", 450, 400 )
My_label = MARK( "Type or paste something in the box ", 300, 30 )
ATTACH( Mainwin, My_label, -10, 100)
FONT(My_label, "sans 10")
'======================
'---toggle
'======================
My_toggle = TOGGLE("Markup_Disabled", 120, 25)
ATTACH( Mainwin, My_toggle, 230, 60 )
CALLBACK(My_toggle, toggle_demo)
'======================
'---entry box
'======================
My_entry = ENTRY("out.png", 120, 25)
ATTACH( Mainwin, My_entry, 20, 50 )
My_entrylabel = MARK( "Name of output file ", 300, 30 )
ATTACH( Mainwin, My_entrylabel, -60, 20 )
'======================
'---edit box
'======================
EDIT_BOX = EDIT(410, 90)
ATTACH( Mainwin, EDIT_BOX, 20, 130 )
'======================
'---button
'======================
My_btn = STOCK("gtk-apply", 80, 25)
ATTACH( Mainwin, My_btn, 230, 20 )
CALLBACK( My_btn, TEXT_OUT)
'======================
'---button
'======================
' Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 345, 20 )
' Make button do something
CALLBACK( My_chk, QUIT)
'======================
'---combo box static
'======================
Menu_label = MARK("The text color " , 220, 30)
ATTACH( Mainwin, Menu_label, 10, 240 )
My_combobox = COMBO("black", 180, 30)
TEXT(My_combobox ,"blue" )
TEXT(My_combobox ,"green" )
TEXT(My_combobox ,"red" )
TEXT(My_combobox ,"yellow" )
TEXT(My_combobox ,"brown" )
TEXT(My_combobox ,"grey" )
TEXT(My_combobox ,"cyan" )
TEXT(My_combobox ,"orange" )
TEXT(My_combobox ,"white" )
ATTACH( Mainwin, My_combobox, 250, 240 )
CALLBACK(My_combobox, My_combobox_demo)
'======================
'---combo box static 2
'======================
Menu_label2 = MARK("The background color" , 220, 30)
ATTACH( Mainwin, Menu_label2, 10, 280 )
My_combobox2 = COMBO("transparent", 180, 30)
TEXT(My_combobox2 ,"black" )
TEXT(My_combobox2 ,"blue" )
TEXT(My_combobox2 ,"green" )
TEXT(My_combobox2 ,"yellow" )
TEXT(My_combobox2 ,"red" )
TEXT(My_combobox2 ,"brown" )
TEXT(My_combobox2 ,"grey" )
TEXT(My_combobox2 ,"cyan" )
TEXT(My_combobox2 ,"orange" )
TEXT(My_combobox2 ,"white" )
ATTACH( Mainwin, My_combobox2, 250, 280 )
CALLBACK(My_combobox2, My_combobox_demo2)
'======================
'---combo box static 3
'======================
Menu_label3 = MARK("Set font " , 220, 30)
ATTACH( Mainwin, Menu_label3, 10, 320 )
My_combobox3 = COMBO("DejaVuSans", 180, 30)
TEXT(My_combobox3 ,"DejaVuSans-Bold" )
TEXT(My_combobox3 ,"DejaVuSans-Oblique" )
TEXT(My_combobox3 ,"DejaVuSans-BoldOblique" )
TEXT(My_combobox3 ,"DejaVuSansCondensed-BoldOblique" )
TEXT(My_combobox3 ,"DejaVuSansCondensed-Bold" )
TEXT(My_combobox3 ,"DejaVuSansCondensed-Oblique" )
TEXT(My_combobox3 ,"DejaVuSansCondensed" )
TEXT(My_combobox3 ,"DejaVuSans-ExtraLight" )
TEXT(My_combobox3 ,"DejaVuSansMono-BoldOblique" )
TEXT(My_combobox3 ,"DejaVuSansMono-Bold" )
TEXT(My_combobox3 ,"DejaVuSansMono-Oblique" )
TEXT(My_combobox3 ,"DejaVuSansMono" )
TEXT(My_combobox3 ,"DejaVuSerif-BoldItalic" )
TEXT(My_combobox3 ,"DejaVuSerif-Bold" )
TEXT(My_combobox3 ,"DejaVuSerifCondensed-BoldItalic" )
TEXT(My_combobox3 ,"DejaVuSerifCondensed-Bold" )
TEXT(My_combobox3 ,"DejaVuSerifCondensed-Italic" )
TEXT(My_combobox3 ,"DejaVuSerifCondensed" )
TEXT(My_combobox3 ,"DejaVuSerif-Italic" )
TEXT(My_combobox3 ,"DejaVuS" )
ATTACH( Mainwin, My_combobox3, 250, 320 )
CALLBACK(My_combobox3, My_combobox_demo3)
'======================
'---combo box static 4
'======================
Menu_label4 = MARK("The dpi size of fonts " , 220, 30)
ATTACH( Mainwin, Menu_label4, 10, 360 )
My_combobox4 = COMBO("72", 180, 30)
TEXT(My_combobox4 ,"96" )
TEXT(My_combobox4 ,"150" )
TEXT(My_combobox4 ,"175" )
TEXT(My_combobox4 ,"200" )
TEXT(My_combobox4 ,"225" )
TEXT(My_combobox4 ,"250" )
TEXT(My_combobox4 ,"300" )
TEXT(My_combobox4 ,"325" )
TEXT(My_combobox4 ,"350" )
TEXT(My_combobox4 ,"400" )
ATTACH( Mainwin, My_combobox4, 250, 360 )
CALLBACK(My_combobox4, My_combobox_demo4)
DISPLAY
' recent-image2.bac
INCLUDE "hug.bac"
INIT
Mainwin = WINDOW( "BaCon image", 450, 400 )
My_label = MARK( "The numbered values are in HUG syntax X,Y" ,400,30)
' Attach the label to the main window
ATTACH( Mainwin, My_label, 0, 340)
' update with the most recent *.png file
TMP_PNG_NAME$ = CHOP$(EXEC$("ls -t $PWD/*.png | head -1"))
PRINT "TMP_PNG_NAME-->", TMP_PNG_NAME$
'get this out to bash
SETENVIRON "TMP_PNG_NAME",TMP_PNG_NAME$
' clean file name to just basename
TMP2_PNG_NAME$ = CHOP$(EXEC$("basename $TMP_PNG_NAME"))
PRINT "TMP2_PNG_NAME --> ",TMP2_PNG_NAME$
'get this out to bash
SETENVIRON "TMP2_PNG_NAME",TMP2_PNG_NAME$
'get pixel size
HUG_IMAGE_SIZE$ = CHOP$(EXEC$("file $TMP_PNG_NAME | cut -f2 -d','| sed 's/ x /,/g'"))
PRINT HUG_IMAGE_SIZE$
'put pixel size x in arrary 0 and pixel size y in array 1
SPLIT HUG_IMAGE_SIZE$ BY "," TO cords$ SIZE dim
PRINT cords$[0]
PRINT cords$[1]
The_image_ = IMAGE(TMP_PNG_NAME$, VAL(cords$[0]), VAL(cords$[1]))
ATTACH( Mainwin, The_image_, 0, 0)
together_again$ = CONCAT$("Your image size in pixels is --> ",HUG_IMAGE_SIZE$)
My_label = MARK( together_again$ ,400,30)
' Attach the label to the main window
ATTACH( Mainwin, My_label, 0, 320)
'--- BUTTON ---
Close_btn = STOCK("gtk-close", 100, 25)
ATTACH(Mainwin, Close_btn, 320, 365)
CALLBACK(Close_btn, QUIT)
DISPLAY