shauns
Junior Member
Posts: 50
|
Post by shauns on Jul 13, 2012 23:35:54 GMT 1
Pango Markup Text Examples:
INCLUDE "hug.bac" INIT Main = WINDOW("Pango Examples", 350, 350)
Label1 = MARK("<b>This is bold.</b>", 330, 20) Label2 = MARK("<i>This is itallic.</i>", 330, 20) Label3 = MARK("<s>This is strikethrough.</s>", 330, 20) Label4 = MARK("<sub>This is subscript.</sub>", 330, 20) Label5 = MARK("<sup>This is superscript.</sup>", 330, 20) Label6 = MARK("<small>This makes the font smaller.</small>", 330, 20) Label7 = MARK("<big>This makes the font larger.</big>", 330, 20) Label8 = MARK("<u>This is underlined text.</u>", 330, 20) Label9 = MARK("<tt>This uses a Monospace font.</tt>", 330, 20) Label10 = MARK("This is normal text UNCHANGED.", 330, 20) Label11 = MARK("<span foreground='blue'>Blue text (single quotes here)!</span>", 330, 20) Label12 = MARK("<span size='x-large'>Extra Large Text</span>", 330, 30) Label13 = MARK("<span font='32' foreground='red'>32 point text.</span>", 330, 40)
ATTACH(Main, Label1, 0, 10) ATTACH(Main, Label2, 0, 30) ATTACH(Main, Label3, 0, 50) ATTACH(Main, Label4, 0, 70) ATTACH(Main, Label5, 0, 90) ATTACH(Main, Label6, 0, 110) ATTACH(Main, Label7, 0, 130) ATTACH(Main, Label8, 0, 150) ATTACH(Main, Label9, 0, 170) ATTACH(Main, Label10, 0, 190) ATTACH(Main, Label11, 0, 210) ATTACH(Main, Label12, 0, 240) ATTACH(Main, Label13, 0, 290) DISPLAY
There is more that you can do here, but you can see the context and if you compile and run it you can see what these look like. That's worth doing because the result looks better than the code.
|
|
|
Post by alexfish on Jul 14, 2012 20:19:00 GMT 1
Nice Example
|
|
|
Post by vovchik on Jul 15, 2012 8:51:05 GMT 1
Dear shauns,
I have been writing pango markup code for years and was always escaping double quotes in span tags. Your example shows that this is totally unnecessary and single quotes suffice. What a nice discovery. It makes for neater code. Also, I discovered - on the basis of your example - that you can do that analogously with double quotes in svg files. Nice work!
With kind regards, vovchik
|
|
shauns
Junior Member
Posts: 50
|
Post by shauns on Jul 15, 2012 11:32:08 GMT 1
Hi Vovchik,
Initially the single quotes were discovered by trial and error, I didn't think to check that they could be escaped. As you imply it's not an aspect of BaCon but if you look at the typical Pango instructions there is some ambiguity.
Although the simple example gives "blue" there are later references to 'condensed', 'semicondensed' and 'normal' etc. So perhaps these are not merely grammatical quotes but actual instances of usage?
So far I haven't been able to persuade button text to embrace the Pango but it's still early days. The lack of actual code examples and the use of grammatical codes to indicate structure (instead of actual use) is always a problem with documentation.
Any thoughts on progress wheels - we don't seem to have one, but at the same time they seem difficult to use, and usually don't work?
|
|
|
Post by alexfish on Jul 15, 2012 12:22:06 GMT 1
Hi Shauns
have done a little Cheat
INCLUDE "hug.bac" INIT FUNCTION set_text txt$=GRAB$(Label13) TEXT(but2,txt$) RETURN TRUE END FUNCTION '------------------------------------------------- ' Main '------------------------------------------------- Main = WINDOW("Pango Examples", 350, 400) but=BUTTON("",350,50) ATTACH(Main,but,0,285) but2=BUTTON("",100,50) ATTACH(Main,but2,10,350) CALLBACK(but,set_text)
Label1 = MARK("<b>This is bold.</b>", 330, 20) Label2 = MARK("<i>This is itallic.</i>", 330, 20) Label3 = MARK("<s>This is strikethrough.</s>", 330, 20) Label4 = MARK("<sub>This is subscript.</sub>", 330, 20) Label5 = MARK("<sup>This is superscript.</sup>", 330, 20) Label6 = MARK("<small>This makes the font smaller.</small>", 330, 20) Label7 = MARK("<big>This makes the font larger.</big>", 330, 20) Label8 = MARK("<u>This is underlined text.</u>", 330, 20) Label9 = MARK("<tt>This uses a Monospace font.</tt>", 330, 20) Label10 = MARK("This is normal text UNCHANGED.", 330, 20) Label11 = MARK("<span foreground='blue'>Blue text (single quotes here)!</span>", 330, 20) Label12 = MARK("<span size='x-large'>Extra Large Text</span>", 330, 30) Label13 = MARK("<span font='32' foreground='red'>CLICK ME.</span>", 330, 40)
ATTACH(Main, Label1, 0, 10) ATTACH(Main, Label2, 0, 30) ATTACH(Main, Label3, 0, 50) ATTACH(Main, Label4, 0, 70) ATTACH(Main, Label5, 0, 90) ATTACH(Main, Label6, 0, 110) ATTACH(Main, Label7, 0, 130) ATTACH(Main, Label8, 0, 150) ATTACH(Main, Label9, 0, 170) ATTACH(Main, Label10, 0, 190) ATTACH(Main, Label11, 0, 210) ATTACH(Main, Label12, 0, 240) ATTACH(Main, Label13, 0, 290) DISPLAY
|
|
|
Post by vovchik on Jul 15, 2012 13:09:36 GMT 1
Dear Alex, Another nice discovery:) Thanks. We can change button fonts in other ways, I know, but this is also very useful. All this reminds me of the way Goodyear supposedly discovered vulcanization - by error and experiment. And a valuable result. Let's keep experimenting. With kind regards, vovchik @ shauns: Your last thoughts on progress wheels may be right. I used to work as a diplomat - for years - and the self-serving, pencil-pushing idiots in Personnel (now Human Resources, of course) at one point introduced management by objectives and performance assessments on that basis. How can you, in a diplomatic outfit and outposted to a war zone, attempt to create rational management objectives when the object of interest is fluid and changing (and half the time you are trying to determine what the real situation actually is)? OK, BaCon is not a "war zone", but...
|
|
|
Post by alexfish on Jul 15, 2012 14:50:47 GMT 1
|
|
|
Post by vovchik on Jul 15, 2012 15:03:52 GMT 1
Dear Alex,
How about:
' ------------------ FUNCTION EVENT_LABEL(STRING hug_text$, int hug_xsize, int hug_ysize) ' ------------------ LOCAL label, ebox ' myframe = gtk_frame_new(0) label = gtk_label_new(NULL) gtk_label_set_markup(label, hug_text$) 'hug_text$ = gtk_label_get_text(hug_widget) ebox = gtk_event_box_new() ' add label to event box gtk_container_add(ebox, label) gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0) IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox) END IF hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_signal(STR$(ebox)) = 4 hug_widget_type$(STR$(ebox)) = "mark" RETURN ebox END FUNCTION
The bad thing is that you cannot update with TEXT(), but I think we can fix that.
With kind regards, vovchik
|
|
|
Post by alexfish on Jul 15, 2012 16:41:19 GMT 1
worth try all REM~~~~~EVENT_LABEL~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FUNCTION EVENT_LABEL (STRING hug_text$, int hug_xsize, int hug_ysize)
LOCAL label,ebox
label = gtk_label_new(NULL) ebox = gtk_event_box_new() '@ set Hard Coded 'gtk_label_set_markup(label, "<span font='32' foreground='red'>CLICK ME.</span>") '@ argv coded gtk_label_set_markup(label, hug_text$) gtk_container_add(ebox, label) '@ Try these 'gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) 'g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) 'g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 0, 0, 0) 'g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) 'g_signal_connect_data(ebox, "scroll-event", hug_mouse_event, 10, 0, G_CONNECT_AFTER) 'g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0) IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox)
hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_signal(STR$(ebox)) = 4 hug_widget_type$(STR$(ebox)) = "label" RETURN ebox
END FUNCTION
REM-------------------------------------------------------------------------- a snipet of code FUNCTION Label_Click PRINT "OK" RETURN TRUE END FUNCTION win=WINDOW("test",400,400) event_label_1=EVENT_LABEL("<span font='32' foreground='red'>CLICK ME.</span>", 330, 40) 'event_label_1=MARK("test", 330, 40) ATTACH(win,event_label_1,10,10) CALLBACK(event_label_1,Label_Click) regards alexfish ADDED: @ any one interested Just had a thought possible to make Code completion for the rad tool
|
|
shauns
Junior Member
Posts: 50
|
Post by shauns on Jul 16, 2012 21:38:20 GMT 1
Hi Vovchik & Alex,
The progress wheels that I was thinking of were really those of REALStudio/REALBasic. They argue that given threads it could work, but in practice never does. However with regard to HR, and I hate them just as much - being unemployed, let me ask: If you only have 1 HR guy how can he or she ever get the sack? They'd never do the paper work.
Alex... I not too smart so didn't entirely understand your example. Correct me if I'm wrong and explain some more. So, if I put a MARK in the same place as a button, it would tend to look as though the text of the MARK was on the button. So then the button could have no text "" but the MARK would be superimposed upon it?
If that's how it is, are there any downsides? Is the text of the MARK always on top? If I have a CANVAS and place it on a MARK, which will be on top (I haven't tried this yet)? Another thing, the window background follows the theme, but the CANVAS background is white. The theme on X11 Mac is different to CentOS linux which follows what I picked as the appearance. How do I get the CANVAS to invisibly match the window? Or perhaps just fill the window with the CANVAS?
Much more experimenting to do I guess.
|
|
|
Post by vovchik on Jul 16, 2012 23:03:43 GMT 1
Dear shauns, I did a spinner - which must be the same as a progress wheel. Some people call it a throbber (usually in browser-speak).: INCLUDE "../hug.bac", INIT, WINDOW, BUTTON, HUGLIB$, HUGOPTIONS, METHOD, REGISTER, \ SET, ATTACH, CALLBACK, QUIT, DISPLAY
' *********************** ' END INCLUDES ' ***********************
' *********************** ' DECLARATIONS ' ***********************
CONST gtk$ = HUGLIB$("gtk") INIT HUGOPTIONS("BASEXFTDPI 96")
' *********************** ' END DECLARATIONS ' ***********************
' *********************** ' IMPORTS ' ***********************
' ------------------ ' 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
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB SPIN_SET(NUMBER hug_widget, int value) ' ------------------ ' self-defined method for SET IF value THEN gtk_spinner_start(hug_widget) ELSE gtk_spinner_stop(hug_widget) END IF END SUB
' ------------------ FUNCTION SPINNER(int hug_xsize, int hug_ysize) ' ------------------ ' create spinner widget for HUG LOCAL widget ' define the spinner widget 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
' ------------------ 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() ' ------------------ 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(start, "tooltip-text", "Start spinner") PROPERTY(stop, "tooltip-text", "Stop spinner") PROPERTY(myquit, "tooltip-text", "Exit program") ATTACH(win, start, 10, 10) ATTACH(win, stop, 140, 10) ATTACH(win, spinner, 97, 14) ATTACH(win, myquit, 140, 170) CALLBACK(start, SPIN_START) CALLBACK(stop, SPIN_STOP) CALLBACK(myquit, QUIT) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
Joe also did a nice demo of the progress bar his "mental math of GUI placement" tutorial. Those are the main activity indicators in GTK. If the progress wheel is different in REALBasic, it could probably be cloned by creating a new widget using GTK primitives. At first I thought you meant "progress wheel" was some kind of groupware progress tracking system for coders. That is why I ranted about HR. In my former line of work there were often committees organized to drafting reports, statements, resolutions and the like. In that connection, some of us not that keen on coercive collaboration would comment that "a camel is a horse designed by a committee". With kind regards, vovchik
|
|
|
Post by alexfish on Jul 16, 2012 23:45:53 GMT 1
@ shauns you are correct about the label over button, it be a cheat but it does work to set pango text intro 'background' colour background ='red' there are examples of canvas examples on the forum ,best to search , it part of the learning also realise the is a strong link in colours RE pango and the actual widgets, + canvas , think X11 window , pixels and mouse. it be early days for a progress wheels post a picky , and see what we can do , nothing is impossible , and never say never , well just sometimes Also thought about a RGB colour chooser , this may help you understand Does it look like a button ? see Attachments regards all Alex Attachments:
|
|
|
Post by alexfish on Jul 16, 2012 23:55:37 GMT 1
Hi All
The above is a R G B colour chooser , easy to use , also part of the rad tool.
As part of an exerciser place a MARK over the Colour , as from the samples done by Shauns
also intro some background colour.
Have Fun
alexfish
Need to ADD
SYNC just above the
PICTURE(<argv's>)
|
|
|
Post by alexfish on Jul 17, 2012 5:20:03 GMT 1
An Improved version of RGB colour Have fun Alex Need to change lines at 83 to Oops txt$=CONCAT$("#",h3$,h2$,h1$) TEXT(txt1,txt$) label$=CONCAT$("<span font='",STR$(16),"' foreground='",txt$,"'>32 point text.</span>") TEXT(text2,label$) TEXT(Label_1,label$) read_write_image(600,400,20,20,400,200,r1,r2,r3,190,179,151) Attachments:
|
|
|
Post by alexfish on Jul 17, 2012 11:37:12 GMT 1
Hi all Finally got it working , that Mark (Pango) have reversed , the output , + added text box so can see What is Happening ' -----------------------------------------------------------------------------' PROGRAM: rgbcolour ' PURPOSE: RGB COLOURS :) ' AUTHOR: Alex (alexfish) Bacon Forums ' MODDED: not yet ' DEPENDS: gcc, bacon (1.27), gtk, rsvg, HUG (0.79) ' Version 0.10 ' PLATFORM: Ubuntu Linux (actually, any *nix) ' DATE: 17-07-2012 ' LICENSE: GPL3 ' If it breaks you get to keep both bits ' ------------------------------------------------------------------------------ 'fixed sync 'added #****** syntax for canvas ' This sets the Enviroment ' See the readme.txt ' *********************** DECLARE sys$,env$ CALL ENVIROMENT INCLUDE "hug.bac" INIT FUNCTION ENVIROMENT LOCAL hug_lib$ sys$=CHOP$(EXEC$("uname -a")) env$=CONCAT$(CHOP$(EXEC$("pwd")),"/") CHANGEDIR env$ RETURN TRUE END FUNCTION REM---------------------------------------------------------------------------------------------------
SETENVIRON "OUTPUT_CHARSET", "UTF-8" OPTION INTERNATIONAL TRUE CONST rsvg$ = "librsvg-2.so" gtk$ = HUGLIB$("gtk") gdk$ = HUGLIB$("gdk") HUGOPTIONS("NOSCALING")
IMPORT "rsvg_init()" FROM rsvg$ TYPE void IMPORT "rsvg_term()" FROM rsvg$ TYPE void IMPORT "rsvg_handle_new()" FROM rsvg$ TYPE long IMPORT "rsvg_handle_write(long,char*,long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_close(long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_get_pixbuf(long)" FROM rsvg$ TYPE long
' ------------------ FUNCTION MK_SVG(int width,int height,int x_pos,int y_pos,int rect_x_size,int rect_y_size,int R1,int G1,int B1,int ST_R2,int ST_G2,int ST_B2) ' ------------------
R_Square$=CONCAT$("<svg width='",STR$(width),"' height='",STR$(height),"'> <rect x='",STR$(x_pos),"' y='", STR$(y_pos),"' ry='5' width='",STR$(rect_x_size) ,"' height='", STR$(rect_y_size), "' style='fill:rgb(",STR$(206),",",STR$(199),",",STR$(192), ");stroke-width:",STR$(2),";stroke:rgb(",STR$(ST_R2),",",STR$(ST_G2),",",STR$(ST_B2),")'/> </svg>" ) TRAP LOCAL OPEN "mgimg" FOR WRITING AS myfile WRITELN R_Square$ TO myfile ' CLOSE FILE myfile SYNC PICTURE("mgimg",0,0,600,400) RETURN TRUE END FUNCTION
SUB read_write_image (int width,int height,int x_pos,int y_pos,int rect_x_size,int rect_y_size,int R1,int G1,int B1,int ST_R2,int ST_G2,int ST_B2) R_Square$=CONCAT$("<svg width='",STR$(width),"' height='",STR$(height),"'> <rect x='",STR$(x_pos),"' y='", STR$(y_pos),"' ry='5' width='",STR$(rect_x_size) ,"' height='", STR$(rect_y_size), "' style='fill:rgb(",STR$(R1),",",STR$(G1),",",STR$(B1), ");stroke-width:",STR$(2),";stroke:rgb(",STR$(ST_R2),",",STR$(ST_G2),",",STR$(ST_B2),")'/> </svg>" ) TRAP LOCAL OPEN "mgimg" FOR WRITING AS myfile WRITELN R_Square$ TO myfile ' CLOSE FILE myfile 'OUT("text", "fgcolor", "bgcolor", xposition, yposition) PICTURE("mgimg",0,0,600,400) OUT("Button1", "#000000", "#FFAABB", 180, 115) SYNC END SUB
FUNCTION set_col r1=GET(spin_r1) r2=GET(spin_r2) r3=GET(spin_r3) h1$=HEX$(r1) h2$=HEX$(r2) h3$=HEX$(r3) IF LEN(h1$) = 1 THEN h1$=CONCAT$("0",h1$) IF LEN(h2$) = 1 THEN h2$=CONCAT$("0",h2$) IF LEN(h3$) = 1 THEN h3$=CONCAT$("0",h3$) txt$=CONCAT$("#",h3$,h2$,h1$) txt2$=CONCAT$("#",h1$,h2$,h3$) TEXT(txt1,txt$) TEXT(text3,txt2$) label$=CONCAT$("<span font='",STR$(16),"' foreground='",txt2$,"'>32 point text.</span>") TEXT(text2,label$) TEXT(Label_1,label$) read_write_image(600,400,20,20,400,200,r1,r2,r3,190,179,151) RETURN TRUE
END FUNCTION
' ------------------
win = WINDOW("test", 445, 310) can = CANVAS(445,220) ATTACH(win,can,0,0) spin_r1=SPIN(75,25,0,255,1) ATTACH(win,spin_r1,200,255) CALLBACK(spin_r1,set_col) spin_r2=SPIN(75,25,0,255,1) ATTACH(win,spin_r2,283,255) CALLBACK(spin_r2,set_col) spin_r3=SPIN(75,25,0,255,1) ATTACH(win,spin_r3,365,255) CALLBACK(spin_r3,set_col) txt1=ENTRY("",92,25) ATTACH(win,txt1,100,255) Label_1=MARK("<span font='16' foreground='#000000'>16 point text.</span>", 160, 18) ATTACH(win,Label_1,10,220) text2=ENTRY("",435,25) ATTACH(win,text2,5,280) text3=ENTRY("",92,25) ATTACH(win,text3,200,220) MK_SVG(600,400,20,20,400,200,206,199,192,229,183,167)
DISPLAY
The readme.txt This works from the home environment
you will need to make a folder either in the home directory or your desk top
in this folder place bacongui,hug.bac + this file "rgbcolour.bac"
to open in the environment , browse to the folder , double click on the bacongui
open up the file required, away to go Have Fun Alex PS : can also play around with the canvas text if you want to Mod it
|
|