pass parent to select folder/file dialog, set icon
This commit is contained in:
parent
7f05b08238
commit
1d52413618
1 changed files with 11 additions and 5 deletions
16
oml/ui.py
16
oml/ui.py
|
@ -1,12 +1,13 @@
|
|||
# encoding: utf-8
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import sys
|
||||
import os
|
||||
try:
|
||||
from gi.repository import Gtk, GObject
|
||||
GObject.threads_init()
|
||||
use_Gtk = True
|
||||
except:
|
||||
from tkinter import Tk
|
||||
from tkinter import Tk, PhotoImage
|
||||
import tkinter.filedialog
|
||||
use_Gtk = False
|
||||
|
||||
|
@ -61,21 +62,26 @@ class GtkUI:
|
|||
print("done")
|
||||
return filename
|
||||
|
||||
|
||||
class TkUI:
|
||||
def __init__(self):
|
||||
self.root = Tk()
|
||||
self.root = Tk(className="Open Media Library")
|
||||
png = os.path.join(os.path.dirname(os.path.abspath('__file__')), 'static', 'png', 'oml.png')
|
||||
icon = PhotoImage(file=png)
|
||||
self.root.tk.call('wm', 'iconphoto', self.root._w, icon)
|
||||
self.root.withdraw() # hiding tkinter window
|
||||
if sys.platform == 'darwin':
|
||||
self.root.lift()
|
||||
self.root.call('wm', 'attributes', '.', '-topmost', True)
|
||||
self.root.update()
|
||||
self.root.after_idle(self.root.call, 'wm', 'attributes', '.', '-topmost', False)
|
||||
self.root.withdraw() # hiding tkinter window
|
||||
|
||||
def selectFolder(self, data):
|
||||
return tkinter.filedialog.askdirectory(title=data.get("title", "Select Folder"))
|
||||
return tkinter.filedialog.askdirectory(parent=self.root, title=data.get("title", "Select Folder"))
|
||||
|
||||
def selectFile(self, data):
|
||||
return tkinter.filedialog.askopenfilename(title=data.get("title", "Select File"))
|
||||
return tkinter.filedialog.askopenfilename(parent=self.root, title=data.get("title", "Select File"))
|
||||
|
||||
|
||||
if use_Gtk:
|
||||
ui = GtkUI()
|
||||
|
|
Loading…
Reference in a new issue