Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import toga
- import toga_android
- from toga.style import Pack
- from toga.style.pack import COLUMN, LEFT, RIGHT
- class FileScannerApp(toga.App):
- def file_picker_handler(self, widget):
- # Open a file picker dialog to choose the directory
- selected_directory = self.main_window.select_folder_dialog('Select a directory')
- if selected_directory:
- # Scan the selected directory and display the list of files
- files = os.listdir(selected_directory)
- self.file_list.data = [(os.path.basename(file),) for file in files]
- def startup(self):
- # Create a main window
- self.main_window = toga.MainWindow(title=self.name)
- # Create a button to open the file picker
- file_picker_button = toga.Button('Pick a Directory', on_press=self.file_picker_handler)
- # Create a data table to display the list of files
- self.file_list = toga.Table(headings=['File Name'], style=Pack(flex=1))
- # Add the button and data table to the main window
- self.main_window.content = toga.Box(children=[file_picker_button, self.file_list], style=Pack(direction=COLUMN))
- # Show the main window
- self.main_window.show()
- def main():
- return FileScannerApp('File Scanner', 'org.pyqt.filescanner')
- if __name__ == '__main__':
- app = main()
- toga_android.AndroidApp(app)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement