diff --git a/README.md b/README.md index 41f750e..5f821c0 100644 --- a/README.md +++ b/README.md @@ -9,28 +9,24 @@ where we have had to deviate from the C++ API, however. ## Current status -Currently, Haiku-PyAPI is best suited to scripts and small, simple -applications. +Virtually everything from Haiku's API is available. It is likely that you will +run into some bugs if you try to make an application. Please report them! Also, +there's a good chance we can give you a workaround to use until it is fixed. -Almost everything in the app and interface kits have been ported. The storage -kit has mostly been ported. The support kit has only partially been ported. -The other kits haven't been ported yet. - -Of the kits that have been ported, many of the functions haven't been tested -yet. You should, therefore, expect to encounter problems occasionally. Besides -this, you can expect memory leaks, as little work has been done on getting -memory freed correctly once it is no longer needed. +Probably, the biggest bug is memory leaks. Unless memory management for a class +was simple for us to do, it is likely that we opted to never free the memory +so that we could worry about memory management later! ## Installing + ### From HaikuPorts + Installation on Haiku is easy, just run + ``` pkgman install haiku_pyapi_python310 ``` -or -``` -pkgman install haiku_pyapi_python39 -``` + If you need the latest widgets and bugfixes, then you should compile from source, see below. ### From source @@ -69,6 +65,12 @@ specify a build parameter, add `-sPARAMETER=VALUE` to the build command line. ## Example projects -This repository contains `test.py`, which is a simple "Hello world" program. -The matching game [BeMatched](https://github.com/coolcoder613eb/BeMatched) -provides another example of the library in use. +This repository contains `example.py`, which is a simple "Hello world" program. +Other examples: +- https://github.com/coolcoder613eb/Bemini +- https://github.com/coolcoder613eb/BeMatched +- https://github.com/tmtfx/HaiQR +- https://github.com/tmtfx/FeedGator +- https://github.com/tmtfx/HTPBZ2 +- https://github.com/tmtfx/HaikuPO +- https://github.com/robante15/Haiku-PyAPI_Examples diff --git a/example.py b/example.py new file mode 100644 index 0000000..3c109ed --- /dev/null +++ b/example.py @@ -0,0 +1,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() diff --git a/test.py b/test.py deleted file mode 100644 index 22502cf..0000000 --- a/test.py +++ /dev/null @@ -1,36 +0,0 @@ -from Be import BApplication, BWindow, BRect, BMessage, BView, BButton, window_type, B_NOT_RESIZABLE, B_QUIT_ON_WINDOW_CLOSE - -class Window(BWindow): - def __init__(self): - BWindow.__init__(self, BRect(100,100,200,150), "Hello Haiku!", window_type.B_TITLED_WINDOW, B_NOT_RESIZABLE | B_QUIT_ON_WINDOW_CLOSE) - self.say_hi = BMessage(1) - self.panel = BView(self.Bounds(), "panel", 8, 20000000) - self.button = BButton(self.panel.Bounds(), "hi", "Say Hello!", self.say_hi) #BRect(10,10,100,50) - self.panel.AddChild(self.button, None) - self.AddChild(self.panel, None) - - def MessageReceived(self, msg): - if msg.what == self.say_hi.what: - print("Hello World!") - else: - BWindow.MessageReceived(self, msg) - - def QuitRequested(self): - print("PyQUIT") - return True - -class App(BApplication): - def __init__(self): - BApplication.__init__(self, "application/x-python") - def ReadyToRun(self): - self.window = Window() - self.window.Show() - -def main(): - global be_app - be_app = App() - be_app.Run() - print('Ran') - -if __name__ == "__main__": - main() diff --git a/fstest.py b/tests/filesystem.py similarity index 100% rename from fstest.py rename to tests/filesystem.py diff --git a/tmtest.py b/tests/interfaceKit.py similarity index 100% rename from tmtest.py rename to tests/interfaceKit.py