Update Gui testing
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env python3.5
|
||||
|
||||
# You are free to use and/or change this code for
|
||||
# your own needs.
|
||||
|
||||
# Original code (c)2018 Jan Lerking
|
||||
# Program to convert C-header (*.h) files to nasm include files (*.inc),
|
||||
# for direct usage in assembly programming using nasm/yasm.
|
||||
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
class FileChooserWindow(Gtk.Window):
|
||||
|
||||
def __init__(self):
|
||||
Gtk.Window.__init__(self, title="FileChooser Example")
|
||||
|
||||
box = Gtk.Box(spacing=6)
|
||||
self.add(box)
|
||||
|
||||
button1 = Gtk.Button("Choose File")
|
||||
button1.connect("clicked", self.on_file_clicked)
|
||||
box.add(button1)
|
||||
|
||||
button2 = Gtk.Button("Choose Folder")
|
||||
button2.connect("clicked", self.on_folder_clicked)
|
||||
box.add(button2)
|
||||
|
||||
def on_file_clicked(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Please choose a file", self,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||
|
||||
self.add_filters(dialog)
|
||||
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
print("Open clicked")
|
||||
print("File selected: " + dialog.get_filename())
|
||||
elif response == Gtk.ResponseType.CANCEL:
|
||||
print("Cancel clicked")
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
def add_filters(self, dialog):
|
||||
filter_text = Gtk.FileFilter()
|
||||
filter_text.set_name("Text files")
|
||||
filter_text.add_mime_type("text/plain")
|
||||
dialog.add_filter(filter_text)
|
||||
|
||||
filter_py = Gtk.FileFilter()
|
||||
filter_py.set_name("Python files")
|
||||
filter_py.add_mime_type("text/x-python")
|
||||
dialog.add_filter(filter_py)
|
||||
|
||||
filter_any = Gtk.FileFilter()
|
||||
filter_any.set_name("Any files")
|
||||
filter_any.add_pattern("*")
|
||||
dialog.add_filter(filter_any)
|
||||
|
||||
def on_folder_clicked(self, widget):
|
||||
dialog = Gtk.FileChooserDialog("Please choose a folder", self,
|
||||
Gtk.FileChooserAction.SELECT_FOLDER,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
"Select", Gtk.ResponseType.OK))
|
||||
dialog.set_default_size(800, 400)
|
||||
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
print("Select clicked")
|
||||
print("Folder selected: " + dialog.get_filename())
|
||||
elif response == Gtk.ResponseType.CANCEL:
|
||||
print("Cancel clicked")
|
||||
|
||||
dialog.destroy()
|
||||
|
||||
win = FileChooserWindow()
|
||||
win.connect("delete-event", Gtk.main_quit)
|
||||
win.show_all()
|
||||
Gtk.main()
|
||||
Reference in New Issue
Block a user