An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authorede7fd2077
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# PamhyrWindow.py -- Pamhyr
# Copyright (C) 2023 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
import logging
from PyQt5.QtGui import (
QKeySequence,
)
from PyQt5.QtWidgets import (
QUndoStack, QShortcut,
)
from View.Tools.ASubWindow import ASubMainWindow, ASubWindow
from View.Tools.ListedSubWindow import ListedSubWindow
logger = logging.getLogger()
class PamhyrWindowTools(object):
def __init__(self, options = ["undo", "copy"], parent = None, **kwargs):
super(PamhyrWindowTools, self).__init__()
self._hash_data = []
self._undo_stack = None
if "undo" in options:
self._init_undo()
if "copy" in options:
self._init_copy()
# Undo/Redo
def _init_undo(self):
self._undo_stack = QUndoStack()
self._undo_sc = QShortcut(QKeySequence.Undo, self)
self._redo_sc = QShortcut(QKeySequence.Redo, self)
self._undo_sc.activated.connect(self._undo)
self._redo_sc.activated.connect(self._redo)
def _undo(self):
if self._undo_stack is not None:
self._undo_stack.undo()
self._update()
def _redo(self):
if self._undo_stack is not None:
self._undo_stack.redo()
self._update()
# Copy/Paste
def _init_copy(self):
self._copy_sc = QShortcut(QKeySequence.Copy, self)
self._paste_sc = QShortcut(QKeySequence.Paste, self)
self._copy_sc.activated.connect(self._copy)
self._paste_sc.activated.connect(self._paste)
def _copy(self):
if self._copy_stack is not None:
self._copy_stack.copy()
self._update()
def _paste(self):
if self._copy_stack is not None:
self._copy_stack.redo()
self._update()
# Display
def _set_title(self):
"""Apply `self._title` at current window title displayed
Returns:
Nothing
"""
self.ui.setWindowTitle(self._title)
def _update(self):
"""Update window display component
Returns:
Nothing
"""
self._set_title()
# Hash methods
@classmethod
def _hash(cls, data):
"""Compute window hash
Args:
data: window data parameters
Returns:
The hash
"""
hash_str = cls._pamhyr_name
hash_str += cls._pamhyr_ui
for el in data:
hash_str += repr(el)
h = hash(hash_str)
logger.debug(f"Compute hash = {h} for window {cls._pamhyr_name}")
return h
def hash(self):
"""Compute window hash
Returns:
The hash
"""
return self._hash(self._hash_data)
class PamhyrWindow(ASubMainWindow, ListedSubWindow, PamhyrWindowTools):
_pamhyr_ui = "dummy"
_pamhyr_name = "PamhyrWindow"
def __init__(self,
title = "Pamhyr2",
study = None, config = None,
options = ["undo", "copy"],
parent = None):
self._title = title
self._study = study
self._config = config
self._parent = parent
super(PamhyrWindow, self).__init__(
name = self._pamhyr_name,
ui = self._pamhyr_ui,
parent = parent,
)
self._hash_data.append(self._study)
self._hash_data.append(self._config)
self._set_title()
class PamhyrDialog(ASubWindow, ListedSubWindow, PamhyrWindowTools):
_pamhyr_ui = "dummy"
_pamhyr_name = "PamhyrWindow"
def __init__(self,
title = "Pamhyr2",
study = None, config = None,
options = ["undo", "copy"],
parent = None):
self._title = title
self._study = study
self._config = config
self._parent = parent
logger.info(self._pamhyr_name)
logger.info(self._pamhyr_ui)
super(PamhyrDialog, self).__init__(
name = self._pamhyr_name,
ui = self._pamhyr_ui,
parent = parent,
)
self._set_title()