Skip to content

Instantly share code, notes, and snippets.

@Dayof
Last active September 14, 2022 09:14
Show Gist options
  • Save Dayof/c2fc5883c8884d61ca02109dc7944813 to your computer and use it in GitHub Desktop.
Save Dayof/c2fc5883c8884d61ca02109dc7944813 to your computer and use it in GitHub Desktop.
import toga
from colosseum import CSS
class StartApp(toga.App):
def startup(self):
self.main_window = toga.MainWindow(self.name)
self.main_window.app = self
self.outer_box = toga.Box()
all_tests_box = toga.Tree(['Tests'])
problems_box = toga.Tree(['Problems'])
self.notebook = toga.OptionContainer(content=[
('All tests', all_tests_box),
('Problems', problems_box)])
self.button = toga.Button('Print ID', on_press=self.printCurrentID,
style=CSS(margin=50))
self.outer_box.add(self.notebook)
self.outer_box.add(self.button)
self.main_window.content = self.outer_box
self.main_window.show()
def printCurrentID(self, button):
print(self.notebook.selected['id'])
def main():
app = StartApp('ProgressBar Test', 'org.pybee.test')
app.main_loop()
if __name__ == '__main__':
main()
@BrendanSimon
Copy link

BrendanSimon commented Feb 26, 2020

The callback mechanism on_select will pass the selected widget back as the option parameter to the on_select handler. You could maintain a copy of that reference in your own app.

The core OptionContainer widget could also maintain a selected attribute as you have suggested. I have just created a PR for iOS implementation of OptionContainer and I've added the index to the callback handler (as that could be useful to the app developer).

So I could see selected.option and selected.index properties as being easy enough to implement.

@freakboy3742 is this something you would like to see in OptionContainer or would accept if there was a PR for it?

@HK416A5
Copy link

HK416A5 commented Aug 22, 2021

Hello! I want to use the optioinCintainer widget to add tab views to my app, when I type briefcase dev, it works fine on Windows systems, but after I typebriefcase package android, and install it on my android phone and open it, there is nothing appeare on my screen but a title of the app...How could this happen? Is there something wrong? How can I add tab views to my android app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment