-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.py
50 lines (42 loc) · 1.79 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# There two ways to import Haiku-PyAPI
# First, you can import only the things you need
from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE, int32, B_WILL_DRAW, B_FOLLOW_NONE
# Or import everything!
#from Be import *
# Usage of the API is extremely similar to how it is used in C++
class App(BApplication):
def __init__(self):
BApplication.__init__(
self, # Any call to a constructor requires self as the first parameter
"application/x-vnd.pyapi_test") # Application signature
def ReadyToRun(self):
# Display the main window
window = MainWindow()
window.Show()
class MainWindow(BWindow):
def __init__(self):
BWindow.__init__(
self, # Any call to a constructor requires self as the first parameter
BRect(100,100,200,150), # Window size
"Hello Haiku!", # Window title
window_type.B_TITLED_WINDOW, # Window type
B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) # Flags
# The "Say Hello!" button's message code
self.MSG_SAY_HI = int32(b"syhi")
# The "Say Hello!" button
self.button = BButton(
self.Bounds(), # Button size
"hi", # Internal name of button
"Say Hello!", # Button text
BMessage(self.MSG_SAY_HI)) # Message to send when button is pressed
self.AddChild(self.button, None)
def MessageReceived(self, msg):
if msg.what == self.MSG_SAY_HI:
# The "Say Hello!" button has been pressed!
print("Hello World!")
else:
# We don't know what to do with this message. Pass it on to BWindow
BWindow.MessageReceived(self, msg)
# Let's launch the application!
app = App()
app.Run()