Commit 401a35434f6ed04223616e0d8304883b607778cf
1 parent
447a269e
Exists in
master
and in
68 other branches
ADD: Draft classes for controlling mode and session configuration
Showing
3 changed files
with
145 additions
and
0 deletions
Show diff stats
.gitattributes
... | ... | @@ -131,6 +131,7 @@ invesalius/gui/widgets/gradient.py -text |
131 | 131 | invesalius/gui/widgets/listctrl.py -text |
132 | 132 | invesalius/gui/widgets/slice_menu.py -text |
133 | 133 | invesalius/invesalius.py -text |
134 | +invesalius/mode.py -text | |
134 | 135 | invesalius/presets.py -text |
135 | 136 | invesalius/project.py -text |
136 | 137 | invesalius/reader/__init__.py -text |
... | ... | @@ -138,6 +139,7 @@ invesalius/reader/analyze_reader.py -text |
138 | 139 | invesalius/reader/dicom.py -text |
139 | 140 | invesalius/reader/dicom_grouper.py -text |
140 | 141 | invesalius/reader/dicom_reader.py -text |
142 | +invesalius/session.py -text | |
141 | 143 | invesalius/utils.py -text |
142 | 144 | presets/raycasting/Airways[!!-~]II.plist -text |
143 | 145 | presets/raycasting/Airways.plist -text | ... | ... |
... | ... | @@ -0,0 +1,110 @@ |
1 | +# mode.py | |
2 | +# to be instanced inside Controller (control.py) | |
3 | + | |
4 | + | |
5 | +# TODO: Add to constants.py: | |
6 | +#-------------------- | |
7 | +# SLICE MODE | |
8 | +SLICE_STATE_DEFAULT = 0 | |
9 | +SLICE_STATE_EDITOR = 1 | |
10 | +SLICE_STATE_WL = 2 | |
11 | +SLICE_STATE_SPIN = 3 | |
12 | +SLICE_STATE_ZOOM = 4 | |
13 | +SLICE_STATE_ZOOM_SL = 5 | |
14 | +# IMPORTANT: When adding a new state, remember o insert it into LEVEL | |
15 | +# dictionary | |
16 | + | |
17 | + | |
18 | +# RULE: | |
19 | +# default is the only level 0 | |
20 | +# states controlled somehow by taskmenu are level 1 | |
21 | +# states controlled by toolbar are level 2 | |
22 | +LEVEL = {SLICE_STATE_DEFAULT: 0, | |
23 | + SLICE_STATE_EDITOR: 1, | |
24 | + SLICE_STATE_WL: 2, | |
25 | + SLICE_STATE_SPIN: 2, | |
26 | + SLICE_STATE_ZOOM: 2, | |
27 | + SLICE_STATE_ZOOM_SL: 2} | |
28 | +#---------------------- | |
29 | +# TODO: Add to viewer_slice.py: | |
30 | + | |
31 | + ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode') | |
32 | + | |
33 | +def OnSetMode(self, pubsub_evt): | |
34 | + mode = pubsub_evt.data | |
35 | + # according to mode, set cursor, interaction, etc | |
36 | +#---------------------- | |
37 | +# TODO: Add GUI classes (frame, tasks related to slice, toolbar): | |
38 | + | |
39 | +# always bind to this class (regarding slice mode) and not to | |
40 | +# viewer_slice directly | |
41 | + | |
42 | +# example - pseudo code | |
43 | +def OnToggleButtonSpin(self, evt) | |
44 | + if evt.toggle: # doesn't exist, just to illustrate | |
45 | + ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM) | |
46 | + else: | |
47 | + ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM) | |
48 | + | |
49 | + | |
50 | +#---------------------- | |
51 | + | |
52 | + | |
53 | +import constants as const | |
54 | + | |
55 | +class SliceMode(object): | |
56 | +# don't need to be singleton, only needs to be instantiated inside | |
57 | +# (Controller) self.slice_mode = SliceMode() | |
58 | + | |
59 | + def __init__(self): | |
60 | + self.stack = {} | |
61 | + | |
62 | + # push default value to stack | |
63 | + self.stack[const.LEVEL[const.SLICE_STATE_DEFAULT]] = \ | |
64 | + const.SLICE_STATE_DEFAULT | |
65 | + | |
66 | + # bind pubsub evt | |
67 | + self.bind_events() | |
68 | + | |
69 | + def _bind_events(self): | |
70 | + ps.Publisher().subscribe(self.OnEnableState, 'Enable mode') | |
71 | + ps.Publisher().subscribe(self.OnDisableState, 'Disable mode') | |
72 | + | |
73 | + def OnEnableState(self, pubsub_evt): | |
74 | + state = pubsub_evt.data | |
75 | + self.AddState(state) | |
76 | + | |
77 | + def OnDisableState(self, pubsub_evt): | |
78 | + state = pubsub_evt.data | |
79 | + self.RemoveState(state) | |
80 | + | |
81 | + def AddState(self, state): | |
82 | + level = const.LEVEL[state] | |
83 | + max_level = max(self.stack.keys()) | |
84 | + | |
85 | + # Insert new state into stack | |
86 | + self.stack[level] = state | |
87 | + | |
88 | + # Only will affect InVesalius behaviour if it is the highest | |
89 | + # level in stack | |
90 | + if level == max_level: | |
91 | + # let viewer slice and other classes know this | |
92 | + # change (cursor, interaction, etc) | |
93 | + ps.Publisher().sendMessage('Set slice mode', state) | |
94 | + | |
95 | + def RemoveState(self, state): | |
96 | + level = const.LEVEL[state] | |
97 | + max_level = max(self.stack.keys()) | |
98 | + | |
99 | + # Remove item from stack | |
100 | + self.stack.popitem(level) | |
101 | + | |
102 | + # New max level | |
103 | + new_max_level = max(self.stack.keys()) | |
104 | + | |
105 | + # Only will affect InVesalius behaviour if the highest | |
106 | + # level in stack has been removed | |
107 | + if level == max_level: | |
108 | + new_state = self.stack[new_max_level] | |
109 | + ps.Publisher().sendMessage('Set slice mode', state) | |
110 | + | ... | ... |
... | ... | @@ -0,0 +1,33 @@ |
1 | +# session.py | |
2 | + | |
3 | + | |
4 | +class Session(object) | |
5 | + def __init__(self): | |
6 | + self.project_state = const.PROJ_FREE | |
7 | + # const.PROJ_FREE | |
8 | + # const.PROJ_OPEN | |
9 | + # const.PROJ_CHANGE | |
10 | + self.language = const.DEFAULT_LANG # en | |
11 | + self.imagedata_reformat = const.DEFAULT_REFORMAT # 1 | |
12 | + self.layout = const.DEFAULT_LAYOUT # | |
13 | + # const.LAYOUT_RAPID_PROTOTYPING, | |
14 | + # const.LAYOUT_RADIOLOGY, | |
15 | + # const.LAYOUT_NEURO_NAVIGATOR, | |
16 | + # const.LAYOUT_ODONTOLOGY | |
17 | + | |
18 | + | |
19 | + | |
20 | + | |
21 | +# USE PICKLE / PLIST !!!!!! | |
22 | +# external - possibly inside controller | |
23 | +# def SetFileName(self, filename) | |
24 | +# # try to load config file from home/.invesalius | |
25 | +# load = self.Load(filename) | |
26 | +# if load: | |
27 | +# config = InVesaliusConfig | |
28 | + | |
29 | +# def Load(self, filename): | |
30 | +# # TODO: which file representation? | |
31 | +# # config? | |
32 | +# # plist? | |
33 | +# pass | ... | ... |