File: style.py

package info (click to toggle)
invesalius 3.1.99992-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 86,416 kB
  • sloc: python: 28,433; makefile: 56
file content (121 lines) | stat: -rw-r--r-- 3,822 bytes parent folder | download | duplicates (2)
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
#--------------------------------------------------------------------------
# Software:     InVesalius - Software de Reconstrucao 3D de Imagens Medicas
# Copyright:    (C) 2001  Centro de Pesquisas Renato Archer
# Homepage:     http://www.softwarepublico.gov.br
# Contact:      invesalius@cti.gov.br
# License:      GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
#--------------------------------------------------------------------------
#    Este programa e software livre; voce pode redistribui-lo e/ou
#    modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
#    publicada pela Free Software Foundation; de acordo com a versao 2
#    da Licenca.
#
#    Este programa eh distribuido na expectativa de ser util, mas SEM
#    QUALQUER GARANTIA; sem mesmo a garantia implicita de
#    COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
#    PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
#    detalhes.
#--------------------------------------------------------------------------

from wx.lib.pubsub import pub as Publisher


# mode.py
# to be instanced inside Controller (control.py)



# IMPORTANT: When adding a new state, remember o insert it into LEVEL
# dictionary


# RULE:
# default is the only level 0
# states controlled somehow by taskmenu are level 1
# states controlled by toolbar are level 2
#LEVEL = {SLICE_STATE_DEFAULT: 0,
#         SLICE_STATE_EDITOR: 1,
#         SLICE_STATE_WL: 2,
#         SLICE_STATE_SPIN: 2,
#         SLICE_STATE_ZOOM: 2,
#         SLICE_STATE_ZOOM_SL: 2}
#----------------------
# TODO: Add to viewer_slice.py:

#ps.Publisher().subscribe(self.OnSetMode, 'Set slice mode')

#def OnSetMode(self, pubsub_evt):
#    mode = pubsub_evt.data
    # according to mode, set cursor, interaction, etc
#----------------------
# TODO: Add GUI classes (frame, tasks related to slice, toolbar):

# always bind to this class (regarding slice mode) and not to
# viewer_slice directly

# example - pseudo code
#def OnToggleButtonSpin(self, evt)
#    if evt.toggle: # doesn't exist, just to illustrate
#        ps.Publisher().sendMessage('Enable mode', const.SLICE_STATE_ZOOM)
#    else:
#        ps.Publisher().subscribe('Disable mode', const.SLICE_STATE_ZOOM)


#----------------------


import invesalius.constants as const

class StyleStateManager(object):
# don't need to be singleton, only needs to be instantiated inside
# (Controller) self.slice_mode = SliceMode()

    def __init__(self):
        self.stack = {}

        # push default value to stack
        self.stack[const.STYLE_LEVEL[const.STATE_DEFAULT]] = \
                    const.STATE_DEFAULT

    def AddState(self, state):

        level = const.STYLE_LEVEL[state]
        max_level = max(self.stack.keys())

        # Insert new state into stack
        self.stack[level] = state


        new_max_level =  max(self.stack.keys())
        return self.stack[new_max_level]

    def RemoveState(self, state):
        level = const.STYLE_LEVEL[state]
        if level in self.stack.keys():
            max_level = max(self.stack.keys())

            # Remove item from stack
            self.stack.pop(level)

            # New max level
            new_max_level =  max(self.stack.keys())

            # Only will affect InVesalius behaviour if the highest
            # level in stack has been removed
            if level == max_level:
                new_state = self.stack[new_max_level]

            return self.stack[new_max_level]

        max_level = max(self.stack.keys())
        return self.stack[max_level]

    def GetActualState(self):
        max_level = max(self.stack.keys())
        state = self.stack[max_level]
        return state

    def Reset(self):
        self.stack = {}
        self.stack[const.STYLE_LEVEL[const.STATE_DEFAULT]] = \
                    const.STATE_DEFAULT