Skip to content

Commit

Permalink
Use QToolbar insteadmenubar
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmassay committed Feb 24, 2022
1 parent 5f80a08 commit fba15c5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions buildplugin
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ PLUGIN_FILES = ['dialogs.py',
'plugin.xml',
'plugin_utils.py',
'utilities.py',
'config.svg',
'plugin.svg',
'plugin.png',]

Expand Down
54 changes: 54 additions & 0 deletions config.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 15 additions & 6 deletions dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from utilities import UpdateChecker, taglist, combobox_defaults, remove_dupes
from parsing_engine import MarkupParser

from plugin_utils import Qt, QtCore, QtWidgets, QAction
from plugin_utils import Qt, QtCore, QtGui, QtWidgets, QAction
from plugin_utils import PluginApplication, iswindows, _t # , Signal, Slot, loadUi


Expand All @@ -30,7 +30,8 @@ def launch_gui(bk, prefs):

icon = os.path.join(bk._w.plugin_dir, bk._w.plugin_name, 'plugin.svg')
mdp = True if iswindows else False
app = PluginApplication(sys.argv, bk, app_icon=icon, match_dark_palette=mdp)
app = PluginApplication(sys.argv, bk, app_icon=icon, match_dark_palette=mdp,
dont_use_native_menubars=True)

win = guiMain(bk, prefs)
# Use exec() and not exec_() for PyQt5/PySide6 compliance
Expand Down Expand Up @@ -176,12 +177,20 @@ def setup_ui(self):
self.NO_CHANGE_STR = _t('guiMain', 'No change')
self.setWindowTitle(_t('guiMain', 'Tag Mechanic'))

configAct = QAction(_t('guiMain', '&Config'), self)
configAct = QAction(_t('guiMain', 'Config'), self)
configAct.setShortcut('Ctrl+Alt+C')
tooltip = _t('guiMain','Configure')
configAct.setToolTip(tooltip + ' ' + self.bk._w.plugin_name)
icon = os.path.join(self.bk._w.plugin_dir, self.bk._w.plugin_name, 'config.svg')
configAct.setIcon(QtGui.QIcon(icon))
configAct.triggered.connect(self.showConfig)

menubar = self.menuBar()
fileMenu = menubar.addMenu(_t('guiMain', '&Edit'))
fileMenu.addAction(configAct)
editToolBar = self.addToolBar(_t('guiMain', 'Edit'))
editToolBar.setMovable(False)
editToolBar.setFloatable(False)
editToolBar.setContextMenuPolicy(Qt.PreventContextMenu)
editToolBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
editToolBar.addAction(configAct)

layout = QtWidgets.QVBoxLayout()

Expand Down
10 changes: 5 additions & 5 deletions plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
SCRIPT_DIRECTORY = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
e = os.environ.get('SIGIL_QT_RUNTIME_VERSION', '5.10.0')
SIGIL_QT_MAJOR_VERSION = tuple(map(int, (e.split("."))))[0]
DEBUG = 0
DEBUG = 1


if SIGIL_QT_MAJOR_VERSION == 6:
from PySide6 import QtCore, QtGui, QtNetwork, QtPrintSupport, QtSvg, QtWebChannel, QtWidgets # noqa: F401
from PySide6 import QtWebEngineCore, QtWebEngineWidgets # noqa: F401
from PySide6.QtCore import Qt, Signal, Slot, qVersion # noqa: F401
from PySide6.QtGui import QAction # noqa: F401
from PySide6.QtGui import QAction, QActionGroup # noqa: F401
from PySide6.QtUiTools import QUiLoader # noqa: F401
elif SIGIL_QT_MAJOR_VERSION == 5:
from PyQt5 import QtCore, QtGui, QtNetwork, QtPrintSupport, QtSvg, QtWebChannel, QtWidgets # noqa: F401
from PyQt5 import QtWebEngineCore, QtWebEngineWidgets # noqa: F401
from PyQt5.QtCore import Qt, pyqtSignal as Signal, pyqtSlot as Slot, qVersion # noqa: F401
from PyQt5.QtWidgets import QAction # noqa: F401
from PyQt5.QtWidgets import QAction, QActionGroup # noqa: F401
from PyQt5 import uic # noqa: F401


Expand Down Expand Up @@ -136,7 +136,7 @@ def convertWeights(weight, inverted=False, shift=False):
class PluginApplication(QtWidgets.QApplication):
def __init__(self, args, bk, app_icon=None, match_fonts=True,
match_highdpi=True, match_dark_palette=True,
match_whats_this=True, dont_use_native_menubars=True,
match_whats_this=True, dont_use_native_menubars=False,
load_qtbase_translations=True, load_qtplugin_translations=True,
plugin_trans_folder=None):

Expand All @@ -145,7 +145,7 @@ def __init__(self, args, bk, app_icon=None, match_fonts=True,
self.setAttribute(Qt.AA_DontUseNativeMenuBar)

self.bk = bk
program_name = 'sigil_plugin_{}'.format(bk._w.plugin_name.lower())
program_name = '{}'.format(bk._w.plugin_name)
if plugin_trans_folder is None:
plugin_trans_folder = os.path.join(self.bk._w.plugin_dir, self.bk._w.plugin_name, 'translations')

Expand Down

0 comments on commit fba15c5

Please sign in to comment.