|
11 | 11 |
|
12 | 12 | import pkg_resources |
13 | 13 |
|
14 | | -from PyQt4.QtGui import ( |
| 14 | +from AnyQt.QtWidgets import ( |
15 | 15 | QMainWindow, QWidget, QAction, QActionGroup, QMenu, QMenuBar, QDialog, |
16 | | - QFileDialog, QMessageBox, QVBoxLayout, QSizePolicy, QColor, QKeySequence, |
17 | | - QIcon, QToolBar, QToolButton, QDockWidget, QDesktopServices, QApplication, |
18 | | - QShortcut |
| 16 | + QFileDialog, QMessageBox, QVBoxLayout, QSizePolicy, QToolBar, QToolButton, |
| 17 | + QDockWidget, QApplication, QShortcut |
19 | 18 | ) |
| 19 | +from AnyQt.QtGui import QColor, QIcon, QDesktopServices, QKeySequence |
20 | 20 |
|
21 | | -from PyQt4.QtCore import ( |
22 | | - Qt, QEvent, QSize, QUrl, QTimer, QFile, QByteArray |
| 21 | +from AnyQt.QtCore import ( |
| 22 | + Qt, QEvent, QSize, QUrl, QTimer, QFile, QByteArray, QSettings, QT_VERSION |
23 | 23 | ) |
24 | 24 |
|
25 | | -from PyQt4.QtNetwork import QNetworkDiskCache |
26 | | - |
27 | | -from PyQt4.QtWebKit import QWebView |
28 | | - |
29 | | -from PyQt4.QtCore import pyqtProperty as Property |
30 | | - |
31 | | -# Compatibility with PyQt < v4.8.3 |
32 | | -from ..utils.qtcompat import QSettings |
| 25 | +if QT_VERSION < 0x50500: |
| 26 | + from AnyQt.QtWebKitWidgets import QWebView |
| 27 | + from AnyQt.QtNetwork import QNetworkDiskCache |
| 28 | + USE_WEB_ENGINE = False |
| 29 | +else: |
| 30 | + from PyQt5.QtWebEngineWidgets import QWebEngineView |
| 31 | + USE_WEB_ENGINE = True |
| 32 | + |
| 33 | +from AnyQt.QtCore import pyqtProperty as Property |
| 34 | + |
| 35 | +if QT_VERSION >= 0x50000: |
| 36 | + from AnyQt.QtCore import QStandardPaths |
| 37 | + def user_documents_path(): |
| 38 | + """Return the users 'Documents' folder path.""" |
| 39 | + return QStandardPaths.writableLocation( |
| 40 | + QStandardPaths.DocumentsLocation) |
| 41 | +else: |
| 42 | + def user_documents_path(): |
| 43 | + return QDesktopServices.storageLocation( |
| 44 | + QDesktopServices.DocumentsLocation) |
33 | 45 |
|
34 | 46 | from ..gui.dropshadow import DropShadowFrame |
35 | 47 | from ..gui.dock import CollapsibleDockWidget |
@@ -155,9 +167,7 @@ def __init__(self, *args): |
155 | 167 |
|
156 | 168 | self.widget_registry = None |
157 | 169 |
|
158 | | - self.last_scheme_dir = QDesktopServices.StandardLocation( |
159 | | - QDesktopServices.DocumentsLocation |
160 | | - ) |
| 170 | + self.last_scheme_dir = user_documents_path() |
161 | 171 | try: |
162 | 172 | self.recent_schemes = config.recent_schemes() |
163 | 173 | except Exception: |
@@ -334,13 +344,17 @@ def setup_ui(self): |
334 | 344 | objectName="help-dock", |
335 | 345 | allowedAreas=Qt.RightDockWidgetArea | |
336 | 346 | Qt.BottomDockWidgetArea) |
337 | | - self.help_view = QWebView() |
338 | | - manager = self.help_view.page().networkAccessManager() |
339 | | - cache = QNetworkDiskCache() |
340 | | - cache.setCacheDirectory( |
341 | | - os.path.join(config.cache_dir(), "help", "help-view-cache") |
342 | | - ) |
343 | | - manager.setCache(cache) |
| 347 | + self.help_dock.setAllowedAreas(Qt.NoDockWidgetArea) |
| 348 | + if USE_WEB_ENGINE: |
| 349 | + self.help_view = QWebEngineView() |
| 350 | + else: |
| 351 | + self.help_view = QWebView() |
| 352 | + manager = self.help_view.page().networkAccessManager() |
| 353 | + cache = QNetworkDiskCache() |
| 354 | + cache.setCacheDirectory( |
| 355 | + os.path.join(config.cache_dir(), "help", "help-view-cache") |
| 356 | + ) |
| 357 | + manager.setCache(cache) |
344 | 358 | self.help_dock.setWidget(self.help_view) |
345 | 359 | self.addDockWidget( |
346 | 360 | QSettings().value('help-dock/area', Qt.RightDockWidgetArea, type=int), |
@@ -567,7 +581,10 @@ def setup_actions(self): |
567 | 581 | triggered=self.reset_widget_settings) |
568 | 582 |
|
569 | 583 | def setup_menu(self): |
570 | | - menu_bar = QMenuBar() |
| 584 | + if sys.platform == "darwin" and QT_VERSION >= 0x50000: |
| 585 | + self.__menu_glob = QMenuBar(None) |
| 586 | + |
| 587 | + menu_bar = QMenuBar(self) |
571 | 588 |
|
572 | 589 | # File menu |
573 | 590 | file_menu = QMenu(self.tr("&File"), menu_bar) |
@@ -691,9 +708,7 @@ def restore(self): |
691 | 708 | self.show_log_action.setChecked( |
692 | 709 | settings.value("output-dock/is-visible", False, type=bool)) |
693 | 710 |
|
694 | | - default_dir = QDesktopServices.storageLocation( |
695 | | - QDesktopServices.DocumentsLocation |
696 | | - ) |
| 711 | + default_dir = user_documents_path() |
697 | 712 |
|
698 | 713 | self.last_scheme_dir = settings.value("last-scheme-dir", default_dir, |
699 | 714 | type=str) |
@@ -872,15 +887,14 @@ def open_scheme(self): |
872 | 887 |
|
873 | 888 | if self.last_scheme_dir is None: |
874 | 889 | # Get user 'Documents' folder |
875 | | - start_dir = QDesktopServices.storageLocation( |
876 | | - QDesktopServices.DocumentsLocation) |
| 890 | + start_dir = user_documents_path() |
877 | 891 | else: |
878 | 892 | start_dir = self.last_scheme_dir |
879 | 893 |
|
880 | 894 | # TODO: Use a dialog instance and use 'addSidebarUrls' to |
881 | 895 | # set one or more extra sidebar locations where Schemes are stored. |
882 | 896 | # Also use setHistory |
883 | | - filename = QFileDialog.getOpenFileName( |
| 897 | + filename, _ = QFileDialog.getOpenFileName( |
884 | 898 | self, self.tr("Open Orange Workflow File"), |
885 | 899 | start_dir, self.tr("Orange Workflow (*.ows)"), |
886 | 900 | ) |
@@ -1179,13 +1193,11 @@ def save_scheme_as(self): |
1179 | 1193 | if self.last_scheme_dir is not None: |
1180 | 1194 | start_dir = self.last_scheme_dir |
1181 | 1195 | else: |
1182 | | - start_dir = QDesktopServices.storageLocation( |
1183 | | - QDesktopServices.DocumentsLocation |
1184 | | - ) |
| 1196 | + start_dir = user_documents_path() |
1185 | 1197 |
|
1186 | 1198 | start_dir = os.path.join(str(start_dir), title + ".ows") |
1187 | 1199 |
|
1188 | | - filename = QFileDialog.getSaveFileName( |
| 1200 | + filename, _ = QFileDialog.getSaveFileName( |
1189 | 1201 | self, self.tr("Save Orange Workflow File"), |
1190 | 1202 | start_dir, self.tr("Orange Workflow (*.ows)") |
1191 | 1203 | ) |
|
0 commit comments