task_tools.py
5.45 KB
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
#--------------------------------------------------------------------------
# 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.
#--------------------------------------------------------------------------
import wx
import os
import wx.lib.embeddedimage as emb
import wx.lib.hyperlink as hl
import wx.lib.platebtn as pbtn
from wx.lib.pubsub import pub as Publisher
import invesalius.constants as constants
import invesalius.constants as const
ID_BTN_MEASURE_LINEAR = wx.NewId()
ID_BTN_MEASURE_ANGULAR = wx.NewId()
ID_BTN_ANNOTATION = wx.NewId()
class TaskPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
inner_panel = InnerTaskPanel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(inner_panel, 1, wx.EXPAND | wx.GROW | wx.BOTTOM | wx.RIGHT |
wx.LEFT, 7)
sizer.Fit(self)
self.SetSizer(sizer)
self.Update()
self.SetAutoLayout(1)
class InnerTaskPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(wx.Colour(255,255,255))
self.SetAutoLayout(1)
# Counter for projects loaded in current GUI
self.proj_count = 0
# Floating items (to be inserted)
self.float_hyper_list = []
# Fixed text and hyperlink items
tooltip = wx.ToolTip(_("Measure distances"))
txt_measure = wx.StaticText(self, -1, _("Measure"))
txt_measure.SetToolTip(tooltip)
tooltip = wx.ToolTip(_("Add text annotations"))
txt_annotation = hl.HyperLinkCtrl(self, -1,_("Add text annotations"))
txt_annotation.SetUnderlines(False, False, False)
txt_annotation.SetColours("BLACK", "BLACK", "BLACK")
txt_annotation.SetToolTip(tooltip)
txt_annotation.AutoBrowse(False)
txt_annotation.UpdateLink()
txt_annotation.Bind(hl.EVT_HYPERLINK_LEFT, self.OnTextAnnotation)
# Image(s) for buttons
BMP_ANNOTATE = wx.Bitmap(os.path.join(const.ICON_DIR, "annotation.png"), wx.BITMAP_TYPE_PNG)
BMP_ANGLE = wx.Bitmap(os.path.join(const.ICON_DIR, "measure_angle.jpg"), wx.BITMAP_TYPE_JPEG)
BMP_DISTANCE = wx.Bitmap(os.path.join(const.ICON_DIR, "measure_line.png"), wx.BITMAP_TYPE_PNG)
BMP_ANNOTATE.SetWidth(25)
BMP_ANNOTATE.SetHeight(25)
BMP_ANGLE.SetWidth(25)
BMP_ANGLE.SetHeight(25)
BMP_DISTANCE.SetWidth(25)
BMP_DISTANCE.SetHeight(25)
# Buttons related to hyperlinks
button_style = pbtn.PB_STYLE_SQUARE | pbtn.PB_STYLE_DEFAULT
button_measure_linear = pbtn.PlateButton(self, ID_BTN_MEASURE_LINEAR, "",
BMP_DISTANCE, style=button_style)
button_measure_angular = pbtn.PlateButton(self, ID_BTN_MEASURE_ANGULAR, "",
BMP_ANGLE, style=button_style)
button_annotation = pbtn.PlateButton(self, ID_BTN_ANNOTATION, "",
BMP_ANNOTATE, style=button_style)
# When using PlaneButton, it is necessary to bind events from parent win
self.Bind(wx.EVT_BUTTON, self.OnButton)
# Tags and grid sizer for fixed items
flag_link = wx.EXPAND|wx.GROW|wx.LEFT|wx.TOP
flag_button = wx.EXPAND | wx.GROW
sizer = wx.GridBagSizer(hgap=0, vgap=0)
sizer.Add(txt_measure,pos=(0,0),flag=wx.GROW|wx.EXPAND|wx.TOP,border=3)
sizer.Add(button_measure_linear,pos=(0,1),flag=wx.GROW|wx.EXPAND)
sizer.Add(button_measure_angular,pos=(0,2),flag=wx.GROW|wx.EXPAND)
sizer.Add(txt_annotation, pos=(1,0),flag=wx.GROW|wx.EXPAND)
sizer.Add(button_annotation, pos=(1,2),span=(2,1), flag=wx.GROW|wx.EXPAND)
sizer.AddGrowableCol(0)
# Add line sizers into main sizer
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(sizer, 0, wx.GROW|wx.EXPAND)
main_sizer.Fit(self)
# Update main sizer and panel layout
self.SetSizer(sizer)
self.Fit()
self.sizer = main_sizer
def OnTextAnnotation(self, evt=None):
print "TODO: Send Signal - Add text annotation (both 2d and 3d)"
def OnLinkLinearMeasure(self):
Publisher.sendMessage('Enable style',
constants.STATE_MEASURE_DISTANCE)
def OnLinkAngularMeasure(self):
Publisher.sendMessage('Enable style',
constants.STATE_MEASURE_ANGLE)
def OnButton(self, evt):
id = evt.GetId()
if id == ID_BTN_MEASURE_LINEAR:
self.OnLinkLinearMeasure()
elif id == ID_BTN_MEASURE_ANGULAR:
self.OnLinkAngularMeasure()
else: # elif id == ID_BTN_ANNOTATION:
self.OnTextAnnotation()