diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2023-01-22 02:02:13 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2023-01-22 02:02:13 +0100 |
commit | 86480e58eafc1fa3486e03155ed34e02b4595a24 (patch) | |
tree | 0e8f64c4003ea558e946b7a3347688904b451635 /lib/kross/python/scripts/gui.py | |
parent | 135d005014a1e85295af4e379f026a361537ae5f (diff) | |
download | koffice-86480e58eafc1fa3486e03155ed34e02b4595a24.tar.gz koffice-86480e58eafc1fa3486e03155ed34e02b4595a24.zip |
Drop python2 support in scripts.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'lib/kross/python/scripts/gui.py')
-rwxr-xr-x | lib/kross/python/scripts/gui.py | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/lib/kross/python/scripts/gui.py b/lib/kross/python/scripts/gui.py index 487a58627..693261dd5 100755 --- a/lib/kross/python/scripts/gui.py +++ b/lib/kross/python/scripts/gui.py @@ -34,8 +34,8 @@ class TkDialog: """ This class is used to wrap Tkinter into a more abstract interface.""" def __init__(self, title): - import Tkinter - self.root = Tkinter.Tk() + import tkinter + self.root = tkinter.Tk() self.root.title(title) self.root.deiconify() @@ -52,42 +52,42 @@ class TkDialog: class Frame(Widget): def __init__(self, dialog, parent): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Frame(parent) + import tkinter + self.widget = tkinter.Frame(parent) self.widget.pack() class Label(Widget): def __init__(self, dialog, parent, caption): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Label(parent, text=caption) - self.widget.pack(side=Tkinter.TOP) + import tkinter + self.widget = tkinter.Label(parent, text=caption) + self.widget.pack(side=tkinter.TOP) class CheckBox(Widget): def __init__(self, dialog, parent, caption, checked = True): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.checkstate = Tkinter.IntVar() + import tkinter + self.checkstate = tkinter.IntVar() self.checkstate.set(checked) - self.widget = Tkinter.Checkbutton(parent, text=caption, variable=self.checkstate) - self.widget.pack(side=Tkinter.TOP) + self.widget = tkinter.Checkbutton(parent, text=caption, variable=self.checkstate) + self.widget.pack(side=tkinter.TOP) def isChecked(self): return self.checkstate.get() class List(Widget): def __init__(self, dialog, parent, caption, items): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter + import tkinter - listframe = Tkinter.Frame(parent) + listframe = tkinter.Frame(parent) listframe.pack() - Tkinter.Label(listframe, text=caption).pack(side=Tkinter.LEFT) + tkinter.Label(listframe, text=caption).pack(side=tkinter.LEFT) self.items = items - self.variable = Tkinter.StringVar() - itemlist = apply(Tkinter.OptionMenu, (listframe, self.variable) + tuple( items )) - itemlist.pack(side=Tkinter.LEFT) + self.variable = tkinter.StringVar() + itemlist = tkinter.OptionMenu(*(listframe, self.variable) + tuple( items )) + itemlist.pack(side=tkinter.LEFT) def get(self): return self.variable.get() def set(self, index): @@ -96,48 +96,48 @@ class TkDialog: class Button(Widget): def __init__(self, dialog, parent, caption, commandmethod): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Button(parent, text=caption, command=self.doCommand) + import tkinter + self.widget = tkinter.Button(parent, text=caption, command=self.doCommand) self.commandmethod = commandmethod - self.widget.pack(side=Tkinter.LEFT) + self.widget.pack(side=tkinter.LEFT) def doCommand(self): try: self.commandmethod() except: #TODO why the heck we arn't able to redirect exceptions? import traceback - import StringIO - fp = StringIO.StringIO() + import io + fp = io.StringIO() traceback.print_exc(file=fp) - import tkMessageBox - tkMessageBox.showerror("Exception", fp.getvalue()) + import tkinter.messagebox + tkinter.messagebox.showerror("Exception", fp.getvalue()) #self.dialog.root.destroy() class Edit(Widget): def __init__(self, dialog, parent, caption, text): #TkDialog.Widget.__init__(self, dialog, parent) - import Tkinter - self.widget = Tkinter.Frame(parent) + import tkinter + self.widget = tkinter.Frame(parent) self.widget.pack() - label = Tkinter.Label(self.widget, text=caption) - label.pack(side=Tkinter.LEFT) - self.entrytext = Tkinter.StringVar() + label = tkinter.Label(self.widget, text=caption) + label.pack(side=tkinter.LEFT) + self.entrytext = tkinter.StringVar() self.entrytext.set(text) - self.entry = Tkinter.Entry(self.widget, width=36, textvariable=self.entrytext) - self.entry.pack(side=Tkinter.LEFT) + self.entry = tkinter.Entry(self.widget, width=36, textvariable=self.entrytext) + self.entry.pack(side=tkinter.LEFT) def get(self): return self.entrytext.get() class FileChooser(Edit): def __init__(self, dialog, parent, caption, initialfile = None, filetypes = None): TkDialog.Edit.__init__(self, dialog, parent, caption, initialfile) - import Tkinter + import tkinter self.initialfile = initialfile self.entrytext.set(initialfile) - btn = Tkinter.Button(self.widget, text="...", command=self.browse) - btn.pack(side=Tkinter.LEFT) + btn = tkinter.Button(self.widget, text="...", command=self.browse) + btn.pack(side=tkinter.LEFT) if filetypes: self.filetypes = filetypes @@ -150,8 +150,8 @@ class TkDialog: d = os.path.dirname(text) or os.path.dirname(self.initialfile) f = os.path.basename(text) or os.path.basename(self.initialfile) - import tkFileDialog - file = tkFileDialog.asksaveasfilename( + import tkinter.filedialog + file = tkinter.filedialog.asksaveasfilename( initialdir=d, initialfile=f, #defaultextension='.html', @@ -167,11 +167,11 @@ class TkDialog: self.caption = str(caption) self.message = str(message) def show(self): - import tkMessageBox + import tkinter.messagebox if self.typename == "okcancel": - return tkMessageBox.askokcancel(self.caption, self.message,icon=tkmessageBox.QESTION) + return tkinter.messagebox.askokcancel(self.caption, self.message,icon=tkmessageBox.QESTION) else: - tkMessageBox.showinfo(self.caption, self.message) + tkinter.messagebox.showinfo(self.caption, self.message) return True def show(self): @@ -276,7 +276,7 @@ class TQtDialog: def browseButtonClicked(self): filtermask = "" import types - if isinstance(self.filetypes, types.TupleType): + if isinstance(self.filetypes, tuple): for ft in self.filetypes: if len(ft) == 1: filtermask += "%s\n" % (ft[0]) @@ -289,12 +289,12 @@ class TQtDialog: filename = None try: - print "TQtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog" + print("TQtDialog.FileChooser.browseButtonClicked() tdefile.KFileDialog") # try to use the tdefile module included in pytde import tdefile filename = tdefile.KFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") except: - print "TQtDialog.FileChooser.browseButtonClicked() qt.TQFileDialog" + print("TQtDialog.FileChooser.browseButtonClicked() qt.TQFileDialog") # fallback to TQt filedialog filename = qt.TQFileDialog.getOpenFileName(self.initialfile, filtermask, self, "Save to file") if filename != None and filename != "": @@ -341,7 +341,7 @@ class TQtDialog: qt.TQApplication.restoreOverrideCursor() def close(self): - print "TQtDialog.close()" + print("TQtDialog.close()") self.dialog.close() #self.dialog.deleteLater() @@ -352,16 +352,16 @@ class Dialog: self.dialog = None try: - print "Trying to import PyTQt..." + print("Trying to import PyTQt...") self.dialog = TQtDialog(title) - print "PyTQt is our toolkit!" + print("PyTQt is our toolkit!") except: try: - print "Failed to import PyTQt. Trying to import TkInter..." + print("Failed to import PyTQt. Trying to import TkInter...") self.dialog = TkDialog(title) - print "Falling back to TkInter as our toolkit!" + print("Falling back to TkInter as our toolkit!") except: - raise "Failed to import GUI-toolkit. Please install the PyTQt or the Tkinter python module." + raise Exception("Failed to import GUI-toolkit. Please install the PyTQt or the Tkinter python module.") self.widget = self.dialog.widget def show(self): |