processview 1.4.4__tar.gz → 1.5.1__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.
Files changed (41) hide show
  1. {processview-1.4.4 → processview-1.5.1}/PKG-INFO +3 -2
  2. {processview-1.4.4 → processview-1.5.1}/processview/core/manager/manager.py +12 -0
  3. processview-1.5.1/processview/gui/__init__.py +4 -0
  4. {processview-1.4.4 → processview-1.5.1}/processview/gui/processmanager.py +15 -5
  5. processview-1.5.1/processview/resources/gui/__init__.py +0 -0
  6. {processview-1.4.4 → processview-1.5.1}/processview/version.py +2 -2
  7. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/PKG-INFO +3 -2
  8. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/SOURCES.txt +1 -1
  9. processview-1.4.4/processview/gui/icons.py +0 -403
  10. processview-1.4.4/processview/resources/__init__.py +0 -277
  11. {processview-1.4.4 → processview-1.5.1}/LICENSE +0 -0
  12. {processview-1.4.4 → processview-1.5.1}/README.md +0 -0
  13. {processview-1.4.4 → processview-1.5.1}/processview/__init__.py +0 -0
  14. {processview-1.4.4 → processview-1.5.1}/processview/core/__init__.py +0 -0
  15. {processview-1.4.4 → processview-1.5.1}/processview/core/dataset.py +0 -0
  16. {processview-1.4.4 → processview-1.5.1}/processview/core/helpers.py +0 -0
  17. {processview-1.4.4 → processview-1.5.1}/processview/core/manager/__init__.py +0 -0
  18. {processview-1.4.4 → processview-1.5.1}/processview/core/manager/test/__init__.py +0 -0
  19. {processview-1.4.4 → processview-1.5.1}/processview/core/manager/test/test_manager.py +0 -0
  20. {processview-1.4.4 → processview-1.5.1}/processview/core/setup.py +0 -0
  21. {processview-1.4.4 → processview-1.5.1}/processview/core/sorting.py +0 -0
  22. {processview-1.4.4 → processview-1.5.1}/processview/core/superviseprocess.py +0 -0
  23. {processview-1.4.4 → processview-1.5.1}/processview/core/test/__init__.py +0 -0
  24. {processview-1.4.4 → processview-1.5.1}/processview/gui/DropDownWidget.py +0 -0
  25. {processview-1.4.4 → processview-1.5.1}/processview/gui/messagebox.py +0 -0
  26. {processview-1.4.4 → processview-1.5.1}/processview/gui/test/__init__.py +0 -0
  27. {processview-1.4.4 → processview-1.5.1}/processview/gui/test/test_process_manager.py +0 -0
  28. {processview-1.4.4/processview/gui → processview-1.5.1/processview/resources}/__init__.py +0 -0
  29. {processview-1.4.4 → processview-1.5.1}/processview/resources/gui/icons/advancement.png +0 -0
  30. {processview-1.4.4 → processview-1.5.1}/processview/resources/gui/icons/advancement.svg +0 -0
  31. {processview-1.4.4 → processview-1.5.1}/processview/resources/gui/icons/magnifying_glass.png +0 -0
  32. {processview-1.4.4 → processview-1.5.1}/processview/resources/gui/icons/magnifying_glass.svg +0 -0
  33. {processview-1.4.4 → processview-1.5.1}/processview/test/__init__.py +0 -0
  34. {processview-1.4.4 → processview-1.5.1}/processview/utils/__init__.py +0 -0
  35. {processview-1.4.4 → processview-1.5.1}/processview/utils/singleton.py +0 -0
  36. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/dependency_links.txt +0 -0
  37. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/requires.txt +0 -0
  38. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/top_level.txt +0 -0
  39. {processview-1.4.4 → processview-1.5.1}/processview.egg-info/zip-safe +0 -0
  40. {processview-1.4.4 → processview-1.5.1}/setup.cfg +0 -0
  41. {processview-1.4.4 → processview-1.5.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: processview
3
- Version: 1.4.4
3
+ Version: 1.5.1
4
4
  Summary: Simple helper to provide user feedback about dataset processing
5
5
  Author: data analysis unit
6
6
  Author-email: henri.payno@esrf.fr
@@ -35,3 +35,4 @@ Provides-Extra: full
35
35
  Requires-Dist: Sphinx; extra == "full"
36
36
  Requires-Dist: pytest; extra == "full"
37
37
  Requires-Dist: PyQt5; extra == "full"
38
+ Dynamic: license-file
@@ -44,6 +44,8 @@ class ProcessManager:
44
44
  """list of callback to trigger when a process is added"""
45
45
  self._processRemovedCallback = set()
46
46
  """list of callback to trigger when a process is removed"""
47
+ self._process_renamed_callback = set()
48
+ """list of callback to trigger when a process is renamed"""
47
49
  self.lock = threading.Lock()
48
50
 
49
51
  def met(self, process, dataset) -> bool:
@@ -57,6 +59,13 @@ class ProcessManager:
57
59
  if process.process_id in self._dataset_process_states:
58
60
  return dataset_id in self._dataset_process_states[process.process_id]
59
61
 
62
+ def process_renamed(self, process):
63
+ """
64
+ the process name only matter for the GUI side
65
+ """
66
+ for callback in self._process_renamed_callback:
67
+ callback(process)
68
+
60
69
  def register(self, process) -> int:
61
70
  """
62
71
  Register a process to the manager
@@ -351,6 +360,9 @@ class ProcessManager:
351
360
  if callback in self._processRemovedCallback:
352
361
  self._processRemovedCallback.remove(callback)
353
362
 
363
+ def add_process_name_changed_callback(self, callback):
364
+ self._process_renamed_callback.add(callback)
365
+
354
366
  def clear(self):
355
367
  """
356
368
  clear registered processes and dataset states
@@ -0,0 +1,4 @@
1
+ from silx import resources as _silx_resources # noqa
2
+
3
+ # Add processview resources to silx resource management
4
+ _silx_resources.register_resource_directory("processview", "processview.resources")
@@ -13,7 +13,7 @@ from processview.core.manager import ProcessManager as _ProcessManager
13
13
  from processview.core.sorting import SortType, tooltips
14
14
  from processview.core.superviseprocess import SuperviseProcess
15
15
  from processview.gui.DropDownWidget import DropDownWidget
16
- from processview.gui import icons as icons
16
+ from silx.gui import icons
17
17
  from processview.gui.messagebox import MessageBox
18
18
  from processview.utils import docstring
19
19
 
@@ -215,6 +215,7 @@ class ProcessManagerWidget(qt.QWidget):
215
215
  self._optionsWidget._orderingWidget.sigSortTypeChanged.connect(
216
216
  self.observationTable.model()._setSorting
217
217
  )
218
+ self._manager.sigProcessRenamed.connect(self._renameProcess)
218
219
  # update to fit existing processes / datasets
219
220
  self._updateProcesses()
220
221
  self._updateDatasetStates()
@@ -225,6 +226,11 @@ class ProcessManagerWidget(qt.QWidget):
225
226
  def _updateProcesses(self):
226
227
  self.observationTable.model().setProcesses(self._manager.get_processes())
227
228
 
229
+ def _renameProcess(self, process: SuperviseProcess):
230
+ self.observationTable.model().headerDataChanged.emit(
231
+ qt.Qt.Horizontal, 0, len(self._manager.get_processes())
232
+ )
233
+
228
234
  def _filterUpdated(self):
229
235
  self.observationTable.model().process_patterns = (
230
236
  self._dropDownOptionsWidget.getProcessPatterns()
@@ -477,9 +483,9 @@ class _FilterWidget(qt.QWidget):
477
483
  font.setPixelSize(font_size)
478
484
  self.setFont(font)
479
485
 
480
- icon = icons.getQIcon("magnifying_glass")
486
+ icon = icons.getQPixmap("processview:gui/icons/magnifying_glass")
481
487
  self._researchLabelIcon = qt.QLabel("", parent=self)
482
- self._researchLabelIcon.setPixmap(icon.pixmap(icon_size, state=qt.QIcon.On))
488
+ self._researchLabelIcon.setPixmap(icon)
483
489
  self.layout().addWidget(qt.QLabel(name, self), 0, 1, 1, 1)
484
490
  self.layout().addWidget(self._researchLabelIcon, 0, 2, 1, 1)
485
491
 
@@ -599,6 +605,9 @@ class ProcessManager(qt.QObject):
599
605
  sigProcessUnregistered = qt.Signal()
600
606
  """Signal emitted when a process is unregistered"""
601
607
 
608
+ sigProcessRenamed = qt.Signal(SuperviseProcess)
609
+ """Emit when the process is renamed"""
610
+
602
611
  def __init__(self):
603
612
  qt.QObject.__init__(self)
604
613
  self.manager = _ProcessManager()
@@ -608,6 +617,7 @@ class ProcessManager(qt.QObject):
608
617
  self.manager.add_update_callback(self.updated)
609
618
  self.manager.add_new_process_callback(self.processAdded)
610
619
  self.manager.add_process_removed_callback(self.processRemoved)
620
+ self.manager.add_process_name_changed_callback(self.processRenamed)
611
621
 
612
622
  def updated(self):
613
623
  self.sigUpdated.emit()
@@ -618,8 +628,8 @@ class ProcessManager(qt.QObject):
618
628
  def processRemoved(self):
619
629
  self.sigProcessUnregistered.emit()
620
630
 
621
- def processNameChanged(self, process):
622
- self.sigProcessNameChanged.emit(process)
631
+ def processRenamed(self, process):
632
+ self.sigProcessRenamed.emit(process)
623
633
 
624
634
  def destroyed(self, object_):
625
635
  self.manager.remove_update_callback(self.updated)
@@ -76,8 +76,8 @@ RELEASE_LEVEL_VALUE = {
76
76
  }
77
77
 
78
78
  MAJOR = 1
79
- MINOR = 4
80
- MICRO = 4
79
+ MINOR = 5
80
+ MICRO = 1
81
81
  RELEV = "final" # <16
82
82
  SERIAL = 0 # <16
83
83
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: processview
3
- Version: 1.4.4
3
+ Version: 1.5.1
4
4
  Summary: Simple helper to provide user feedback about dataset processing
5
5
  Author: data analysis unit
6
6
  Author-email: henri.payno@esrf.fr
@@ -35,3 +35,4 @@ Provides-Extra: full
35
35
  Requires-Dist: Sphinx; extra == "full"
36
36
  Requires-Dist: pytest; extra == "full"
37
37
  Requires-Dist: PyQt5; extra == "full"
38
+ Dynamic: license-file
@@ -23,12 +23,12 @@ processview/core/manager/test/test_manager.py
23
23
  processview/core/test/__init__.py
24
24
  processview/gui/DropDownWidget.py
25
25
  processview/gui/__init__.py
26
- processview/gui/icons.py
27
26
  processview/gui/messagebox.py
28
27
  processview/gui/processmanager.py
29
28
  processview/gui/test/__init__.py
30
29
  processview/gui/test/test_process_manager.py
31
30
  processview/resources/__init__.py
31
+ processview/resources/gui/__init__.py
32
32
  processview/resources/gui/icons/advancement.png
33
33
  processview/resources/gui/icons/advancement.svg
34
34
  processview/resources/gui/icons/magnifying_glass.png
@@ -1,403 +0,0 @@
1
- # coding: utf-8
2
- # /*##########################################################################
3
- #
4
- # Copyright (c) 2016 European Synchrotron Radiation Facility
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- #
24
- # ###########################################################################*/
25
- """Set of icons for buttons.
26
-
27
- Use :func:`getQIcon` to create Qt QIcon from the name identifying an icon.
28
- """
29
-
30
- __authors__ = ["T. Vincent"]
31
- __license__ = "MIT"
32
- __date__ = "06/09/2017"
33
-
34
-
35
- import os
36
- import logging
37
- import weakref
38
- from silx.gui import qt
39
- import processview.resources
40
- from silx.utils import weakref as silxweakref
41
- from silx.utils.deprecation import deprecated
42
-
43
-
44
- _logger = logging.getLogger(__name__)
45
- """Module logger"""
46
-
47
-
48
- _cached_icons = weakref.WeakValueDictionary()
49
- """Cache loaded icons in a weak structure"""
50
-
51
-
52
- _supported_formats = None
53
- """Order of file format extension to check"""
54
-
55
-
56
- class AbstractAnimatedIcon(qt.QObject):
57
- """Store an animated icon.
58
-
59
- It provides an event containing the new icon everytime it is updated."""
60
-
61
- def __init__(self, parent=None):
62
- """Constructor
63
-
64
- :param qt.QObject parent: Parent of the QObject
65
- :raises: ValueError when name is not known
66
- """
67
- qt.QObject.__init__(self, parent)
68
-
69
- self.__targets = silxweakref.WeakList()
70
- self.__currentIcon = None
71
-
72
- iconChanged = qt.Signal(qt.QIcon)
73
- """Signal sent with a QIcon everytime the animation changed."""
74
-
75
- def register(self, obj):
76
- """Register an object to the AnimatedIcon.
77
- If no object are registred, the animation is paused.
78
- Object are stored in a weaked list.
79
-
80
- :param object obj: An object
81
- """
82
- if obj not in self.__targets:
83
- self.__targets.append(obj)
84
- self._updateState()
85
-
86
- def unregister(self, obj):
87
- """Remove the object from the registration.
88
- If no object are registred the animation is paused.
89
-
90
- :param object obj: A registered object
91
- """
92
- if obj in self.__targets:
93
- self.__targets.remove(obj)
94
- self._updateState()
95
-
96
- def hasRegistredObjects(self):
97
- """Returns true if any object is registred.
98
-
99
- :rtype: bool
100
- """
101
- return len(self.__targets)
102
-
103
- def isRegistered(self, obj):
104
- """Returns true if the object is registred in the AnimatedIcon.
105
-
106
- :param object obj: An object
107
- :rtype: bool
108
- """
109
- return obj in self.__targets
110
-
111
- def currentIcon(self):
112
- """Returns the icon of the current frame.
113
-
114
- :rtype: qt.QIcon
115
- """
116
- return self.__currentIcon
117
-
118
- def _updateState(self):
119
- """Update the object according to the connected objects."""
120
- pass
121
-
122
- def _setCurrentIcon(self, icon):
123
- """Store the current icon and emit a `iconChanged` event.
124
-
125
- :param qt.QIcon icon: The current icon
126
- """
127
- self.__currentIcon = icon
128
- self.iconChanged.emit(self.__currentIcon)
129
-
130
-
131
- class MovieAnimatedIcon(AbstractAnimatedIcon):
132
- """Store a looping QMovie to provide icons for each frames.
133
- Provides an event with the new icon everytime the movie frame
134
- is updated."""
135
-
136
- def __init__(self, filename, parent=None):
137
- """Constructor
138
-
139
- :param str filename: An icon name to an animated format
140
- :param qt.QObject parent: Parent of the QObject
141
- :raises: ValueError when name is not known
142
- """
143
- AbstractAnimatedIcon.__init__(self, parent)
144
-
145
- qfile = getQFile(filename)
146
- self.__movie = qt.QMovie(qfile.fileName(), qt.QByteArray(), parent)
147
- self.__movie.setCacheMode(qt.QMovie.CacheAll)
148
- self.__movie.frameChanged.connect(self.__frameChanged)
149
- self.__cacheIcons = {}
150
-
151
- self.__movie.jumpToFrame(0)
152
- self.__updateIconAtFrame(0)
153
-
154
- def __frameChanged(self, frameId):
155
- """Callback everytime the QMovie frame change
156
- :param int frameId: Current frame id
157
- """
158
- self.__updateIconAtFrame(frameId)
159
-
160
- def __updateIconAtFrame(self, frameId):
161
- """
162
- Update the current stored QIcon
163
-
164
- :param int frameId: Current frame id
165
- """
166
- if frameId in self.__cacheIcons:
167
- icon = self.__cacheIcons[frameId]
168
- else:
169
- icon = qt.QIcon(self.__movie.currentPixmap())
170
- self.__cacheIcons[frameId] = icon
171
- self._setCurrentIcon(icon)
172
-
173
- def _updateState(self):
174
- """Update the movie play according to internal stat of the
175
- AnimatedIcon."""
176
- self.__movie.setPaused(not self.hasRegistredObjects())
177
-
178
-
179
- class MultiImageAnimatedIcon(AbstractAnimatedIcon):
180
- """Store a looping QMovie to provide icons for each frames.
181
- Provides an event with the new icon everytime the movie frame
182
- is updated."""
183
-
184
- def __init__(self, filename, parent=None):
185
- """Constructor
186
-
187
- :param str filename: An icon name to an animated format
188
- :param qt.QObject parent: Parent of the QObject
189
- :raises: ValueError when name is not known
190
- """
191
- AbstractAnimatedIcon.__init__(self, parent)
192
-
193
- self.__frames = []
194
- for i in range(100):
195
- try:
196
- pixmap = getQPixmap("%s/%02d" % (filename, i))
197
- except ValueError:
198
- break
199
- icon = qt.QIcon(pixmap)
200
- self.__frames.append(icon)
201
-
202
- if len(self.__frames) == 0:
203
- raise ValueError("Animated icon '%s' do not exists" % filename)
204
-
205
- self.__frameId = -1
206
- self.__timer = qt.QTimer(self)
207
- self.__timer.timeout.connect(self.__increaseFrame)
208
- self.__updateIconAtFrame(0)
209
-
210
- def __increaseFrame(self):
211
- """Callback called every timer timeout to change the current frame of
212
- the animation
213
- """
214
- frameId = (self.__frameId + 1) % len(self.__frames)
215
- self.__updateIconAtFrame(frameId)
216
-
217
- def __updateIconAtFrame(self, frameId):
218
- """
219
- Update the current stored QIcon
220
-
221
- :param int frameId: Current frame id
222
- """
223
- self.__frameId = frameId
224
- icon = self.__frames[frameId]
225
- self._setCurrentIcon(icon)
226
-
227
- def _updateState(self):
228
- """Update the object to wake up or sleep it according to its use."""
229
- if self.hasRegistredObjects():
230
- if not self.__timer.isActive():
231
- self.__timer.start(100)
232
- else:
233
- if self.__timer.isActive():
234
- self.__timer.stop()
235
-
236
-
237
- class AnimatedIcon(MovieAnimatedIcon):
238
- """Store a looping QMovie to provide icons for each frames.
239
- Provides an event with the new icon everytime the movie frame
240
- is updated.
241
-
242
- It may not be available anymore for the silx release 0.6.
243
-
244
- .. deprecated:: 0.5
245
- Use :class:`MovieAnimatedIcon` instead.
246
- """
247
-
248
- @deprecated
249
- def __init__(self, filename, parent=None):
250
- MovieAnimatedIcon.__init__(self, filename, parent=parent)
251
-
252
-
253
- def getWaitIcon():
254
- """Returns a cached version of the waiting AbstractAnimatedIcon.
255
-
256
- :rtype: AbstractAnimatedIcon
257
- """
258
- return getAnimatedIcon("process-working")
259
-
260
-
261
- def getAnimatedIcon(name):
262
- """Create an AbstractAnimatedIcon from a resource name.
263
-
264
- The resource name can be prefixed by the name of a resource directory. For
265
- example "silx:foo.png" identify the resource "foo.png" from the resource
266
- directory "silx".
267
-
268
- If no prefix are specified, the file with be returned from the silx
269
- resource directory with a specific path "gui/icons".
270
-
271
- See also :func:`silx.resources.register_resource_directory`.
272
-
273
- Try to load a mng or a gif file, then try to load a multi-image animated
274
- icon.
275
-
276
- In Qt5 mng or gif are not used, because the transparency is not very well
277
- managed.
278
-
279
- :param str name: Name of the icon, in one of the defined icons
280
- in this module.
281
- :return: Corresponding AbstractAnimatedIcon
282
- :raises: ValueError when name is not known
283
- """
284
- key = name + "__anim"
285
- if key not in _cached_icons:
286
- qtMajorVersion = int(qt.qVersion().split(".")[0])
287
- icon = None
288
-
289
- # ignore mng and gif in Qt5
290
- if qtMajorVersion != 5:
291
- try:
292
- icon = MovieAnimatedIcon(name)
293
- except ValueError:
294
- icon = None
295
-
296
- if icon is None:
297
- try:
298
- icon = MultiImageAnimatedIcon(name)
299
- except ValueError:
300
- icon = None
301
-
302
- if icon is None:
303
- raise ValueError("Not an animated icon name: %s", name)
304
-
305
- _cached_icons[key] = icon
306
- else:
307
- icon = _cached_icons[key]
308
- return icon
309
-
310
-
311
- def getQIcon(name):
312
- """Create a QIcon from its name.
313
-
314
- The resource name can be prefixed by the name of a resource directory. For
315
- example "silx:foo.png" identify the resource "foo.png" from the resource
316
- directory "silx".
317
-
318
- If no prefix are specified, the file with be returned from the silx
319
- resource directory with a specific path "gui/icons".
320
-
321
- See also :func:`silx.resources.register_resource_directory`.
322
-
323
- :param str name: Name of the icon, in one of the defined icons
324
- in this module.
325
- :return: Corresponding QIcon
326
- :raises: ValueError when name is not known
327
- """
328
- if name not in _cached_icons:
329
- qfile = getQFile(name)
330
- pixmap = qt.QPixmap(qfile.fileName())
331
- icon = qt.QIcon(pixmap)
332
- _cached_icons[name] = icon
333
- else:
334
- icon = _cached_icons[name]
335
- return icon
336
-
337
-
338
- def getQPixmap(name):
339
- """Create a QPixmap from its name.
340
-
341
- The resource name can be prefixed by the name of a resource directory. For
342
- example "silx:foo.png" identify the resource "foo.png" from the resource
343
- directory "silx".
344
-
345
- If no prefix are specified, the file with be returned from the silx
346
- resource directory with a specific path "gui/icons".
347
-
348
- See also :func:`silx.resources.register_resource_directory`.
349
-
350
- :param str name: Name of the icon, in one of the defined icons
351
- in this module.
352
- :return: Corresponding QPixmap
353
- :raises: ValueError when name is not known
354
- """
355
- qfile = getQFile(name)
356
- return qt.QPixmap(qfile.fileName())
357
-
358
-
359
- def getQFile(name):
360
- """Create a QFile from an icon name. Filename is found
361
- according to supported Qt formats.
362
-
363
- The resource name can be prefixed by the name of a resource directory. For
364
- example "silx:foo.png" identify the resource "foo.png" from the resource
365
- directory "silx".
366
-
367
- If no prefix are specified, the file with be returned from the silx
368
- resource directory with a specific path "gui/icons".
369
-
370
- See also :func:`silx.resources.register_resource_directory`.
371
-
372
- :param str name: Name of the icon, in one of the defined icons
373
- in this module.
374
- :return: Corresponding QFile
375
- :rtype: qt.QFile
376
- :raises: ValueError when name is not known
377
- """
378
- global _supported_formats
379
- if _supported_formats is None:
380
- _supported_formats = []
381
- supported_formats = qt.supportedImageFormats()
382
- order = ["svg", "png", "jpg"]
383
- for format_ in order:
384
- if format_ in supported_formats:
385
- _supported_formats.append(format_)
386
- if len(_supported_formats) == 0:
387
- _logger.error("No format supported for icons")
388
- else:
389
- _logger.debug("Format %s supported", ", ".join(_supported_formats))
390
-
391
- for format_ in _supported_formats:
392
- format_ = str(format_)
393
- filename = processview.resources._resource_filename(
394
- "%s.%s" % (name, format_), default_directory=os.path.join("gui", "icons")
395
- )
396
- qfile = qt.QFile(filename)
397
- if qfile.exists():
398
- return qfile
399
- elif os.path.exists(filename):
400
- mess = filename + " exists, but is not supported by qt"
401
- _logger.warning(mess)
402
-
403
- raise ValueError("Not an icon name: %s" % name)
@@ -1,277 +0,0 @@
1
- # coding: utf-8
2
- # /*##########################################################################
3
- #
4
- # Copyright (c) 2016-2017 European Synchrotron Radiation Facility
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- #
24
- # ###########################################################################*/
25
- """Access project's data and documentation files.
26
-
27
- All access to data and documentation files MUST be made through the functions
28
- of this modules to ensure access across different distribution schemes:
29
-
30
- - Installing from source or from wheel
31
- - Installing package as a zip (through the use of pkg_resources)
32
- - Linux packaging willing to install data files (and doc files) in
33
- alternative folders. In this case, this file must be patched.
34
- - Frozen fat binary application using silx (frozen with cx_Freeze or py2app).
35
- This needs special care for the resource files in the setup:
36
-
37
- - With cx_Freeze, add silx/resources to include_files:
38
-
39
- .. code-block:: python
40
-
41
- import silx.resources
42
- silx_include_files = (os.path.dirname(silx.resources.__file__),
43
- os.path.join('silx', 'resources'))
44
- setup(...
45
- options={'build_exe': {'include_files': [silx_include_files]}}
46
- )
47
-
48
- - With py2app, add silx in the packages list of the py2app options:
49
-
50
- .. code-block:: python
51
-
52
- setup(...
53
- options={'py2app': {'packages': ['silx']}}
54
- )
55
- """
56
-
57
- __authors__ = ["V.A. Sole", "Thomas Vincent", "J. Kieffer"]
58
- __license__ = "MIT"
59
- __date__ = "06/09/2017"
60
-
61
-
62
- import os
63
- import sys
64
- import threading
65
- import json
66
- import getpass
67
- import logging
68
- import tempfile
69
- import unittest
70
- import importlib
71
-
72
- logger = logging.getLogger(__name__)
73
-
74
-
75
- # pkg_resources is useful when this package is stored in a zip
76
- # When pkg_resources is not available, the resources dir defaults to the
77
- # directory containing this module.
78
- try:
79
- import pkg_resources
80
- except ImportError:
81
- pkg_resources = None
82
-
83
-
84
- # For packaging purpose, patch this variable to use an alternative directory
85
- # E.g., replace with _RESOURCES_DIR = '/usr/share/silx/data'
86
- _RESOURCES_DIR = None
87
-
88
- # For packaging purpose, patch this variable to use an alternative directory
89
- # E.g., replace with _RESOURCES_DIR = '/usr/share/silx/doc'
90
- # Not in use, uncomment when functionality is needed
91
- # _RESOURCES_DOC_DIR = None
92
-
93
- # cx_Freeze frozen support
94
- # See http://cx-freeze.readthedocs.io/en/latest/faq.html#using-data-files
95
- if getattr(sys, "frozen", False):
96
- # Running in a frozen application:
97
- # We expect resources to be located either in a silx/resources/ dir
98
- # relative to the executable or within this package.
99
- _dir = os.path.join(os.path.dirname(sys.executable), "tomwer", "resources")
100
- if os.path.isdir(_dir):
101
- _RESOURCES_DIR = _dir
102
-
103
-
104
- class _ResourceDirectory(object):
105
- """Store a source of resources"""
106
-
107
- def __init__(self, package_name, package_path=None, forced_path=None):
108
- if forced_path is None:
109
- if package_path is None:
110
- if pkg_resources is None:
111
- # In this case we have to compute the package path
112
- # Else it will not be used
113
- module = importlib.import_module(package_name)
114
- package_path = os.path.abspath(os.path.dirname(module.__file__))
115
- self.package_name = package_name
116
- self.package_path = package_path
117
- self.forced_path = forced_path
118
-
119
-
120
- _TOMWER_DIRECTORY = _ResourceDirectory(
121
- package_name=__name__,
122
- package_path=os.path.abspath(os.path.dirname(__file__)),
123
- forced_path=_RESOURCES_DIR,
124
- )
125
-
126
- _RESOURCE_DIRECTORIES = {}
127
- _RESOURCE_DIRECTORIES["tomwer"] = _TOMWER_DIRECTORY
128
-
129
-
130
- def register_resource_directory(name, package_name, forced_path=None):
131
- """Register another resource directory to the available list.
132
-
133
- By default only the directory "silx" is available.
134
-
135
- .. versionadded:: 0.6
136
-
137
- :param str name: Name of the resource directory. It is used on the resource
138
- name to specify the resource directory to use. The resource
139
- "silx:foo.png" will use the "silx" resource directory.
140
- :param str package_name: Python name of the package containing resources.
141
- For example "silx.resources".
142
- :param str forced_path: Path containing the resources. If specified
143
- `pkg_resources` nor `package_name` will be used
144
- For example "silx.resources".
145
- :raises ValueError: If the resource directory name already exists.
146
- """
147
- if name in _RESOURCE_DIRECTORIES:
148
- raise ValueError("Resource directory name %s already exists" % name)
149
- resource_directory = _ResourceDirectory(
150
- package_name=package_name, forced_path=forced_path
151
- )
152
- _RESOURCE_DIRECTORIES[name] = resource_directory
153
-
154
-
155
- def list_dir(resource):
156
- """List the content of a resource directory.
157
-
158
- Result are not prefixed by the resource name.
159
-
160
- The resource name can be prefixed by the name of a resource directory. For
161
- example "silx:foo.png" identify the resource "foo.png" from the resource
162
- directory "silx". See also :func:`register_resource_directory`.
163
-
164
- :param str resource: Name of the resource directory to list
165
- :return: list of name contained in the directory
166
- :rtype: list
167
- """
168
- resource_directory, resource_name = _get_package_and_resource(resource)
169
-
170
- if resource_directory.forced_path is not None:
171
- # if set, use this directory
172
- path = resource_filename(resource)
173
- return os.listdir(path)
174
- elif pkg_resources is None:
175
- # Fallback if pkg_resources is not available
176
- path = resource_filename(resource)
177
- return os.listdir(path)
178
- else:
179
- # Preferred way to get resources as it supports zipfile package
180
- package_name = resource_directory.package_name
181
- return pkg_resources.resource_listdir(package_name, resource_name)
182
-
183
-
184
- def is_dir(resource):
185
- """True is the resource is a resource directory.
186
-
187
- The resource name can be prefixed by the name of a resource directory. For
188
- example "silx:foo.png" identify the resource "foo.png" from the resource
189
- directory "silx". See also :func:`register_resource_directory`.
190
-
191
- :param str resource: Name of the resource
192
- :rtype: bool
193
- """
194
- path = resource_filename(resource)
195
- return os.path.isdir(path)
196
-
197
-
198
- def _get_package_and_resource(resource, default_directory=None):
199
- """
200
- Return the resource directory class and a cleaned resource name without
201
- prefix.
202
-
203
- :param str: resource: Name of the resource with resource prefix.
204
- :param str default_directory: If the resource is not prefixed, the resource
205
- will be searched on this default directory of the silx resource
206
- directory.
207
- :rtype: tuple(_ResourceDirectory, str)
208
- :raises ValueError: If the resource name uses an unregistred resource
209
- directory name
210
- """
211
- if ":" in resource:
212
- prefix, resource = resource.split(":", 1)
213
- else:
214
- prefix = "tomwer"
215
- if default_directory is not None:
216
- resource = os.path.join(default_directory, resource)
217
- if prefix not in _RESOURCE_DIRECTORIES:
218
- raise ValueError("Resource '%s' uses an unregistred prefix", resource)
219
- resource_directory = _RESOURCE_DIRECTORIES[prefix]
220
- return resource_directory, resource
221
-
222
-
223
- def resource_filename(resource):
224
- """Return filename corresponding to resource.
225
-
226
- The existence of the resource is not checked.
227
-
228
- The resource name can be prefixed by the name of a resource directory. For
229
- example "silx:foo.png" identify the resource "foo.png" from the resource
230
- directory "silx". See also :func:`register_resource_directory`.
231
-
232
- :param str resource: Resource path relative to resource directory
233
- using '/' path separator. It can be either a file or
234
- a directory.
235
- :raises ValueError: If the resource name uses an unregistred resource
236
- directory name
237
- :return: Absolute resource path in the file system
238
- :rtype: str
239
- """
240
- return _resource_filename(resource, default_directory=None)
241
-
242
-
243
- def _resource_filename(resource, default_directory=None):
244
- """Return filename corresponding to resource.
245
-
246
- The existence of the resource is not checked.
247
-
248
- The resource name can be prefixed by the name of a resource directory. For
249
- example "silx:foo.png" identify the resource "foo.png" from the resource
250
- directory "silx". See also :func:`register_resource_directory`.
251
-
252
- :param str resource: Resource path relative to resource directory
253
- using '/' path separator. It can be either a file or
254
- a directory.
255
- :param str default_directory: If the resource is not prefixed, the resource
256
- will be searched on this default directory of the silx resource
257
- directory. It should only be used internally by silx.
258
- :return: Absolute resource path in the file system
259
- :rtype: str
260
- """
261
- resource_directory, resource_name = _get_package_and_resource(
262
- resource, default_directory=default_directory
263
- )
264
- if resource_directory.forced_path is not None:
265
- # if set, use this directory
266
- base_dir = resource_directory.forced_path
267
- resource_path = os.path.join(base_dir, *resource_name.split("/"))
268
- return resource_path
269
- elif pkg_resources is None:
270
- # Fallback if pkg_resources is not available
271
- base_dir = resource_directory.package_path
272
- resource_path = os.path.join(base_dir, *resource_name.split("/"))
273
- return resource_path
274
- else:
275
- # Preferred way to get resources as it supports zipfile package
276
- package_name = resource_directory.package_name
277
- return pkg_resources.resource_filename(package_name, resource_name)
File without changes
File without changes
File without changes
File without changes