From fc5abcbd6748c2650a15fd25a06eb677f325073e Mon Sep 17 00:00:00 2001 From: tatiana Date: Wed, 26 Aug 2009 17:22:22 +0000 Subject: [PATCH] ADD: Export task panel - still need to fix icons --- invesalius/gui/task_exporter.py | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 206 insertions(+), 4 deletions(-) diff --git a/invesalius/gui/task_exporter.py b/invesalius/gui/task_exporter.py index fa3c415..29c8c34 100644 --- a/invesalius/gui/task_exporter.py +++ b/invesalius/gui/task_exporter.py @@ -17,10 +17,212 @@ # detalhes. #-------------------------------------------------------------------------- +import os +import sys + import wx - +import wx.lib.hyperlink as hl +import wx.lib.platebtn as pbtn +import wx.lib.pubsub as ps + +import constants as const +import project as proj + +BTN_PICTURE = wx.NewId() +BTN_SURFACE = wx.NewId() +BTN_REPORT = wx.NewId() +BTN_REQUEST_RP = wx.NewId() + +WILDCARD_SAVE_3D = "Inventor (*.iv)|*.iv|"\ + "Renderman (*.rib)|*.rib|"\ + "STL (*.stl)|*.stl|"\ + "VRML (*.vrml)|*.vrml|"\ + "Wavefront (*.obj)|*.obj" +INDEX_TO_TYPE_3D = {0: const.FILETYPE_IV, + 1: const.FILETYPE_RIB, + 2: const.FILETYPE_STL, + 3: const.FILETYPE_VRML, + 4: const.FILETYPE_OBJ} +INDEX_TO_EXTENSION = {0: "iv", + 1: "rib", + 2: "stl", + 3: "vrml", + 4: "obj"} + +WILDCARD_SAVE_2D = "BMP (*.bmp)|*.bmp|"\ + "JPEG (*.jpg)|*.jpg|"\ + "PNG (*.png)|*.png|"\ + "PostScript (*.ps)|*.ps|"\ + "Povray (*.pov)|*.pov|"\ + "TIFF (*.tiff)|*.tiff" +INDEX_TO_TYPE_2D = {0: const.FILETYPE_BMP, + 1: const.FILETYPE_JPG, + 2: const.FILETYPE_PNG, + 3: const.FILETYPE_PS, + 4: const.FILETYPE_POV, + 5: const.FILETYPE_OBJ} + + class TaskPanel(wx.Panel): def __init__(self, parent): - wx.Panel.__init__(self, parent, pos=wx.Point(0, 50), size=wx.Size(256, 120)) - self.SetBackgroundColour(wx.Colour(221, 221, 221, 255)) - \ No newline at end of file + 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 + + # Fixed hyperlink items + tooltip = wx.ToolTip("Export InVesalius screen to a image file") + link_export_picture = hl.HyperLinkCtrl(self, -1, + "Export picture...") + link_export_picture.SetUnderlines(False, False, False) + link_export_picture.SetColours("BLACK", "BLACK", "BLACK") + link_export_picture.SetToolTip(tooltip) + link_export_picture.AutoBrowse(False) + link_export_picture.UpdateLink() + link_export_picture.Bind(hl.EVT_HYPERLINK_LEFT, + self.OnLinkExportPicture) + + tooltip = wx.ToolTip("Export 3D surface") + link_export_surface = hl.HyperLinkCtrl(self, -1,"Export 3D surface...") + link_export_surface.SetUnderlines(False, False, False) + link_export_surface.SetColours("BLACK", "BLACK", "BLACK") + link_export_surface.SetToolTip(tooltip) + link_export_surface.AutoBrowse(False) + link_export_surface.UpdateLink() + link_export_surface.Bind(hl.EVT_HYPERLINK_LEFT, + self.OnLinkExportSurface) + + tooltip = wx.ToolTip("Request rapid prototyping services") + link_request_rp = hl.HyperLinkCtrl(self,-1,"Request rapid prototyping...") + link_request_rp.SetUnderlines(False, False, False) + link_request_rp.SetColours("BLACK", "BLACK", "BLACK") + link_request_rp.SetToolTip(tooltip) + link_request_rp.AutoBrowse(False) + link_request_rp.UpdateLink() + link_request_rp.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkRequestRP) + + tooltip = wx.ToolTip("Open report tool...") + link_report = hl.HyperLinkCtrl(self,-1,"Open report tool...") + link_report.SetUnderlines(False, False, False) + link_report.SetColours("BLACK", "BLACK", "BLACK") + link_report.SetToolTip(tooltip) + link_report.AutoBrowse(False) + link_report.UpdateLink() + link_report.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLinkReport) + + + # Image(s) for buttons + BMP_IMPORT = wx.Bitmap("../icons/file_import.png", wx.BITMAP_TYPE_PNG) + + bmp_list = [BMP_IMPORT] + for bmp in bmp_list: + bmp.SetWidth(25) + bmp.SetHeight(25) + + # Buttons related to hyperlinks + button_style = pbtn.PB_STYLE_SQUARE | pbtn.PB_STYLE_DEFAULT + + button_picture = pbtn.PlateButton(self, BTN_PICTURE, "", + BMP_IMPORT, style=button_style) + button_surface = pbtn.PlateButton(self, BTN_SURFACE, "", BMP_IMPORT, + style=button_style) + button_request_rp = pbtn.PlateButton(self, BTN_REQUEST_RP, "", + BMP_IMPORT, style=button_style) + button_report = pbtn.PlateButton(self, BTN_REPORT, "", + BMP_IMPORT, + 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 + + fixed_sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=2, vgap=0) + fixed_sizer.AddGrowableCol(0, 1) + fixed_sizer.AddMany([ (link_export_picture, 1, flag_link, 3), + (button_picture, 0, flag_button), + (link_export_surface, 1, flag_link, 3), + (button_surface, 0, flag_button), + (link_report, 0, flag_link, 3), + (button_report, 0, flag_button), + (link_request_rp, 1, flag_link, 3), + (button_request_rp, 0, flag_button)]) + + # Add line sizers into main sizer + main_sizer = wx.BoxSizer(wx.VERTICAL) + main_sizer.Add(fixed_sizer, 0, wx.GROW|wx.EXPAND) + + # Update main sizer and panel layout + self.SetSizer(main_sizer) + self.Fit() + self.sizer = main_sizer + + def OnLinkExportPicture(self, evt=None): + pass + + + def OnLinkExportSurface(self, evt=None): + project = proj.Project() + if sys.platform == 'win32': + project_name = project.name + else: + project_name = project.name+".stl" + + if project.surface_dict: + + dlg = wx.FileDialog(None, + "Export 3D surface", # title + "", # directory + project_name, # filename + WILDCARD_SAVE_3D, + wx.SAVE|wx.OVERWRITE_PROMPT) + dlg.SetFilterIndex(2) # default is STL + + if dlg.ShowModal() == wx.ID_OK: + filetype_index = dlg.GetFilterIndex() + filetype = INDEX_TO_TYPE_3D[filetype_index] + filename = dlg.GetPath() + extension = INDEX_TO_EXTENSION[filetype_index] + if sys.platform != 'win32': + if filename.split(".")[-1] != extension: + filename = filename + "."+ extension + ps.Publisher().sendMessage('Export surface to file', + (filename, filetype)) + else: + print "Nao tem superficie, nao podemos exportar" + + def OnLinkRequestRP(self, evt=None): + pass + + def OnLinkReport(self, evt=None): + pass + + def OnButton(self, evt): + id = evt.GetId() + if id == BTN_PICTURE: + self.OnLinkExportPicture() + elif id == BTN_SURFACE: + self.OnLinkExportSurface() + elif id == BTN_REPORT: + self.OnLinkReport() + else: #elif id == BTN_REQUEST_RP: + self.OnLinkRequestRP() -- libgit2 0.21.2