BaCon Bits

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

BaCon Bits

#1 Post by GatorDog »

.
I started out to learn BaCon programming and the HUG widgets.
Somehow one of the sample programs I started evolved into
this program, pFontSelect. Puppy already has Gfontsel,
which will return the Font and Size. pFontSelect returns
those parameters and also the Style ie. Regular, Italic, etc.
pFontSelect also reports how many fonts are registered
on your system.

Anyway I thought this might be helpful as a reference to
using some of the HUG widgets.

rod

Please download the attachment to view the source and a compiled standalone version of program.

Edits:
Incorporated L19L and volchik suggestions.
Attached zip file of compiled pFontSelect.
--------------
Bumped version to 1.0.1
volchik massaged code into a structured form.
" added code for colored text.

Added routine to save preview text as new default text.
Changed Close button to Apply button.
Attached zip file of both source and binary.
Updated screenshot.
--------------
Updated attachment files, v1.0.3
There are a few cosmetic changes in GUI.
--------------
Changed "medium" to "light" in a gtk font statement.
Bumped to v1.0.4


______________________________________________________________________________

EDIT - More example programs in this thread:
Video-Play

HKP - Hug Keyword Parser

Start of "Hello Bacon (World)"

More Hello Bacon

Even More Hello Bacon

Still more Hello Bacon

Hello Bacon - a complete app

Bacon File I/O

Bacon port of resizepfile "Resize pup save file"
Attachments
pFontselect-1.0.4.tar.gz
pFontselect 1.0.4 source and Standalone compiled program
(58.7 KiB) Downloaded 785 times
pFontSelect.png
pFontSelect
(32.12 KiB) Downloaded 1853 times
Last edited by GatorDog on Thu 03 Nov 2011, 13:27, edited 8 times in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: BaCon Bits

#2 Post by L18L »

GatorDog wrote:I tried attaching the source ".bac" and the compiled prg but the Post editor said "extension not allowed" for both of them.
gzip program
unzipped by clicking :)

Very nice, compiled in 6 seconds
Just 1 comment for now: the buttons need more width (I used to give them 120px)
Thank you
Attachments
pfontselect.png
(4.99 KiB) Downloaded 1967 times

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

Very nice

#3 Post by vovchik »

Dear Rod,

Nice work. My suggestion is to change your font_list$ = EXEC$ line to:

Code: Select all

font_list$ = REPLACE$(EXEC$("fc-list | cut -d':' -f1 | sort | cut -d',' -f1 | uniq"),"\\-","-")
The reason is that "fc-list" will give you an escaped hyphen if the internal ttf name contains a hyphen. The font name will show in the list but the real font won't display (i.e. no real glyphs).

With kind regards,
vovchik

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

#4 Post by GatorDog »

I've incorporated your suggestions in the first post's
code. I used a button width of 100. 120 seemed
a little excessive for those two buttons. Try
that size and see if it is addequate for you.

I don't currently have a font with a hyphen. If you do
you might check that out.

Other than being a tad bit wider to accommodate the
buttons, the app looks the same.

Thanks :wink: L18L and volchik

rod

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

Weird font names

#5 Post by vovchik »

Dear Rod,

You will see why the REPLACE$ mod is needed if you install the attached font (just unpack and copy into HOME$/.fonts). There might be other "escaped chars" generated by fc-list, too, but this is the first one I came upon.

With kind regards,
vovchik
Attachments
N_E_B.TTF.tar.gz
(8.42 KiB) Downloaded 809 times

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#6 Post by L18L »

GatorDog wrote:Try that size and see if it is addequate for you.
Yes, it is :!:

The red and green squares animating the buttons are very nice.

BTW, I have compared pFontSelect to yad --font, gfontselect,...
pFontSelect has the advantage of changing sizes "step 1" :)

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

#7 Post by GatorDog »

I tested pFontSelect on another Linux OS. The app title
in the top frame (not the window title) did not appear.
I checked and that system did not have the "cursor" font
that puppy 525 has. So I changed the title font to a
common one, DejaVu Sans.

The title was still blank, and if I selected the same
combination for font description, the pre-view text
would disappear.

After several hours of hacking I chanced upon this fix.

Code: Select all

junk_label = MARK("", 10, 10)
FONT(junk_label, "DejaVu Sans:Regular 6")
ATTACH(mainwin, junk_label, 0,0)
The construction "Font name COLON Style SPACE size"
ie "Font name:Style N" seems to be the only syntax
that works.

I put it in a SUB called "SUB_sync_font_description"
and call it before printing with any HUG widgets.

The sub addition is incorporated in the program listing
in the first post. And a new binary attached.

To try it, comment out the "SUB_sync_font_description" call.
Compile and run. Select DejaVu Sans Italic 18 and see if
the preview text and the app title both disappear.

rod
Attachments
pFS.png
With and without "font sync" fix
(52.93 KiB) Downloaded 1037 times

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

