Add Help menu pointing to Github Pages (#242)

Edit GUI backend to allow creating QAction via `create_element(QAction, **kwargs)`
pull/357/head
nyanpasu64 2019-03-25 16:18:19 -07:00 zatwierdzone przez GitHub
rodzic 030e769413
commit 27b5fc5106
3 zmienionych plików z 32 dodań i 16 usunięć

Wyświetl plik

@ -8,9 +8,8 @@ from typing import Optional, List, Any, Tuple, Callable, Union, Dict, Sequence
import PyQt5.QtCore as qc
import PyQt5.QtWidgets as qw
import attr
from PyQt5.QtCore import QModelIndex, Qt
from PyQt5.QtCore import QVariant
from PyQt5.QtGui import QKeySequence, QFont, QCloseEvent
from PyQt5.QtCore import QModelIndex, Qt, QVariant
from PyQt5.QtGui import QKeySequence, QFont, QCloseEvent, QDesktopServices
from PyQt5.QtWidgets import QShortcut
import corrscope
@ -38,7 +37,7 @@ from corrscope.gui.model_bind import (
from corrscope.gui.util import color2hex, Locked, find_ranges, TracebackDialog
from corrscope.gui.view_mainwindow import MainWindow as Ui_MainWindow
from corrscope.layout import Orientation, StereoOrientation
from corrscope.outputs import IOutputConfig, FFplayOutputConfig, FFmpegOutputConfig
from corrscope.outputs import IOutputConfig, FFplayOutputConfig
from corrscope.settings import paths
from corrscope.triggers import (
CorrelationTriggerConfig,
@ -122,6 +121,7 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
self.actionSaveAs.triggered.connect(self.on_action_save_as)
self.actionPreview.triggered.connect(self.on_action_preview)
self.actionRender.triggered.connect(self.on_action_render)
self.actionHelp.triggered.connect(self.on_action_help)
self.actionExit.triggered.connect(qw.QApplication.closeAllWindows)
# Initialize CorrScope-thread attribute.
@ -454,6 +454,12 @@ class MainWindow(qw.QMainWindow, Ui_MainWindow):
def cfg(self):
return self.model.cfg
# Misc.
@qc.pyqtSlot()
def on_action_help(self):
help_url = r"https://nyanpasu64.github.io/corrscope/"
QDesktopServices.openUrl(qc.QUrl(help_url))
def format_stack_trace(e):
if isinstance(e, CorrError):

Wyświetl plik

@ -17,6 +17,7 @@ from corrscope.gui.view_stack import (
set_menu_bar,
append_menu,
add_toolbar,
create_element,
)
NBSP = "\xa0"
@ -372,6 +373,7 @@ class MainWindow(QWidget):
self.actionExit = QAction(MainWindow)
self.actionPreview = QAction(MainWindow)
self.actionRender = QAction(MainWindow)
self.actionHelp = create_element(QAction, MainWindow, text=tr("Help"))
self.action_separate_render_dir = QAction(MainWindow)
self.action_separate_render_dir.setCheckable(True)
@ -392,6 +394,10 @@ class MainWindow(QWidget):
with append_menu(s) as self.menuTools:
self.menuTools.addAction(self.action_separate_render_dir)
with append_menu(s, title=tr("&Help")) as w:
self.menuHelp = w
w.addAction(self.actionHelp)
# Setup toolbar
with add_toolbar(s, Qt.TopToolBarArea) as self.toolBar:
self.toolBar.addAction(self.actionNew)

Wyświetl plik

@ -20,24 +20,28 @@ WidgetOrLayout = TypeVar("WidgetOrLayout", bound=Union[QWidget, QLayout])
# LayoutStack.push(instance)
# Like HTML document.createElement()
def new_widget_or_layout(
item_type: Union[Type[WidgetOrLayout], str], parent: QWidget, attributes=None
def create_element(
item_type: Union[Type[WidgetOrLayout], str],
parent: QWidget,
attributes=None,
**kwargs,
) -> WidgetOrLayout:
"""Creates a widget or layout, for insertion into an existing layout.
Do NOT use for filling a widget with a layout!"""
if attributes is None:
attributes = {}
attributes.update(kwargs)
if isinstance(item_type, str):
item = QLabel(item_type, parent)
elif issubclass(item_type, QWidget):
item = item_type(parent)
else:
assert issubclass(item_type, QLayout)
elif issubclass(item_type, QLayout):
# new_widget_or_layout is used to add sublayouts, which do NOT have a parent.
# Only widgets' root layouts have parents.
item = item_type(None)
else:
assert issubclass(item_type, (QWidget, QAction))
item = item_type(parent)
if "name" in attributes:
item.setObjectName(attributes.pop("name"))
@ -151,9 +155,9 @@ def set_menu_bar(stack: LayoutStack):
# won't bother adding type hints that pycharm is too dumb to understand
def append_menu(stack: LayoutStack):
def append_menu(stack: LayoutStack, **kwargs):
assert_peek(stack, QMenuBar)
return _new_widget(stack, QMenu, exit_action="addMenu")
return _new_widget(stack, QMenu, exit_action="addMenu", **kwargs)
def add_toolbar(stack: LayoutStack, area=Qt.TopToolBarArea):
@ -188,7 +192,7 @@ def _new_widget(
else:
parent = None
with stack.push(new_widget_or_layout(item_type, parent, kwargs)) as item:
with stack.push(create_element(item_type, parent, kwargs)) as item:
if layout:
set_layout(stack, layout)
yield item
@ -227,12 +231,12 @@ def widget_pair_inserter(append_widgets: Callable):
parent = stack.widget
if right_type is Both:
left = new_widget_or_layout(left_type, parent, kwargs)
left = create_element(left_type, parent, kwargs)
right = Both
push = left
else:
left = new_widget_or_layout(left_type, parent)
right = new_widget_or_layout(right_type, parent, kwargs)
left = create_element(left_type, parent)
right = create_element(right_type, parent, kwargs)
push = right
if name: