BeBits > TableOfContents > Info > ScriptingBeos
Python is an interpreted, object-oriented programming language, that has gained popularity because of its clear syntax and readability. Python is said to be relatively easy to learn, portable and open source. Python was created by Guido van Rossum.
An interesting feature of Python is its indenting of source statements to make the code easier to read. Python offers dynamic data type, ready-made class, and interfaces to many system calls and libraries. It can be extended, using the C or C++ language.
Python Hello World example with Bethon:
#!/boot/home/config/bin/python
# Import Various components form the Be API
import BApplication
from BWindow import BWindow
from BStringView import BStringView
from BFont import be_bold_font
from InterfaceKit import *
from AppKit import *
class MainWindow:
def __init__(self):
#Main Window
self.this = BWindow((100, 80, 480, 100), 'Hello World!', B_TITLED_WINDOW, B_NOT_RESIZABLE)
self.this.bind(self)
#get the Rect of the main window
rect = self.this.Bounds()
#unpack the Rect into 4 individual variables...left, top, right, bottom
l, t, r, b = rect
# Setup BStringView
self.text = BStringView(rect, 'text', 'Look at me! I am a fancy BeOS programmer!', B_FOLLOW_ALL, B_WILL_DRAW)
# Set font parameters
self.text.SetFont(be_bold_font)
self.text.SetFontSize(18.0)
# Add the stringview to the main window
self.this.AddChild(self.text)
def QuitRequested(self):
BApplication.be_app.PostMessage(B_QUIT_REQUESTED)
return 1
# Setup main app that gets called
class MainApp:
def __init__(self):
self.this = BApplication.BApplication("application/x-vnd.Cube-HelloWorldTest")
self.this.bind(self)
def ReadyToRun(self):
window = MainWindow()
window.this.Show()
# the code that runs first
HelloWorldApp = MainApp()
HelloWorldApp.this.Run()
Links:
Homepage
Python Applications on BeOS
BitTorrent - file distribution system
Hermod - jabber instant messaging
Horus - irc bot
PGPforBeMail - easily use PGP with BeMail
PyShare2 - Beshare peer to peer network
e.t.c.