Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1b5a1f

Browse files
committed
Improve example program
* Rename test.py to example.py* Rewrite itAlso move and rename tmtest.py and fstest.py
1 parent19f56f0 commitf1b5a1f

File tree

5 files changed

+51
-37
lines changed

5 files changed

+51
-37
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ specify a build parameter, add `-sPARAMETER=VALUE` to the build command line.
6565

6666
##Example projects
6767

68-
This repository contains`test.py`, which is a simple "Hello world" program.
68+
This repository contains`example.py`, which is a simple "Hello world" program.
6969
Other examples:
7070
-https://github.com/coolcoder613eb/Bemini
7171
-https://github.com/coolcoder613eb/BeMatched

‎example.py‎

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

‎test.py‎

Lines changed: 0 additions & 36 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp