gera 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gera-0.1.0/.github/workflows/ci.yml +26 -0
- gera-0.1.0/.github/workflows/release.yml +35 -0
- gera-0.1.0/.gitignore +4 -0
- gera-0.1.0/.vscode/settings.json +5 -0
- gera-0.1.0/PKG-INFO +10 -0
- gera-0.1.0/README.md +5 -0
- gera-0.1.0/gera/__init__.py +0 -0
- gera-0.1.0/gera/__main__.py +3 -0
- gera-0.1.0/gera/application.py +41 -0
- gera-0.1.0/gera/dbutils.py +66 -0
- gera-0.1.0/gera/main_window.py +133 -0
- gera-0.1.0/gera/mdi_area.py +253 -0
- gera-0.1.0/gera/report_window.py +137 -0
- gera-0.1.0/gera/resources/cascade.svg +20 -0
- gera-0.1.0/gera/resources/fullscreen.svg +12 -0
- gera-0.1.0/gera/resources/gera.svg +16 -0
- gera-0.1.0/gera/resources/menu.svg +4 -0
- gera-0.1.0/gera/resources/next.svg +6 -0
- gera-0.1.0/gera/resources/open.svg +7 -0
- gera-0.1.0/gera/resources/prev.svg +6 -0
- gera-0.1.0/gera/resources/tile.svg +19 -0
- gera-0.1.0/gera/resources/tile_h.svg +13 -0
- gera-0.1.0/gera/resources/tile_v.svg +12 -0
- gera-0.1.0/gera/schemas/__init__.py +45 -0
- gera-0.1.0/gera/schemas/ldj.py +230 -0
- gera-0.1.0/gera/sql_text_edit.py +168 -0
- gera-0.1.0/gera/utils.py +12 -0
- gera-0.1.0/gera.egg-info/PKG-INFO +10 -0
- gera-0.1.0/gera.egg-info/SOURCES.txt +34 -0
- gera-0.1.0/gera.egg-info/dependency_links.txt +1 -0
- gera-0.1.0/gera.egg-info/entry_points.txt +2 -0
- gera-0.1.0/gera.egg-info/requires.txt +1 -0
- gera-0.1.0/gera.egg-info/top_level.txt +1 -0
- gera-0.1.0/pyproject.toml +27 -0
- gera-0.1.0/run_gera.py +5 -0
- gera-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "main" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "main" ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
main:
|
|
11
|
+
name: Main pipeline
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
security-events: read
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: '3.10'
|
|
21
|
+
cache: 'pip'
|
|
22
|
+
- uses: psf/black@stable
|
|
23
|
+
- name: wheel
|
|
24
|
+
run: |
|
|
25
|
+
pip install build
|
|
26
|
+
python -m build . --wheel
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: PyPI Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*' # Triggers on version tags
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
release:
|
|
10
|
+
name: Publish on PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: release
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
id-token: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: '3.10'
|
|
21
|
+
cache: 'pip'
|
|
22
|
+
- name: Build
|
|
23
|
+
run: |
|
|
24
|
+
pip install build &&
|
|
25
|
+
python -m build
|
|
26
|
+
- name: Publish
|
|
27
|
+
# implemented using "STOP! You probably don't need this section"
|
|
28
|
+
# as it was easy to understand and implement
|
|
29
|
+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
|
|
30
|
+
run: |
|
|
31
|
+
pip install id twine &&
|
|
32
|
+
oidc_token=$(python -m id pypi)
|
|
33
|
+
resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}")
|
|
34
|
+
api_token=$(jq -r '.token' <<< "${resp}")
|
|
35
|
+
twine upload --verbose --username __token__ --password ${api_token} dist/*
|
gera-0.1.0/.gitignore
ADDED
gera-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gera
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: General ERror Analyzer
|
|
5
|
+
Author-email: Arseniy Terekhin <senyai@gmail.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: PyQt5
|
gera-0.1.0/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from argparse import Namespace, ArgumentParser
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def application():
|
|
7
|
+
from PyQt5.QtWidgets import QApplication
|
|
8
|
+
|
|
9
|
+
a = QApplication(sys.argv)
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from gera.main_window import MainWindow
|
|
13
|
+
|
|
14
|
+
main_window = MainWindow(**vars(parse_args()))
|
|
15
|
+
except Exception:
|
|
16
|
+
import traceback
|
|
17
|
+
|
|
18
|
+
traceback.print_exc(file=sys.stdout)
|
|
19
|
+
print("press <Enter> to exit")
|
|
20
|
+
input()
|
|
21
|
+
return (None, None)
|
|
22
|
+
|
|
23
|
+
main_window.show()
|
|
24
|
+
return a, main_window
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def main():
|
|
28
|
+
a, _main_window = application()
|
|
29
|
+
sys.exit(a and a.exec_())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def parse_args() -> Namespace:
|
|
33
|
+
parser = ArgumentParser("GERA runner")
|
|
34
|
+
|
|
35
|
+
parser.add_argument("files", nargs="*", help="files to open")
|
|
36
|
+
parser.add_argument(
|
|
37
|
+
"--schema",
|
|
38
|
+
choices=["ldj"],
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return parser.parse_args()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from itertools import islice, chain
|
|
3
|
+
|
|
4
|
+
SEP = "/"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def batch(iterable, size=100):
|
|
8
|
+
"""
|
|
9
|
+
>>> list(list(_) for _ in batch(range(10), 3))
|
|
10
|
+
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
|
|
11
|
+
"""
|
|
12
|
+
it = iter(iterable)
|
|
13
|
+
try:
|
|
14
|
+
while True:
|
|
15
|
+
batchiter = islice(it, size)
|
|
16
|
+
yield chain([next(batchiter)], batchiter)
|
|
17
|
+
except StopIteration:
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def flat_dict(entry, sep=SEP):
|
|
22
|
+
"""
|
|
23
|
+
flattens hierarchical dict adding sep at each depth
|
|
24
|
+
"""
|
|
25
|
+
for key, value in entry.items():
|
|
26
|
+
if isinstance(value, dict):
|
|
27
|
+
for sub_key, value in flat_dict(value):
|
|
28
|
+
yield key + sep + sub_key, value
|
|
29
|
+
elif isinstance(value, list):
|
|
30
|
+
yield key, int # count number of items
|
|
31
|
+
elif value is not None:
|
|
32
|
+
yield key, type(value)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def extract_rows(data):
|
|
36
|
+
"""
|
|
37
|
+
list all possible column names from dict
|
|
38
|
+
"""
|
|
39
|
+
rows = {}
|
|
40
|
+
for plate in data:
|
|
41
|
+
rows.update(flat_dict(plate))
|
|
42
|
+
return rows
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def create_table_statement(
|
|
46
|
+
rows: dict[str, type[int | str | float]],
|
|
47
|
+
table_name: str = "report",
|
|
48
|
+
column_order: list[str] | None = None,
|
|
49
|
+
):
|
|
50
|
+
"""
|
|
51
|
+
:param rows: dict of `str:type`
|
|
52
|
+
"""
|
|
53
|
+
types = {
|
|
54
|
+
int: "INTEGER",
|
|
55
|
+
float: "REAL",
|
|
56
|
+
}
|
|
57
|
+
return (
|
|
58
|
+
"CREATE TABLE "
|
|
59
|
+
+ table_name
|
|
60
|
+
+ " (\n "
|
|
61
|
+
+ ",\n ".join(
|
|
62
|
+
'"' + key + '" ' + types.get(rows[key], "TEXT")
|
|
63
|
+
for key in column_order or sorted(rows)
|
|
64
|
+
)
|
|
65
|
+
+ "\n)"
|
|
66
|
+
)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
3
|
+
from .mdi_area import MdiArea
|
|
4
|
+
from .utils import get_icon
|
|
5
|
+
from .schemas import iter_schemas, load_schema_cls
|
|
6
|
+
|
|
7
|
+
Qt = QtCore.Qt
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MainWindow(QtWidgets.QMainWindow):
|
|
11
|
+
def __init__(self, schema: str, files: list[str]):
|
|
12
|
+
# enable `get_icon`
|
|
13
|
+
QtCore.QDir.addSearchPath(
|
|
14
|
+
"gera",
|
|
15
|
+
QtCore.QFileInfo(f"{__file__}/../resources").absoluteFilePath(),
|
|
16
|
+
)
|
|
17
|
+
super().__init__(
|
|
18
|
+
windowTitle="GERA - General ERror Analyzer",
|
|
19
|
+
windowIcon=get_icon("gera"),
|
|
20
|
+
)
|
|
21
|
+
self._setup_ui()
|
|
22
|
+
self._load_settings()
|
|
23
|
+
if schema == "ldj":
|
|
24
|
+
for path in files:
|
|
25
|
+
cls = load_schema_cls("ldj")
|
|
26
|
+
report_window = cls().open_filename(path)
|
|
27
|
+
if report_window:
|
|
28
|
+
self._mdi_area.add(report_window, True)
|
|
29
|
+
|
|
30
|
+
def _setup_ui(self):
|
|
31
|
+
self.resize(1000, 770)
|
|
32
|
+
self.setStyleSheet(
|
|
33
|
+
"""QMainWindow::separator, QSplitter::handle {
|
|
34
|
+
background:rgba(0,0,0,50);
|
|
35
|
+
width:4px;
|
|
36
|
+
height:4px;
|
|
37
|
+
} """
|
|
38
|
+
)
|
|
39
|
+
# main_splitter splits left_frame and mdi_area
|
|
40
|
+
menu_button = self._create_menu_button()
|
|
41
|
+
self._mdi_area = MdiArea(self, menu_button)
|
|
42
|
+
self._mdi_area.subWindowActivated.connect(self._sub_window_changed)
|
|
43
|
+
|
|
44
|
+
self.setCentralWidget(self._mdi_area)
|
|
45
|
+
|
|
46
|
+
def _create_menu_button(self):
|
|
47
|
+
size_policy = QtWidgets.QSizePolicy(
|
|
48
|
+
QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed
|
|
49
|
+
)
|
|
50
|
+
menu_button = QtWidgets.QPushButton(
|
|
51
|
+
maximumSize=QtCore.QSize(24, 24),
|
|
52
|
+
icon=get_icon("menu"),
|
|
53
|
+
flat=True,
|
|
54
|
+
sizePolicy=size_policy,
|
|
55
|
+
shortcut="Alt+M",
|
|
56
|
+
)
|
|
57
|
+
menu = QtWidgets.QMenu()
|
|
58
|
+
self._open_actions = []
|
|
59
|
+
for name, title in iter_schemas():
|
|
60
|
+
open_act = QtWidgets.QAction(
|
|
61
|
+
get_icon("open"),
|
|
62
|
+
"&Open - " + title,
|
|
63
|
+
self,
|
|
64
|
+
triggered=self._on_open,
|
|
65
|
+
)
|
|
66
|
+
open_act.setData(name)
|
|
67
|
+
self._open_actions.append(open_act)
|
|
68
|
+
menu.addActions(self._open_actions)
|
|
69
|
+
menu_button.setMenu(menu)
|
|
70
|
+
return menu_button
|
|
71
|
+
|
|
72
|
+
def _on_open(self):
|
|
73
|
+
self._default_open = module_name = self.sender().data()
|
|
74
|
+
for act in self._open_actions:
|
|
75
|
+
act.setShortcut(
|
|
76
|
+
"Ctrl+O" if act is self.sender() else QtGui.QKeySequence()
|
|
77
|
+
)
|
|
78
|
+
cls = load_schema_cls(module_name)
|
|
79
|
+
settings = self.get_settings()
|
|
80
|
+
try:
|
|
81
|
+
report_window = cls().open(self, settings)
|
|
82
|
+
except Exception as e:
|
|
83
|
+
QtWidgets.QMessageBox.warning(
|
|
84
|
+
self,
|
|
85
|
+
"Warning",
|
|
86
|
+
"Error opening a file:\n\n"
|
|
87
|
+
+ repr(e)
|
|
88
|
+
+ "\n\nprobably invalid file",
|
|
89
|
+
)
|
|
90
|
+
import traceback
|
|
91
|
+
|
|
92
|
+
traceback.print_exception(e)
|
|
93
|
+
return
|
|
94
|
+
if report_window is not None:
|
|
95
|
+
self._mdi_area.add(report_window, True)
|
|
96
|
+
|
|
97
|
+
def _sub_window_changed(self, window):
|
|
98
|
+
if window is not None:
|
|
99
|
+
try:
|
|
100
|
+
on_activate = window.widget().on_activate
|
|
101
|
+
except AttributeError:
|
|
102
|
+
return
|
|
103
|
+
on_activate()
|
|
104
|
+
|
|
105
|
+
def _load_settings(self):
|
|
106
|
+
settings = self.get_settings()
|
|
107
|
+
default = QtCore.QByteArray()
|
|
108
|
+
self.restoreGeometry(settings.value("geometry", default))
|
|
109
|
+
self.restoreState(settings.value("windowState", default))
|
|
110
|
+
self._default_open = settings.value("default_open", "")
|
|
111
|
+
for act in self._open_actions:
|
|
112
|
+
if act.data() == self._default_open:
|
|
113
|
+
act.setShortcut(Qt.CTRL + Qt.Key_O)
|
|
114
|
+
|
|
115
|
+
def closeEvent(self, event: QtGui.QCloseEvent):
|
|
116
|
+
"""User closes GERA. By default, the event is accepted."""
|
|
117
|
+
self._mdi_area.closeAllSubWindows()
|
|
118
|
+
if self._mdi_area.subWindowList():
|
|
119
|
+
event.ignore()
|
|
120
|
+
else:
|
|
121
|
+
self._save_settings()
|
|
122
|
+
|
|
123
|
+
def _save_settings(self):
|
|
124
|
+
"""Called from closeEvent."""
|
|
125
|
+
settings = self.get_settings()
|
|
126
|
+
|
|
127
|
+
settings.setValue("geometry", self.saveGeometry())
|
|
128
|
+
settings.setValue("windowState", self.saveState())
|
|
129
|
+
settings.setValue("default_open", self._default_open)
|
|
130
|
+
|
|
131
|
+
@staticmethod
|
|
132
|
+
def get_settings():
|
|
133
|
+
return QtCore.QSettings("iitpvisionlab", "GERA")
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
3
|
+
from .utils import get_icon
|
|
4
|
+
|
|
5
|
+
Qt = QtCore.Qt
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TabRenamer(QtCore.QObject):
|
|
9
|
+
def eventFilter(self, tab_bar, event):
|
|
10
|
+
if (
|
|
11
|
+
event.type() == event.MouseButtonDblClick
|
|
12
|
+
and event.button() == QtCore.Qt.LeftButton
|
|
13
|
+
):
|
|
14
|
+
tab_idx = tab_bar.tabAt(event.pos())
|
|
15
|
+
if tab_idx >= 0:
|
|
16
|
+
text, ok = QtWidgets.QInputDialog.getText(
|
|
17
|
+
tab_bar,
|
|
18
|
+
"Tab Name",
|
|
19
|
+
"?",
|
|
20
|
+
QtWidgets.QLineEdit.Normal,
|
|
21
|
+
tab_bar.tabText(tab_idx),
|
|
22
|
+
)
|
|
23
|
+
if ok and text:
|
|
24
|
+
tab_bar.setTabText(tab_idx, text)
|
|
25
|
+
return True
|
|
26
|
+
return False
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def action_for(self, **mod):
|
|
30
|
+
def action(text, *args, **kwargs):
|
|
31
|
+
if args:
|
|
32
|
+
kwargs["triggered"] = args[0]
|
|
33
|
+
kwargs.update(mod)
|
|
34
|
+
return QtWidgets.QAction(self.tr(text), self, **kwargs)
|
|
35
|
+
|
|
36
|
+
return action
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class MdiArea(QtWidgets.QMdiArea):
|
|
40
|
+
def __init__(self, parent, button):
|
|
41
|
+
super(MdiArea, self).__init__(
|
|
42
|
+
parent,
|
|
43
|
+
objectName="mdi_area",
|
|
44
|
+
viewMode=QtWidgets.QMdiArea.TabbedView,
|
|
45
|
+
)
|
|
46
|
+
self._button = button
|
|
47
|
+
button.setParent(self)
|
|
48
|
+
|
|
49
|
+
# Setting elide mode
|
|
50
|
+
self._tab_bar = tab_bar = self.findChild(QtWidgets.QTabBar)
|
|
51
|
+
tab_bar.setElideMode(Qt.ElideMiddle)
|
|
52
|
+
tab_bar.setMovable(True)
|
|
53
|
+
tab_bar.setTabsClosable(True)
|
|
54
|
+
tab_bar.currentChanged.connect(self._add_button_space)
|
|
55
|
+
tab_bar.tabCloseRequested.connect(self._add_button_space)
|
|
56
|
+
self.subWindowActivated.connect(self._add_button_space)
|
|
57
|
+
self._renamer = TabRenamer()
|
|
58
|
+
tab_bar.installEventFilter(self._renamer)
|
|
59
|
+
|
|
60
|
+
# Actions
|
|
61
|
+
action = action_for(self)
|
|
62
|
+
close_all_act = action("Close &All", self.closeAllSubWindows)
|
|
63
|
+
|
|
64
|
+
close_others_act = action("Close &Others", self.close_others)
|
|
65
|
+
|
|
66
|
+
self.fullscreen_act = action(
|
|
67
|
+
"&Fullscreen",
|
|
68
|
+
icon=get_icon("fullscreen"),
|
|
69
|
+
checkable=True,
|
|
70
|
+
toggled=self.fullscreen,
|
|
71
|
+
shortcut="Ctrl+F11",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
tile_act = action("&Tile", self.tileSubWindows, icon=get_icon("tile"))
|
|
75
|
+
|
|
76
|
+
tile_vert_act = action(
|
|
77
|
+
"&Tile Vertical",
|
|
78
|
+
self.tile_vertical,
|
|
79
|
+
icon=get_icon("tile_v"),
|
|
80
|
+
shortcut="Ctrl+Alt+Left",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
tile_horz_act = action(
|
|
84
|
+
"&Tile Horizontal",
|
|
85
|
+
self.tile_horizontal,
|
|
86
|
+
icon=get_icon("tile_h"),
|
|
87
|
+
shortcut="Ctrl+Alt+Up",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
tile_vert_rev_act = action(
|
|
91
|
+
"&Tile Vertical Reverse",
|
|
92
|
+
self.tile_vertical_rev,
|
|
93
|
+
icon=get_icon("tile_v"),
|
|
94
|
+
shortcut="Ctrl+Alt+Right",
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
tile_horz_rev_act = action(
|
|
98
|
+
"&Tile Horizontal Reverse",
|
|
99
|
+
self.tile_horizontal_rev,
|
|
100
|
+
icon=get_icon("tile_h"),
|
|
101
|
+
shortcut="Ctrl+Alt+Down",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
cascade_act = action(
|
|
105
|
+
"&Cascade", self.cascadeSubWindows, icon=get_icon("cascade")
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
next_act = action(
|
|
109
|
+
"Ne&xt",
|
|
110
|
+
self.activateNextSubWindow,
|
|
111
|
+
shortcut=QtGui.QKeySequence.NextChild,
|
|
112
|
+
icon=get_icon("next"),
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
previous_act = action(
|
|
116
|
+
"Pre&vious",
|
|
117
|
+
self.activatePreviousSubWindow,
|
|
118
|
+
shortcut=QtGui.QKeySequence.PreviousChild,
|
|
119
|
+
icon=get_icon("prev"),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
separator_act = QtWidgets.QAction(self)
|
|
123
|
+
separator_act.setSeparator(True)
|
|
124
|
+
self.menu_actions = [
|
|
125
|
+
close_all_act,
|
|
126
|
+
close_others_act,
|
|
127
|
+
self.fullscreen_act,
|
|
128
|
+
separator_act,
|
|
129
|
+
tile_act,
|
|
130
|
+
tile_vert_act,
|
|
131
|
+
tile_horz_act,
|
|
132
|
+
tile_vert_rev_act,
|
|
133
|
+
tile_horz_rev_act,
|
|
134
|
+
cascade_act,
|
|
135
|
+
separator_act,
|
|
136
|
+
next_act,
|
|
137
|
+
previous_act,
|
|
138
|
+
]
|
|
139
|
+
self.addActions(self.menu_actions) # so shortcuts work
|
|
140
|
+
self._add_button_space()
|
|
141
|
+
|
|
142
|
+
def _add_button_space(self):
|
|
143
|
+
geometry = self._tab_bar.geometry()
|
|
144
|
+
if geometry.x() == 0:
|
|
145
|
+
btn_geometry = self._button.geometry()
|
|
146
|
+
x = btn_geometry.width()
|
|
147
|
+
geometry.setX(x)
|
|
148
|
+
self._tab_bar.setGeometry(geometry)
|
|
149
|
+
if geometry.height() == 0:
|
|
150
|
+
self.setViewportMargins(0, btn_geometry.height(), 0, 0)
|
|
151
|
+
|
|
152
|
+
def close_others(self):
|
|
153
|
+
w = self.currentSubWindow()
|
|
154
|
+
for window in self.subWindowList():
|
|
155
|
+
if window is not w:
|
|
156
|
+
window.close()
|
|
157
|
+
|
|
158
|
+
def fullscreen(self, state):
|
|
159
|
+
if state: # go fullscreen
|
|
160
|
+
self.splitter = self.parent()
|
|
161
|
+
self._splitter_state = self.splitter.saveState()
|
|
162
|
+
self.setParent(self.splitter.parent())
|
|
163
|
+
self.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint)
|
|
164
|
+
self.showFullScreen()
|
|
165
|
+
else:
|
|
166
|
+
self.setParent(self.splitter)
|
|
167
|
+
self.splitter.restoreState(self._splitter_state)
|
|
168
|
+
self.splitter = None
|
|
169
|
+
self.showNormal()
|
|
170
|
+
|
|
171
|
+
def add(self, window, new=False, icon=None):
|
|
172
|
+
if (
|
|
173
|
+
not new
|
|
174
|
+
and QtWidgets.QApplication.keyboardModifiers() != Qt.AltModifier
|
|
175
|
+
and self.activeSubWindow() is not None
|
|
176
|
+
):
|
|
177
|
+
self.closeActiveSubWindow()
|
|
178
|
+
window.setAttribute(Qt.WA_DeleteOnClose)
|
|
179
|
+
sub_window = self.addSubWindow(window)
|
|
180
|
+
sub_window.setAttribute(Qt.WA_DeleteOnClose)
|
|
181
|
+
sub_window.systemMenu().addActions(self.menu_actions)
|
|
182
|
+
sub_window.destroyed.connect(self.should_exit_fullscren)
|
|
183
|
+
|
|
184
|
+
if icon:
|
|
185
|
+
sub_window.setWindowIcon(get_icon(icon))
|
|
186
|
+
window.showMaximized()
|
|
187
|
+
self._add_button_space()
|
|
188
|
+
|
|
189
|
+
def tile_vertical_rev(self):
|
|
190
|
+
self.tile_vertical(True)
|
|
191
|
+
|
|
192
|
+
def tile_horizontal_rev(self):
|
|
193
|
+
self.tile_horizontal(True)
|
|
194
|
+
|
|
195
|
+
def tile_horizontal(self, reverse):
|
|
196
|
+
windows = self.subWindowList() # len(windows) != 0 always!
|
|
197
|
+
height = self.viewport().height() / len(windows)
|
|
198
|
+
x = 0
|
|
199
|
+
if reverse:
|
|
200
|
+
windows.reverse()
|
|
201
|
+
for window in windows:
|
|
202
|
+
window.showNormal()
|
|
203
|
+
window.resize(self.width(), height)
|
|
204
|
+
window.move(0, x)
|
|
205
|
+
x += height
|
|
206
|
+
|
|
207
|
+
def tile_vertical(self, reverse):
|
|
208
|
+
windows = self.subWindowList() # len(windows) != 0 always!
|
|
209
|
+
width = self.width() / len(windows)
|
|
210
|
+
x = 0
|
|
211
|
+
if reverse:
|
|
212
|
+
windows.reverse()
|
|
213
|
+
height = self.viewport().height()
|
|
214
|
+
for window in windows:
|
|
215
|
+
window.showNormal()
|
|
216
|
+
window.resize(width, height)
|
|
217
|
+
window.move(x, 0)
|
|
218
|
+
x += width
|
|
219
|
+
|
|
220
|
+
def closeEvent(self, event):
|
|
221
|
+
# Alt+F4 in fullscreen
|
|
222
|
+
self.fullscreen_act.setChecked(False)
|
|
223
|
+
event.ignore()
|
|
224
|
+
|
|
225
|
+
def resizeEvent(self, event):
|
|
226
|
+
super(MdiArea, self).resizeEvent(event)
|
|
227
|
+
self._add_button_space()
|
|
228
|
+
|
|
229
|
+
def should_exit_fullscren(self, _):
|
|
230
|
+
if not self.subWindowList():
|
|
231
|
+
self.fullscreen_act.setChecked(False)
|
|
232
|
+
|
|
233
|
+
def keyPressEvent(self, event):
|
|
234
|
+
# Not as action as `Ambiguous shortcut overload: Esc`
|
|
235
|
+
if event.key() == Qt.Key_Escape and self.isFullScreen():
|
|
236
|
+
self.fullscreen_act.setChecked(False)
|
|
237
|
+
else:
|
|
238
|
+
return QtWidgets.QMdiArea.keyPressEvent(self, event)
|
|
239
|
+
|
|
240
|
+
def eventFilter(self, obj, event):
|
|
241
|
+
# Trick to not steal focus from QDialog window
|
|
242
|
+
if (
|
|
243
|
+
event.type() in (event.KeyPress, event.KeyRelease)
|
|
244
|
+
and event.modifiers() & Qt.ControlModifier
|
|
245
|
+
):
|
|
246
|
+
parent = obj
|
|
247
|
+
for _level in range(6):
|
|
248
|
+
parent = parent.parent()
|
|
249
|
+
if parent is None:
|
|
250
|
+
break
|
|
251
|
+
if isinstance(parent, QtWidgets.QDialog):
|
|
252
|
+
return False
|
|
253
|
+
return super(MdiArea, self).eventFilter(obj, event)
|