#8 Post by GatorDog »

A few mods, mostly behind the curtain things.

Bumped version to 1.0.1
volchik massaged code into a structured form.
" added code for colored text.

Added routine to save preview text as new default text.
Changed Close button to Apply button.
Attached zip file of both source and binary.
Updated screenshot.

New pFontSelect.bac in 1st post

rod

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

sample text

#9 Post by L18L »

GatorDog wrote:...
Added routine to save preview text as new default text...
Hi, this looks very very nice!
I am glad that you are thinking about greek, cyrillic ....

There are sample text phrases for some languages and I have played with Spanish, see screenshot.
I suggest you make the text display in more than just 1 line.

The samples are taken from quickbrown.txt see
Markus Kuhn wrote:Sentences that contain all letters commonly used in a language
--------------------------------------------------------------

Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> -- 2007-02-08

This file is UTF-8 encoded.


Danish (da)
---------

Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen
Wolther spillede på xylofon.
(= Quiz contestants were eating strawbery with cream while Wolther
the circus clown played on xylophone.)

German (de)
-----------

Falsches Üben von Xylophonmusik quält jeden größeren Zwerg
(= Wrongful practicing of xylophone music tortures every larger dwarf)

Zwölf Boxkämpfer jagten Eva quer über den Sylter Deich
(= Twelve boxing fighters hunted Eva across the dike of Sylt)

Heizölrückstoßabdämpfung
(= fuel oil recoil absorber)
(jqvwxy missing, but all non-ASCII letters in one word)

Greek (el)
----------

Γαζέες καὶ μυ
Attachments
pfontselect-101.png
(31.78 KiB) Downloaded 1760 times

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

#10 Post by GatorDog »

L18L,

I'll pm you with current .bac file that has a few tweaks I'm working on.

rod

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

pfontselect

#11 Post by L18L »

Thanks,
PMed back
and here is the penguin
:)
Attachments
pfontselect-102.png
(14.01 KiB) Downloaded 1761 times

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

Video-Play

#12 Post by GatorDog »

Video-Play - A BaCon example program.
This program is mainly an example of using the FILEDIALOG file browser.

Features:
- Use the filebrowser to pick the video file to play.
- Edit the Mplayer command line and click "Play" to try it out.
- Clicking "Close" or "Play" saves the edited command line and
filename. They will be reloaded the next time Video-Play is run.
- "Restore Default" restores the original Mplayer command line.
- "Cancel" exit/quit.
These are the filtered filetypes:
avi, AVI, aaf, AAF, amv, AMV, amx, arf, asf, , ASF, asx, avs, AVS
bsf, cpi, d2v, dat, divx DIVX, dmb, dpg, dv-avi, dvdmedia, dvr, dvr-ms
dvx, DVX, f4v, flv, FLV, gvi, gvp, h264, hdmov, ifo, k3g, m2t, m2ts
m2v, m4v, mgv, mjp, mkv, mnv, mod, moov, mov, MOV, mp4, MP4, mpeg
MPEG, mpg, MPT, mpv, msdvd, mts, ogv, pgi, pmf, pva, qt, qtm, rm, rv
swf, SWF, tivo, vid, vob, VOB, vro, webm, wmv, WMV, wtv, xvid, yuv
264, 3gp, 3g2
video-play-sa.tar.gz is compiled standalone app. It should not require devx.sfs
video-play.bac.tar.gz is the BaCon source file.

rod
Attachments
video-play-sa.tar.gz
Compiled app video-play
(42.24 KiB) Downloaded 860 times
video-play.bac.tar.gz
BaCon source for video-play
(2.77 KiB) Downloaded 971 times

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

HKP - Hug Keyword Parser

#13 Post by GatorDog »

This program is an example of using EDITDIALOG, MSGDIALOG & FILEDIALOG.

If you use hug_imports.bac while developing and want the final app
to use hug.bac, keyword_list...

Hug Keyword Parser - Parses a Bacon source.bak file for HUG keywords.
Displays a new INCLUDE "/path/hug.bac", list_of_keywords In an Edit window.
Then you can copy/paste the Include line into your program.

rod

Edit: I'm using BaCon GUI v 1.0.24 / hug.bac v.61+

- Latest Version 2.1 source attached. Added Direct Import statements from hug_imports.bac
Attachments
hkp-2.1.png
(48.61 KiB) Downloaded 1062 times
HKP-HugKeywordParser-2.1.tar.gz
HKP 2.1 Bacon source
(6.57 KiB) Downloaded 782 times
hkp.tar.gz
Hug Keyword Parser source 1.0r1
(4.52 KiB) Downloaded 914 times
Last edited by GatorDog on Thu 03 Nov 2011, 12:34, edited 1 time in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

hug keyword parser

#14 Post by vovchik »

Dear Rod,

