MyWindow.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # MyWindow.py
  5. #
  6. # MIT License
  7. # Copyright 2022 Stephen Stengel <stephen.stengel@cwu.edu>
  8. #
  9. #The class for creating the window.
  10. import gi
  11. gi.require_version("Gtk", "3.0")
  12. from gi.repository import Gtk
  13. from Handlers import Handlers
  14. class MyWindow(Gtk.Window):
  15. def __init__(self):
  16. super().__init__(title = "RAVE TIME!")
  17. builder = Gtk.Builder()
  18. builder.add_from_file("glade-button.glade")
  19. jigglypuff = builder.get_object("Jigglypuff")
  20. start_button = builder.get_object("music_start")
  21. start_button.set_label("Play the music!")
  22. stop_button = builder.get_object("music_stop")
  23. stop_button.set_label("Stop the music!")
  24. stop_button.set_sensitive(False)
  25. rave_button = builder.get_object("rave_button")
  26. rave_button.set_label("Change color!")
  27. label1 = builder.get_object("label1")
  28. window = builder.get_object("myWindow")
  29. window.connect("destroy", Handlers.myDestroy)
  30. window.connect("destroy", Gtk.main_quit)
  31. myHandlers = Handlers(jigglypuff, stop_button, label1, window)
  32. builder.connect_signals(myHandlers)
  33. window.show_all()
  34. #this code taken from here:
  35. # ~ https://stackoverflow.com/questions/29979957/how-to-make-filename-path-from-gtk-python-3-4-filechooserdialog-accessible-gl
  36. #I'll make my own later
  37. class FileChooser():
  38. def __init__(self):
  39. #Stores your path
  40. self.path = None
  41. dia = Gtk.FileChooserDialog("Please choose a file", None,
  42. Gtk.FileChooserAction.OPEN,
  43. (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
  44. Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
  45. self.add_filters(dia)
  46. response = dia.run()
  47. if response == Gtk.ResponseType.OK:
  48. print("Open clicked")
  49. print("File selected: " + dia.get_filename())
  50. self.path = dia.get_filename()
  51. elif response == Gtk.ResponseType.CANCEL:
  52. print("Cancel clicked")
  53. dia.destroy()
  54. def add_filters(self, dia):
  55. filter_any = Gtk.FileFilter()
  56. filter_any.set_name("Any files")
  57. filter_any.add_pattern("*")
  58. dia.add_filter(filter_any)
  59. filter_text = Gtk.FileFilter()
  60. filter_text.set_name('Text files')
  61. filter_text.add_mime_type('text/plain')
  62. dia.add_filter(filter_text)
  63. filter_py = Gtk.FileFilter()
  64. filter_py.set_name('Python files')
  65. filter_py.add_mime_type('text/x-python')
  66. dia.add_filter(filter_py)
  67. filter_img = Gtk.FileFilter()
  68. filter_img.set_name('Image')
  69. filter_img.add_mime_type('image/*')
  70. dia.add_filter(filter_img)