Is there any real Basic implementation for GTK+ ?

New to FreeBASIC? Post your questions here.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 19, 2015 15:40

I can see now why you had a hard time with Python if you don't like indenting your code! Indenting code to reflect structure is pretty much essential when teaching beginner programmers. All modern programming languages, including various BASICs are highly structured and variable scope is extremely important. Indenting code serves to represent this to programmer visually so he won't get lost or forget.

I strongly recommend you retrain yourself to indent your blocks of code. You'll avoid a lot of pain and suffering. And if you ever want to collaborate with someone else, it's essential to do.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 19, 2015 15:46

marcov wrote:
caseih wrote:(what is BASIC anyway? never been standardized).

https://en.wikipedia.org/wiki/BASIC#Standards

Yes there are a variety of standards over the years. But nothing that defines BASIC like say, C99 defines C. There is very little direct compatibility between interpreters and compilers. There's still no such thing as the OP's idea of "real" BASIC, other than yet another dialect by that name! It does seem, though, that FB is not what he's looking for. When he does find what he's looking for, I suspect he'll come to find the truth of what Tourist Trap has said about the extreme limitations of such a self-contained system.
hedergabor
Posts: 23
Joined: Feb 15, 2013 10:13
Location: Europe
Contact:

Re: Is there any real Basic implementation for GTK+ ?

Postby hedergabor » Nov 20, 2015 11:58

(Mr.) caseih is absolutely right.
BASIC simply a tool which called "Basic" by the developer. For example AutoIt3 is called only 'Basic-like' language, but is rather Basic for my taste than XBasic or VB. I am not contented with this definition, but it is about the truth. For example I would rather call VB only a Basic-like language but not Basic.

I think this topic is off - till the point when someone can present an authentic Basic implementation of GTK+ into native FreeBASIC, or can present a "GTK+ wrapper" into FreeBASIC. - As (Mr.) Tourist Trap wrote : "the gtk lib" .. "wrapped in a module"

(Mr.) caseih wrote :

GTK+ isn't C either. It's just a library with its own powerful architecture and API.


(Mr.) caseih was write, when it is expressed in a simplified manner. I only mentioned 'C libraries' because of the simplified way of explanation. Such libraries are external libraries for C - written in C - , but there are some of them which became as large or as popular for other platforms then C, that they really cannot be called simply external library for C. (Functions and procedures here : Pascal terminology.) For example the FLTK wrapper is so large that I could count about 800 constant names and function names and procedure names altogether
for FLTK in my key file version for the Crimson Editor. Such tool can be almost a real - but not standalone - computer language for my taste.
It made me some contemplations about GTK+.

(Mr.) caseih wrote :

I can see now why you had a hard time with Python if you don't like indenting your code!


Obviously.
I think it is better if I add some notes here :
I wanted the freedom of Basic and was deeply impressed by simple code examples for Python.
Python is almost a Basic-like language. CPython has two difficulties for Basic-lover hobbist, Python is indented language and is case-sensitive. For avoid strict indentation there are some methods for Python, first of all pindent.py
It is theoretically doable that the programmer develop a converter for CPython and for some certain site-packages, so that he can write codes in free indented style and in not case sensitive manner. Obviously it is was fearsome task to write such script with less than 200 hours code writing experience in any language altogether. To get C++ codes for binaries for multiplatform purpose is even more fearsome task for a beginner. (Please think of Nuitka as one of the best solutions recently. Sad story. I think `love for the first look` can be very dangerous .)

I wrote :

I agree that such function names like 'allocate_memory_block' etc. can appear in any language


It was a mistake I did not want to edit promptly. The proper and polite expression is :
many language (not 'any language').
Last edited by hedergabor on Nov 23, 2015 19:41, edited 3 times in total.
RockTheSchock
Posts: 226
Joined: Mar 12, 2006 16:25

Re: Is there any real Basic implementation for GTK+ ?

Postby RockTheSchock » Nov 20, 2015 12:51

I would say Python is the best beginner language because you are forced to indent your code. To write readable source with less errors you need indentation!

There is not the Basic language or the best language. As more advanced programmer you have one prefered language and at least 2-3 additional languages you use for specific things. Maybe you even use them as mix complementing each other.

FreeBasic was developed with QuickBasic compatibility in mind but with the power of C. So it's used similiar to C or to QB. It's not the best language for beginners. But from my experience it's not enough to learn a language. Thats is done within 1-14 days depending on the language. The problem is learn programming and that is taking several months or for some even years.

If you are a genius with iq of 140 well then you can learn it faster. But it's the same as learning chess, the rules(language) take you some days to master the game(programming) up to a decent amateur level takes months or even years of training. If you begin with the right style(formating/structure) it's will be easier later on and you learn faster.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 20, 2015 15:59

I for one would refuse to work with a fellow programmer who refused to indent his code, even if I could auto-indent it. Not indenting code can lead to serious errors (just ask any TA for a programming 101 class), which would been easily avoided by simply indenting the blocks so you can see the structure clearly as you program. I urge you to change your thinking on this particular issue. I went through a similar challenging change in thinking when I transitioned from non-structured BASIC to TurboBASIC and QuickBasic.
Tourist Trap
Posts: 2817
Joined: Jun 02, 2015 16:24

Re: Is there any real Basic implementation for GTK+ ?

Postby Tourist Trap » Nov 20, 2015 16:06

As far as I remember, the only purpose of not indenting is to save space in systems very short in memory, like very old computers. Today that doesn't make too much sense. The way Python is indenting however is quite strong, and I cant imagine how to type everyday code like this, even with an IDE that would automatizes this (sometimes I like shrinking a block in order to reduce its size at screen momently, after it has been debugged). Even if indenting can save some life at debugging, no doubt here.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 20, 2015 16:13

It's a matter of preference, obviously. But I don't see how indenting in Python is any different from a burden point of view than indenting in any language. Typing everyday code is very easy in Python. When blocks are nested deeply it is easy to mess up (though all editors can automatically indent the next line) but deeply nested code is a form of code smell anyway, so that's a sign it's time to simplify, flatten, and refactor. Whitespace indenting is the thing people who don't use Python love to hate, but it's one of the main things that Python programmers love, and it helps make Python more productive than any language I've ever used. It's very close to executable pseudocode. But I digress.
hedergabor
Posts: 23
Joined: Feb 15, 2013 10:13
Location: Europe
Contact:

Re: Is there any real Basic implementation for GTK+ ?

Postby hedergabor » Nov 21, 2015 20:46

I wrote :
I applied some Cairo font codes into a self-made Basic implementation, but that only looks usable with Courier fonts in the main event loop in my program.


I started learning a little bit the xFont library today and accidently found out that I made a big mistake in my opinion about Cairo font. Sorry.
Cairo with Lucida Console can do many sizes and as good as xfont. I think I have to examine the situation. I dropped out many lines from my test program to show this. I think it maybe useful for someone to get ideas about a concept for GTK+ wrapper. (Although I am not sure about this, I am not an expert.)

hamis/igaz = false/true (I had troubles with true/false in some tests, although this code can be work with true/false with no any trouble. I am right for this, so please do not reflect. A simple not too talkative good tutorial for beginners would be needed, I think. This could be a lesson for real FB 0.24 logic.)

I have no more time for this for a while, so good luck !

[code=vb file=Untitled.bas]

' ANSI CP 1250 , CR+LF

' test program for FB 0.24
' tested on Windows XP with gtk+-bundle_2.24.10-20120208

#include once "fbgfx.bi"
#include once "xfont.bi"
#include once "modules/fbwidgets.bas"
#include once "modules/cairotext.bas"

using FB

#define hamis 0
#define igaz not hamis

'---------------------------------
' Declarations
'---------------------------------

const ESC = chr(27)
const ABLAKX = chr(255 , 107)
const RED = rgb(255 , 0 , 0)
const BACKGROUNDCOLOR = rgb(204 , 204 , 204)
const XFONTBACKCOLOR = rgba(204 , 204 , 204 , 255)

dim shared as string billentyu_
dim shared as byte FBbegomb_
common shared as ushort ablakszelesseg_ , ablakmagassag_
dim shared as ubyte sleeptime_

'Cairo and xfont
dim shared as any pointer szovegmezo2_

'xfont
dim shared as xfont.interface xfont_betu
xfont_betu.loadfont "xfonts/lucida_console_25_bold.xf" , 1

'---------------------------------
' Main
'---------------------------------

FBbegomb_ = hamis
ablakszelesseg_= 600
ablakmagassag_ = 400
sleeptime_ = 20

screenres ablakszelesseg_ , ablakmagassag_ , 32 , 1 , GFX_NO_SWITCH , 0
windowtitle "ABLAK 3"
screencontrol SET_WINDOW_POS , 40 , 10

cairocontext ablakszelesseg_ , ablakmagassag_

'xfont :
xfont_betu.backcolor = XFONTBACKCOLOR

paint (0 , 0 ) , BACKGROUNDCOLOR

screenlock

cairofont 45 , "Times New Roman" , normal , bold , 0 , 0 , 255 , 255
cairoprint 50 , 40 , "This is Cairo text"

'Cairo and xfont test
szovegmezo2_ = imagecreate(250 , 40 , BACKGROUNDCOLOR)
if szovegmezo2_ = 0 then print "Error : imagecreate() error ! "

screenunlock
sleep 50 , 1

' main event loop

do

screenlock

FBbegomb_ = button(40 , 70 , 50 , 50 , "widgetgraphics/begomb1.bmp" , _
"widgetgraphics/begomb2.bmp" , "widgetgraphics/begomb3.bmp" , RED)

if FBbegomb_ then

'Cairo test
cairofont 26 , "Lucida Console" , normal , bold , 50 , 140 , 20 , 255
cairoprint 160 , 190 , "Cairo text"

'xfont test
xfont_betu.fontindex = 1
xfont_betu.forecolor = rgba(120 , 10 , 140 , 255)
xfont_betu.drawstring ,"XFont text" , 160 , 240

FBbegomb_ = hamis

else

'Cairo test
put (160 , 150) , szovegmezo2_ , trans

'xfont test
put (160 , 240) , szovegmezo2_ , trans

endif

screenunlock
sleep sleeptime_ , 1

billentyu_ = inkey
loop until billentyu_ = ESC or billentyu_ = ABLAKX

imagedestroy szovegmezo2_

cairodestroy

end

[/code]

modules/cairotext.bas


[code=vb file=Untitled.bas]

' ANSI CP 1250 , CR+LF

#include once "cairo/cairo.bi"

const normal = 1
const italic = 2
const oblique = 3
const bold = 4


dim shared as any pointer cairofelszin_ , cairorajz_
dim shared as any pointer keppuffer_

declare sub cairocontext(windowwidth_ as ushort , windowheight_ as ushort)

declare sub cairofont(as ubyte , as string , as ubyte , _
as ubyte , as ubyte , as ubyte , as ubyte , as ubyte)

declare sub cairoprint(as ushort , as ushort , as string)
declare sub cairodestroy

'---------------------------------------------------------------

'cairocontext : it has to be placed after (below) screenres
'(because screenptr has to have /proper/ value here below)

sub cairocontext(windowwidth_ as ushort , windowheight_ as ushort)

dim as any pointer keppuffer_

keppuffer_ = screenptr

cairofelszin_ = cairo_image_surface_create_for_data(keppuffer_ , _
CAIRO_FORMAT_ARGB32 , windowwidth_ , windowheight_ , _
windowwidth_*sizeof(integer))

cairorajz_ = cairo_create(cairofelszin_)

cairo_set_source_rgba(cairorajz_ , 0 , 0 , 0 , 0)
cairo_paint(cairorajz_)

end sub


sub cairofont(size_ as ubyte , family_ as string , slant_ as ubyte , _
weight_ as ubyte , red_ as ubyte , green_ as ubyte , blue_ as ubyte , _
alpha_ as ubyte)

dim as single piros_ , zold_ , kek_ , alfa_
dim as ubyte fontslant_ , fontweight_

piros_ = 0 : zold_ = 0 : kek_ = 0 : alfa_ = 0
fontslant_ = 0 : fontweight_ = 0

piros_ = int(1000*red_/255)/1000
zold_ = int(1000*green_/255)/1000
kek_ = int(1000*blue_/255)/1000
alfa_ = int(1000*alpha_/255)/1000

if slant_ < 1 or slant_ > 3 then
fontslant_ = CAIRO_FONT_SLANT_NORMAL
elseif slant_ = normal then
fontslant_ = CAIRO_FONT_SLANT_NORMAL
elseif slant_ = italic then
fontslant_ = CAIRO_FONT_SLANT_ITALIC
elseif slant_ = oblique then
fontslant_ = CAIRO_FONT_SLANT_OBLIQUE
else
fontslant_ = CAIRO_FONT_SLANT_NORMAL
endif

if weight_ = bold then
fontweight_ = CAIRO_FONT_WEIGHT_BOLD
elseif weight_ = normal then
fontweight_ = CAIRO_FONT_WEIGHT_NORMAL
else
fontweight_ = CAIRO_FONT_WEIGHT_NORMAL
endif

cairo_set_source_rgba(cairorajz_ , piros_ , zold_ , kek_ , alfa_)
cairo_select_font_face(cairorajz_ , family_ , fontslant_ , fontweight_)
cairo_set_font_size(cairorajz_ , size_)

end sub


sub cairoprint(xpoz_ as ushort , ypoz_ as ushort , szoveg_ as string)
cairo_move_to(cairorajz_ , xpoz_ , ypoz_)
cairo_show_text(cairorajz_ , szoveg_)
end sub

sub cairodestroy
cairo_destroy(cairorajz_)
cairo_surface_destroy(cairofelszin_)
end sub

[/code]

modules/fbwidgets.bas :


[code=vb file=Untitled.bas]

' ANSI CP 1250 , CR+LF

#define hamis 0
#define igaz not hamis

declare function button( as integer , as integer , as integer , as integer , _
as string , as string , as string , as uinteger ) as integer

'-------------------------------------------------

function button( bxpoz_ as integer , bypoz_ as integer , _
height_ as integer , width_ as integer , passive_ as string , _
hover_ as string , active_ as string , backgroundcolour_ as uinteger ) as integer

