-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgui_utilities.py
72 lines (62 loc) · 2.77 KB
/
gui_utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
from __future__ import unicode_literals, division, absolute_import, print_function
import sys
import os
from compatibility_utils import PY2
from compatibility_utils import unicode_str
from plugin_utils import iswindows
def fileChooser(startfolder, bk, gui='tkinter'):
if gui == 'tkinter':
if PY2:
from Tkinter import Tk
import tkFileDialog as tkinter_filedialog
# import tkMessageBox as tkinter_msgbox
else:
from tkinter import Tk
import tkinter.filedialog as tkinter_filedialog
# import tkinter.messagebox as tkinter_msgbox
localRoot = Tk()
localRoot.withdraw()
file_opt = {}
file_opt['parent'] = None
file_opt['title']= 'Select Kindlebook file'
file_opt['defaultextension'] = '.azw3'
# retrieve the initialdir from JSON prefs
file_opt['initialdir'] = unicode_str(startfolder, 'utf-8')
file_opt['multiple'] = False
file_opt['filetypes'] = [('Kindlebooks', ('.azw', '.azw3', '.prc', '.mobi'))]
localRoot.quit()
return tkinter_filedialog.askopenfilename(**file_opt)
elif gui == 'pyqt':
from plugin_utils import QtWidgets
from plugin_utils import PluginApplication
icon = os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'plugin.png')
mdp = True if iswindows else False
app = PluginApplication(sys.argv, bk, app_icon=icon, match_dark_palette=mdp) # noqa
w = QtWidgets.QWidget()
options = QtWidgets.QFileDialog.Options()
options |= QtWidgets.QFileDialog.DontUseNativeDialog
fileName, _ = QtWidgets.QFileDialog.getOpenFileName(w,'Select Kindlebook file', unicode_str(startfolder, 'utf-8'),
'Kindlebooks (*.azw *.azw3 *.prc *.mobi)', options=options)
return fileName
def update_msgbox(title, msg, bk, gui='tkinter'):
if gui == 'tkinter':
if PY2:
from Tkinter import Tk
import tkMessageBox as tkinter_msgbox
else:
from tkinter import Tk
import tkinter.messagebox as tkinter_msgbox
localRoot = Tk()
localRoot.withdraw()
localRoot.option_add('*font', 'Helvetica -12')
localRoot.quit()
return tkinter_msgbox.showinfo(title, msg)
elif gui == 'pyqt':
from plugin_utils import QtWidgets, PluginApplication
icon = os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'plugin.png')
mdp = True if iswindows else False
app = PluginApplication(sys.argv, bk, app_icon=icon, match_dark_palette=mdp) # noqa
w = QtWidgets.QWidget()
return QtWidgets.QMessageBox.information(w, title, msg)