Commit fc5abcbd6748c2650a15fd25a06eb677f325073e
1 parent
b6d22243
Exists in
master
and in
68 other branches
ADD: Export task panel - still need to fix icons
Showing
1 changed file
with
206 additions
and
4 deletions
Show diff stats
invesalius/gui/task_exporter.py
... | ... | @@ -17,10 +17,212 @@ |
17 | 17 | # detalhes. |
18 | 18 | #-------------------------------------------------------------------------- |
19 | 19 | |
20 | +import os | |
21 | +import sys | |
22 | + | |
20 | 23 | import wx |
21 | - | |
24 | +import wx.lib.hyperlink as hl | |
25 | +import wx.lib.platebtn as pbtn | |
26 | +import wx.lib.pubsub as ps | |
27 | + | |
28 | +import constants as const | |
29 | +import project as proj | |
30 | + | |
31 | +BTN_PICTURE = wx.NewId() | |
32 | +BTN_SURFACE = wx.NewId() | |
33 | +BTN_REPORT = wx.NewId() | |
34 | +BTN_REQUEST_RP = wx.NewId() | |
35 | + | |
36 | +WILDCARD_SAVE_3D = "Inventor (*.iv)|*.iv|"\ | |
37 | + "Renderman (*.rib)|*.rib|"\ | |
38 | + "STL (*.stl)|*.stl|"\ | |
39 | + "VRML (*.vrml)|*.vrml|"\ | |
40 | + "Wavefront (*.obj)|*.obj" | |
41 | +INDEX_TO_TYPE_3D = {0: const.FILETYPE_IV, | |
42 | + 1: const.FILETYPE_RIB, | |
43 | + 2: const.FILETYPE_STL, | |
44 | + 3: const.FILETYPE_VRML, | |
45 | + 4: const.FILETYPE_OBJ} | |
46 | +INDEX_TO_EXTENSION = {0: "iv", | |
47 | + 1: "rib", | |
48 | + 2: "stl", | |
49 | + 3: "vrml", | |
50 | + 4: "obj"} | |
51 | + | |
52 | +WILDCARD_SAVE_2D = "BMP (*.bmp)|*.bmp|"\ | |
53 | + "JPEG (*.jpg)|*.jpg|"\ | |
54 | + "PNG (*.png)|*.png|"\ | |
55 | + "PostScript (*.ps)|*.ps|"\ | |
56 | + "Povray (*.pov)|*.pov|"\ | |
57 | + "TIFF (*.tiff)|*.tiff" | |
58 | +INDEX_TO_TYPE_2D = {0: const.FILETYPE_BMP, | |
59 | + 1: const.FILETYPE_JPG, | |
60 | + 2: const.FILETYPE_PNG, | |
61 | + 3: const.FILETYPE_PS, | |
62 | + 4: const.FILETYPE_POV, | |
63 | + 5: const.FILETYPE_OBJ} | |
64 | + | |
65 | + | |
22 | 66 | class TaskPanel(wx.Panel): |
23 | 67 | def __init__(self, parent): |
24 | - wx.Panel.__init__(self, parent, pos=wx.Point(0, 50), size=wx.Size(256, 120)) | |
25 | - self.SetBackgroundColour(wx.Colour(221, 221, 221, 255)) | |
26 | - | |
27 | 68 | \ No newline at end of file |
69 | + wx.Panel.__init__(self, parent) | |
70 | + | |
71 | + inner_panel = InnerTaskPanel(self) | |
72 | + | |
73 | + sizer = wx.BoxSizer(wx.HORIZONTAL) | |
74 | + sizer.Add(inner_panel, 1, wx.EXPAND | wx.GROW | wx.BOTTOM | wx.RIGHT | | |
75 | + wx.LEFT, 7) | |
76 | + sizer.Fit(self) | |
77 | + | |
78 | + self.SetSizer(sizer) | |
79 | + self.Update() | |
80 | + self.SetAutoLayout(1) | |
81 | + | |
82 | +class InnerTaskPanel(wx.Panel): | |
83 | + | |
84 | + def __init__(self, parent): | |
85 | + wx.Panel.__init__(self, parent) | |
86 | + self.SetBackgroundColour(wx.Colour(255,255,255)) | |
87 | + self.SetAutoLayout(1) | |
88 | + | |
89 | + # Counter for projects loaded in current GUI | |
90 | + | |
91 | + # Fixed hyperlink items | |
92 | + tooltip = wx.ToolTip("Export InVesalius screen to a image file") | |
93 | + link_export_picture = hl.HyperLinkCtrl(self, -1, | |
94 | + "Export picture...") | |
95 | + link_export_picture.SetUnderlines(False, False, False) | |
96 | + link_export_picture.SetColours("BLACK", "BLACK", "BLACK") | |
97 | + link_export_picture.SetToolTip(tooltip) | |
98 | + link_export_picture.AutoBrowse(False) | |
99 | + link_export_picture.UpdateLink() | |
100 | + link_export_picture.Bind(hl.EVT_HYPERLINK_LEFT, | |
101 | + self.OnLinkExportPicture) | |
102 | + | |
103 | + tooltip = wx.ToolTip("Export 3D surface") | |
104 | + link_export_surface = hl.HyperLinkCtrl(self, -1,"Export 3D surface...") | |
105 | + link_export_surface.SetUnderlines(False, False, False) | |
106 | + link_export_surface.SetColours("BLACK", "BLACK", "BLACK") | |
107 | + link_export_surface.SetToolTip(tooltip) | |
108 | + link_export_surface.AutoBrowse(False) | |
109 | + link_export_surface.UpdateLink() | |
110 | + link_export_surface.Bind(hl.EVT_HYPERLINK_LEFT, | |
111 | + self.OnLinkExportSurface) | |
112 | + | |
113 | + tooltip = wx.ToolTip("Request rapid prototyping services") | |
114 | + link_request_rp = hl.HyperLinkCtrl(self,-1,"Request rapid prototyping...") | |
115 | + link_request_rp.SetUnderlines(False, False, False) | |
116 | + link_request_rp.SetColours("BLACK", "BLACK", "BLACK") | |
117 | + link_request_rp.SetToolTip(tooltip) | |
118 | + link_request_rp.AutoBrowse(False) | |
119 | + link_request_rp.UpdateLink() | |
120 | + link_request_rp.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkRequestRP) | |
121 | + | |
122 | + tooltip = wx.ToolTip("Open report tool...") | |
123 | + link_report = hl.HyperLinkCtrl(self,-1,"Open report tool...") | |
124 | + link_report.SetUnderlines(False, False, False) | |
125 | + link_report.SetColours("BLACK", "BLACK", "BLACK") | |
126 | + link_report.SetToolTip(tooltip) | |
127 | + link_report.AutoBrowse(False) | |
128 | + link_report.UpdateLink() | |
129 | + link_report.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkReport) | |
130 | + | |
131 | + | |
132 | + # Image(s) for buttons | |
133 | + BMP_IMPORT = wx.Bitmap("../icons/file_import.png", wx.BITMAP_TYPE_PNG) | |
134 | + | |
135 | + bmp_list = [BMP_IMPORT] | |
136 | + for bmp in bmp_list: | |
137 | + bmp.SetWidth(25) | |
138 | + bmp.SetHeight(25) | |
139 | + | |
140 | + # Buttons related to hyperlinks | |
141 | + button_style = pbtn.PB_STYLE_SQUARE | pbtn.PB_STYLE_DEFAULT | |
142 | + | |
143 | + button_picture = pbtn.PlateButton(self, BTN_PICTURE, "", | |
144 | + BMP_IMPORT, style=button_style) | |
145 | + button_surface = pbtn.PlateButton(self, BTN_SURFACE, "", BMP_IMPORT, | |
146 | + style=button_style) | |
147 | + button_request_rp = pbtn.PlateButton(self, BTN_REQUEST_RP, "", | |
148 | + BMP_IMPORT, style=button_style) | |
149 | + button_report = pbtn.PlateButton(self, BTN_REPORT, "", | |
150 | + BMP_IMPORT, | |
151 | + style=button_style) | |
152 | + | |
153 | + # When using PlaneButton, it is necessary to bind events from parent win | |
154 | + self.Bind(wx.EVT_BUTTON, self.OnButton) | |
155 | + | |
156 | + # Tags and grid sizer for fixed items | |
157 | + flag_link = wx.EXPAND|wx.GROW|wx.LEFT|wx.TOP | |
158 | + flag_button = wx.EXPAND | wx.GROW | |
159 | + | |
160 | + fixed_sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=2, vgap=0) | |
161 | + fixed_sizer.AddGrowableCol(0, 1) | |
162 | + fixed_sizer.AddMany([ (link_export_picture, 1, flag_link, 3), | |
163 | + (button_picture, 0, flag_button), | |
164 | + (link_export_surface, 1, flag_link, 3), | |
165 | + (button_surface, 0, flag_button), | |
166 | + (link_report, 0, flag_link, 3), | |
167 | + (button_report, 0, flag_button), | |
168 | + (link_request_rp, 1, flag_link, 3), | |
169 | + (button_request_rp, 0, flag_button)]) | |
170 | + | |
171 | + # Add line sizers into main sizer | |
172 | + main_sizer = wx.BoxSizer(wx.VERTICAL) | |
173 | + main_sizer.Add(fixed_sizer, 0, wx.GROW|wx.EXPAND) | |
174 | + | |
175 | + # Update main sizer and panel layout | |
176 | + self.SetSizer(main_sizer) | |
177 | + self.Fit() | |
178 | + self.sizer = main_sizer | |
179 | + | |
180 | + def OnLinkExportPicture(self, evt=None): | |
181 | + pass | |
182 | + | |
183 | + | |
184 | + def OnLinkExportSurface(self, evt=None): | |
185 | + project = proj.Project() | |
186 | + if sys.platform == 'win32': | |
187 | + project_name = project.name | |
188 | + else: | |
189 | + project_name = project.name+".stl" | |
190 | + | |
191 | + if project.surface_dict: | |
192 | + | |
193 | + dlg = wx.FileDialog(None, | |
194 | + "Export 3D surface", # title | |
195 | + "", # directory | |
196 | + project_name, # filename | |
197 | + WILDCARD_SAVE_3D, | |
198 | + wx.SAVE|wx.OVERWRITE_PROMPT) | |
199 | + dlg.SetFilterIndex(2) # default is STL | |
200 | + | |
201 | + if dlg.ShowModal() == wx.ID_OK: | |
202 | + filetype_index = dlg.GetFilterIndex() | |
203 | + filetype = INDEX_TO_TYPE_3D[filetype_index] | |
204 | + filename = dlg.GetPath() | |
205 | + extension = INDEX_TO_EXTENSION[filetype_index] | |
206 | + if sys.platform != 'win32': | |
207 | + if filename.split(".")[-1] != extension: | |
208 | + filename = filename + "."+ extension | |
209 | + ps.Publisher().sendMessage('Export surface to file', | |
210 | + (filename, filetype)) | |
211 | + else: | |
212 | + print "Nao tem superficie, nao podemos exportar" | |
213 | + | |
214 | + def OnLinkRequestRP(self, evt=None): | |
215 | + pass | |
216 | + | |
217 | + def OnLinkReport(self, evt=None): | |
218 | + pass | |
219 | + | |
220 | + def OnButton(self, evt): | |
221 | + id = evt.GetId() | |
222 | + if id == BTN_PICTURE: | |
223 | + self.OnLinkExportPicture() | |
224 | + elif id == BTN_SURFACE: | |
225 | + self.OnLinkExportSurface() | |
226 | + elif id == BTN_REPORT: | |
227 | + self.OnLinkReport() | |
228 | + else: #elif id == BTN_REQUEST_RP: | |
229 | + self.OnLinkRequestRP() | ... | ... |