dim as integer xpoz_ , ypoz_ , button_
dim as integer mousestate_ , buttonstate_
dim as any ptr gomb_

xpoz_ = -2
ypoz_ = -2
button_ = hamis
mousestate_ = -2
buttonstate_ = -2

gomb_ = imagecreate(width_+1 , height_+1 , backgroundcolour_)
mousestate_ = getmouse( xpoz_ , ypoz_ , , buttonstate_ )

if _
bxpoz_ < xpoz_ and xpoz_ < bxpoz_ + width_ _
and _
bypoz_ < ypoz_ and ypoz_ < bypoz_ + height_ _
then

if not ( buttonstate_ = 1 ) then
button_ = hamis
bload hover_ , gomb_
put (bxpoz_ , bypoz_) , gomb_ , trans
endif

if buttonstate_ = 1 then
button_ = igaz
bload active_ , gomb_
put (bxpoz_ , bypoz_) , gomb_ , trans
endif

else
button_ = hamis
bload passive_ , gomb_
put (bxpoz_ , bypoz_) , gomb_ , trans
endif

imagedestroy gomb_
return button_

end function

[/code]
Tourist Trap
Posts: 2817
Joined: Jun 02, 2015 16:24

Re: Is there any real Basic implementation for GTK+ ?

Postby Tourist Trap » Nov 24, 2015 10:07

hedergabor wrote:I have no more time for this for a while, so good luck !

Thanks.

caseih wrote: Whitespace indenting is the thing people who don't use Python love to hate, but it's one of the main things that Python programmers love, and it helps make Python more productive than any language I've ever used.

Just as a little remark that is omitted by most people. Indenting is quite nice... but requires a wide screen! Just look the geishi html tool for code display here at the forum. Take it like a screen, you can see that even perfectly indented, your lines of code will be broken in an uggly manner due to the width limitation. For people using small screens, indentation advantages can be beaten by the crude reality of the display hardware.

At hi-school, if you're offered to use 31'' widescreen monitor, of course indenting in Python would not only be good habit but very fun!
marcov
Posts: 2840
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Is there any real Basic implementation for GTK+ ?

Postby marcov » Nov 24, 2015 10:23

RockTheSchock wrote:I would say Python is the best beginner language because you are forced to indent your code.


I always think language features that are (so) easily enforced by a simple editor modifications are signs of a lacking design.
marcov
Posts: 2840
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Is there any real Basic implementation for GTK+ ?

Postby marcov » Nov 24, 2015 10:24

caseih wrote:Yes there are a variety of standards over the years. But nothing that defines BASIC like say, C99 defines C.


Then say "no active Basic implementation cares about the standard", don't say "there is no standard", which is patently false.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 24, 2015 17:08

Tourist Trap wrote:Just as a little remark that is omitted by most people. Indenting is quite nice... but requires a wide screen!

Why do you say that? On the face of it, that's a bizarre statement. And clearly false. I typically code in a small window with 80 characters of width. Even at 8 characters per tab, that's 9 levels of indenting (7 practically). But besides that, you can make the tab any width you like. I remember back in TurboBASIC days that 2 spaces was not uncommon. The standard indent for Python is 4 spaces. But no matter what size of indent you use, if you are indenting more than a few levels, even with block deliminators, it's hard to follow and code starts to smell. At that point it's time to refactor.

Before the popularity of 16:9 monitors (which I argue is a horrible aspect ratio for most computer tasks), dual monitors was very nice for developing. Now I use just one 16:9 monitor, and I can usually have at least two code windows up side by side.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 24, 2015 17:12

Fair enough, Marcov. I guess everything is a moot point if the OP is looking for "standard BASIC" then. Because I know of no current implementations of any practical value.

By the way am I the only one that hates the way online forums work? With only one-dimensional, chronological ordering, these little forays into philosophy just end up derailing the original conversation, rather than branching into an easily-followed or ignored fork. Compared to threaded USENET or e-mail, I think we've lost something in communities on the modern web.
badidea
Posts: 1897
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Is there any real Basic implementation for GTK+ ?

Postby badidea » Nov 24, 2015 22:02

By the way am I the only one that hates the way online forums work? With only one-dimensional, chronological ordering, these little forays into philosophy just end up derailing the original conversation, rather than branching into an easily-followed or ignored fork. Compared to threaded USENET or e-mail, I think we've lost something in communities on the modern web.

What do you mean with derailing the topic? :-)
Last edited by badidea on Nov 25, 2015 14:27, edited 1 time in total.
caseih
Posts: 1425
Joined: Feb 26, 2007 5:32

Re: Is there any real Basic implementation for GTK+ ?

Postby caseih » Nov 24, 2015 22:32

Yup that's what I did! :)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests