moved the piping of the bar menu into a separate file
This commit is contained in:
24
grum/barmenu.py
Normal file
24
grum/barmenu.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from PyQt5.QtWidgets import QAction
|
||||||
|
|
||||||
|
|
||||||
|
class BarMenu:
|
||||||
|
|
||||||
|
def __init__(self, bar, name):
|
||||||
|
self.menu = menu = bar.addMenu(name)
|
||||||
|
menu.triggered[QAction].connect(self.on_select)
|
||||||
|
self.actions = {}
|
||||||
|
|
||||||
|
def on_select(self, p):
|
||||||
|
txt = p.text()
|
||||||
|
func = self.actions[txt]
|
||||||
|
func()
|
||||||
|
|
||||||
|
def addAction(self, name, func):
|
||||||
|
self.menu.addAction(name)
|
||||||
|
self.actions[name] = func
|
||||||
|
|
||||||
|
def addSeparator(self):
|
||||||
|
self.menu.addSeparator()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -3,6 +3,7 @@ from PyQt5.QtGui import QPainter
|
|||||||
|
|
||||||
from .. import assets
|
from .. import assets
|
||||||
from ..theme import MDI_BKG
|
from ..theme import MDI_BKG
|
||||||
|
from ..barmenu import BarMenu
|
||||||
|
|
||||||
|
|
||||||
class MDIArea(QMdiArea):
|
class MDIArea(QMdiArea):
|
||||||
@ -16,21 +17,12 @@ class MDIArea(QMdiArea):
|
|||||||
|
|
||||||
|
|
||||||
def _add_menu(self, bar):
|
def _add_menu(self, bar):
|
||||||
menu = bar.addMenu("&Windows")
|
self.menu = menu = BarMenu(bar, "&Windows")
|
||||||
menu.addAction("Cascade")
|
menu.addAction("Cascade", self.on_cascade)
|
||||||
menu.addAction("Tile")
|
menu.addAction("Tile", self.on_tile)
|
||||||
menu.addAction("Tabbed")
|
menu.addAction("Tabbed", self.enable_tabbed_view)
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
menu.addAction("Close All")
|
menu.addAction("Close All", self.closeAllSubWindows)
|
||||||
menu.triggered[QAction].connect(self.on_menu_select)
|
|
||||||
|
|
||||||
self.actions = {
|
|
||||||
"Cascade": self.on_cascade,
|
|
||||||
"Tile": self.on_tile,
|
|
||||||
"Tabbed": self.enable_tabbed_view,
|
|
||||||
"Close All": self.closeAllSubWindows
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def on_cascade(self):
|
def on_cascade(self):
|
||||||
self.enable_subwindow_view()
|
self.enable_subwindow_view()
|
||||||
@ -47,11 +39,6 @@ class MDIArea(QMdiArea):
|
|||||||
self.setViewMode(QMdiArea.TabbedView)
|
self.setViewMode(QMdiArea.TabbedView)
|
||||||
|
|
||||||
|
|
||||||
def on_menu_select(self, p):
|
|
||||||
txt = p.text()
|
|
||||||
self.actions[txt]()
|
|
||||||
|
|
||||||
|
|
||||||
def paintEvent(self, _event):
|
def paintEvent(self, _event):
|
||||||
self._draw_watermark()
|
self._draw_watermark()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user