Nice job. It is immediately useful. Thanks.

With kind regards,
vovchik

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

#15 Post by sunburnt »

I read in the forum that Barry has included BaCon in Puppy.
I`m running 5.11, which version has it?

I noticed at the BaCon web site a lot of addons, some for GTK+.
BaCon could turn out to be a good replacement for gtkDialog.
# Addendum: Looking at the GTK+ examples, it`s very code intensive.
# A converter needs to be written in BaCon to reduce the required code.

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

#16 Post by GatorDog »

Hi sunburnt,

As far as I know, 511 should have BaCon in the 511 DEVX package.
For starters check out this-
http://bkhome.org/bacon/index.html

I've been using BaCon GUI to edit/compile/run as opposed to the
command line compiler (bacon) and a text editor. The gui is great.

I'm running pup 525. Some of the Bacon in the DEVX is getting a little
crispy. Some of the apps above need the latest bacon related files. I'll
attach the current files.

The DEVX package sets up the Bacon files in /usr/share/BaCon .
Put these files there: hug.bac, hug_imports.bac and hug.so .
You can put bacon and bacongui in you search path. I just made a
bacon directory, put bacon / bacongui in there and do developement
from that directory.

If you put the hug.so in a different directory, you'll need to edit the
top of hug_imports.bac to reflect the different path.

for ref hug.bac / hug.so are v.61 and bacongui 1.0.24beta

bacongui.bac and bacon.bac are the source files. When you have the
DEVX package loaded, compile them with "bacon bacon.bac"
and "bacon bacongui.bac"
# Addendum: Looking at the GTK+ examples, it`s very code intensive.
If your talking about making the cool GUI's, that is what HUG is for (hug.bac etc.)


Hopefully that will get you started.

rod
Attachments
bacon_files.tar.gz
bacon / bacongui 1.0.24beta
hug.bac, hug.so .61
hug_imports.bac current
(167.11 KiB) Downloaded 1021 times

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

#17 Post by sunburnt »

Thanks GatorDog; BaCon has a lot of potential, If it can GUIs without lots of code... Great!

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

Hello Bacon (World)

#18 Post by GatorDog »

sunburnt wrote: BaCon has a lot of potential, If it can GUIs without lots of code... Great!
Here's the classic Hello Bacon (World ;) )

Code: Select all

' BaCon / HUG  Hello World

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

Mainwin = WINDOW( "Hello Title Bar", 250, 100 )

My_label = MARK( "Hello BaCon!", 150, 30 )
ATTACH( Mainwin, My_label, 50, 20 )

My_btn = BUTTON( "I'm done", 80, 25)
ATTACH( Mainwin, My_btn, 85, 60 )

CALLBACK( My_btn, QUIT)

My_chk = CHECK( "Nada", 50, 25 )
ATTACH( Mainwin, My_chk, 175, 60 )

' Make it so! (A little Star Trek lingo :-)
DISPLAY
You start with the main window, then start making widgets.
Use x,y co-ords to place them on the window and away you go.

rod
Attachments
hello_bacon.png
Hello Bacon
(7.36 KiB) Downloaded 1825 times

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

Hello Bacon (World)

#19 Post by GatorDog »

Here is a commented version-

Code: Select all

' BaCon / HUG  Hello World

' Include the files for making a GUI.
INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT

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

' Make a button
My_btn = BUTTON( "I'm done", 80, 25)

' Attach button to window
ATTACH( Mainwin, My_btn, 85, 60 )

' Make button do something
CALLBACK( My_btn, QUIT)

' Create a checkbox widget.
My_chk = CHECK( "Nada", 50, 25 )
ATTACH( Mainwin, My_chk, 175, 60 )

' Make it so! (A little Star Trek lingo :-)
DISPLAY

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

#20 Post by sunburnt »

Thanks GatorDog; Actually your first example was so easy to understand...
The only Q was what the numbers were setting. But that`s obvious.

The window and the control statements have their sizes set.
The ATTACH statements set the screen positions relative to the window.
CALLBACK is the button action and DISPLAY is the whole window action.

The ATTACH statements seem unnecessarily overdone.
A less wordy and typing intensive method:

Code: Select all

My_btn = BUTTON( "I'm done", 80, 25, Mainwin, 85, 60 )
Just specify everything in one statement, less repetition of words.
Words and typing saved: ATTACH, My_btn, and the extra set of ( ).
Nit-picky I know... But I look at things from an engineering view. KISS. :lol:

Q: Apparently a Label is called a MARK? ( My_label = MARK ) Seems so...

This appears to be much closer to the syntax I`ve had in mind.
And BaCon takes this code and produces C executables from it, very nice!
Executables instead of shell scripts to describe and generate GUIs. Great!
The GUIs are bound to be way faster than Bash scrip for sure.

I`ll be taking a serious look at this, I may have more Qs for youGatorDog...

Post Reply