-
Notifications
You must be signed in to change notification settings - Fork 6
/
toolbar.py
85 lines (65 loc) · 2.5 KB
/
toolbar.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
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import annotations
import os
import sysconfig
import webbrowser
from typing import Dict
from platform import python_version
from PySide2 import __version__ as PySide2_version
from PySide2.QtCore import Slot
from PySide2.QtWidgets import (QLabel, QAction, QDialog, QWidget, QToolBar,
QFormLayout, QPushButton)
from .version import __version__
def about() -> Dict[str, str]:
"""Return a dictionary with information about the application."""
return {
'version': __version__,
'python': python_version(),
'pyside': PySide2_version,
'machine': sysconfig.get_platform(),
'user': os.getenv('USER', os.getenv('USERNAME', 'unknown')),
}
class HelpWidget(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('NukeServerSocket Help')
form_layout = QFormLayout()
for name, value in about().items():
form_layout.addRow(f'{name.title()}:', QLabel(value))
form_layout.addRow(self._button_builder('Readme'))
form_layout.addRow(self._button_builder('Changelog'))
form_layout.addRow(self._button_builder('Issues'))
self.setLayout(form_layout)
def _button_builder(self, text: str) -> QPushButton:
button = QPushButton(text)
button.clicked.connect(lambda: self._on_open_link(text))
return button
@Slot(str)
def _on_open_link(self, link: str):
gitrepo = 'https://github.com/sisoe24/nukeserversocket'
links = {
'issues': f'{gitrepo}/issues',
'changelog': f'{gitrepo}/blob/master/CHANGELOG.md',
'readme': f'{gitrepo}/blob/master/README.md'
}
webbrowser.open(links[link.lower()])
def _show_window(widget: QWidget) -> None:
"""Show a widget window.
If widget is already visible then regain focus.
"""
widget.show()
widget.activateWindow()
widget.raise_()
class ToolBar(QToolBar):
"""Custom QToolBar class."""
def __init__(self, parent=None):
"""Init method for the ToolBar class."""
super().__init__(parent)
self.setMovable(False)
self.setStyleSheet('color: white;')
self.add_widget(title='Help', widget=HelpWidget(self))
def add_widget(self, title: str, widget: QWidget) -> QAction:
widget.setWindowTitle(title)
action = QAction(title, self)
action.triggered.connect(lambda: _show_window(widget))
self.addAction(action)
return action