Advertisement
Dynamic_Fantasy

Untitled

Jul 25th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import os
  2. import toga
  3. import toga_android
  4. from toga.style import Pack
  5. from toga.style.pack import COLUMN, LEFT, RIGHT
  6.  
  7.  
  8. class FileScannerApp(toga.App):
  9.  
  10. def file_picker_handler(self, widget):
  11. # Open a file picker dialog to choose the directory
  12. selected_directory = self.main_window.select_folder_dialog('Select a directory')
  13. if selected_directory:
  14. # Scan the selected directory and display the list of files
  15. files = os.listdir(selected_directory)
  16. self.file_list.data = [(os.path.basename(file),) for file in files]
  17.  
  18. def startup(self):
  19. # Create a main window
  20. self.main_window = toga.MainWindow(title=self.name)
  21.  
  22. # Create a button to open the file picker
  23. file_picker_button = toga.Button('Pick a Directory', on_press=self.file_picker_handler)
  24.  
  25. # Create a data table to display the list of files
  26. self.file_list = toga.Table(headings=['File Name'], style=Pack(flex=1))
  27.  
  28. # Add the button and data table to the main window
  29. self.main_window.content = toga.Box(children=[file_picker_button, self.file_list], style=Pack(direction=COLUMN))
  30.  
  31. # Show the main window
  32. self.main_window.show()
  33.  
  34.  
  35. def main():
  36. return FileScannerApp('File Scanner', 'org.pyqt.filescanner')
  37.  
  38.  
  39. if __name__ == '__main__':
  40. app = main()
  41. toga_android.AndroidApp(app)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement