Commit 50143a2b0551dd32717490c2a2ab7271058a02cc

Authored by Thiago Franco de Moraes
1 parent af3ad6f5
Exists in master

Added a dialog to show project properties and change project name

invesalius/constants.py
... ... @@ -468,11 +468,11 @@ VTK_WARNING = 0
468 468 #----------------------------------------------------------
469 469  
470 470 [ID_DICOM_IMPORT, ID_PROJECT_OPEN, ID_PROJECT_SAVE_AS, ID_PROJECT_SAVE,
471   - ID_PROJECT_CLOSE, ID_EXPORT_SLICE, ID_EXPORT_MASK, ID_PROJECT_INFO,
  471 + ID_PROJECT_CLOSE, ID_EXPORT_SLICE, ID_PROJECT_PROPERTIES, ID_EXPORT_MASK, ID_PROJECT_INFO,
472 472 ID_SAVE_SCREENSHOT, ID_DICOM_LOAD_NET, ID_PRINT_SCREENSHOT,
473 473 ID_IMPORT_OTHERS_FILES, ID_PREFERENCES, ID_DICOM_NETWORK, ID_TIFF_JPG_PNG,
474 474 ID_VIEW_INTERPOLATED, ID_MODE_NAVIGATION, ID_ANALYZE_IMPORT, ID_NIFTI_IMPORT,
475   - ID_PARREC_IMPORT, ID_MODE_DBS] = [wx.NewId() for number in range(21)]
  475 + ID_PARREC_IMPORT, ID_MODE_DBS] = [wx.NewId() for number in range(22)]
476 476 ID_EXIT = wx.ID_EXIT
477 477 ID_ABOUT = wx.ID_ABOUT
478 478  
... ...
invesalius/gui/frame.py
... ... @@ -40,6 +40,7 @@ import wx.aui
40 40 import wx.lib.agw.toasterbox as TB
41 41 import wx.lib.popupctl as pc
42 42 from invesalius import inv_paths
  43 +from invesalius.gui import project_properties
43 44 from wx.lib.agw.aui.auibar import AUI_TB_PLAIN_BACKGROUND, AuiToolBar
44 45 from pubsub import pub as Publisher
45 46  
... ... @@ -438,6 +439,8 @@ class Frame(wx.Frame):
438 439 self.ShowSaveAsProject()
439 440 elif id == const.ID_EXPORT_SLICE:
440 441 self.ExportProject()
  442 + elif id == const.ID_PROJECT_PROPERTIES:
  443 + self.ShowProjectProperties()
441 444 elif id == const.ID_PROJECT_CLOSE:
442 445 self.CloseProject()
443 446 elif id == const.ID_EXIT:
... ... @@ -698,6 +701,16 @@ class Frame(wx.Frame):
698 701 p.export_project(filename)
699 702 session['paths']['last_directory_export_prj'] = os.path.split(filename)[0]
700 703  
  704 + def ShowProjectProperties(self):
  705 + window = project_properties.ProjectProperties(self)
  706 + if window.ShowModal() == wx.ID_OK:
  707 + p = prj.Project()
  708 + if window.name_txt.GetValue() != p.name:
  709 + p.name = window.name_txt.GetValue()
  710 + ses.Session().ChangeProject()
  711 + self._SetProjectName(p.name)
  712 + window.Destroy()
  713 +
701 714 def ShowBitmapImporter(self):
702 715 """
703 716 Tiff, BMP, JPEG and PNG
... ... @@ -821,6 +834,7 @@ class MenuBar(wx.MenuBar):
821 834 self.enable_items = [const.ID_PROJECT_SAVE,
822 835 const.ID_PROJECT_SAVE_AS,
823 836 const.ID_EXPORT_SLICE,
  837 + const.ID_PROJECT_PROPERTIES,
824 838 const.ID_PROJECT_CLOSE,
825 839 const.ID_REORIENT_IMG,
826 840 const.ID_FLOODFILL_MASK,
... ... @@ -898,6 +912,7 @@ class MenuBar(wx.MenuBar):
898 912 app(const.ID_PROJECT_SAVE, _("Save project\tCtrl+S"))
899 913 app(const.ID_PROJECT_SAVE_AS, _("Save project as...\tCtrl+Shift+S"))
900 914 app(const.ID_EXPORT_SLICE, _("Export project"))
  915 + app(const.ID_PROJECT_PROPERTIES, _("Project properties"))
901 916 app(const.ID_PROJECT_CLOSE, _("Close project"))
902 917 file_menu.AppendSeparator()
903 918 #app(const.ID_PROJECT_INFO, _("Project Information..."))
... ...
invesalius/gui/project_properties.py 0 → 100644
... ... @@ -0,0 +1,95 @@
  1 +#--------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +#--------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +#--------------------------------------------------------------------
  19 +
  20 +import wx
  21 +import invesalius.project as prj
  22 +from pubsub import pub as Publisher
  23 +from invesalius.gui import utils
  24 +from invesalius import constants as const
  25 +
  26 +ORIENTATION_LABEL = {
  27 + const.AXIAL: _("Axial"),
  28 + const.CORONAL: _("Coronal"),
  29 + const.SAGITAL: _("Sagital"),
  30 +}
  31 +
  32 +
  33 +class ProjectProperties(wx.Dialog):
  34 + def __init__(self, parent):
  35 + super().__init__(id=-1, name='', parent=parent,
  36 + style=wx.DEFAULT_FRAME_STYLE, title=_('Project Properties'))
  37 + self.Center(wx.BOTH)
  38 + self._init_gui()
  39 +
  40 + def _init_gui(self):
  41 + project = prj.Project()
  42 + self.name_txt = wx.TextCtrl(self, -1, value=project.name)
  43 + self.name_txt.SetMinSize((utils.calc_width_needed(self.name_txt, 30), -1))
  44 +
  45 + modality_txt = wx.TextCtrl(self, -1, value=project.modality, style=wx.TE_READONLY)
  46 +
  47 + try:
  48 + orientation = ORIENTATION_LABEL[project.original_orientation]
  49 + except KeyError:
  50 + orientation = _("Other")
  51 +
  52 + orientation_txt = wx.TextCtrl(self, -1, value=orientation, style=wx.TE_READONLY)
  53 +
  54 + sx, sy, sz = project.spacing
  55 + spacing_txt_x = wx.TextCtrl(self, -1, value=f"{sx:.5}", style=wx.TE_READONLY)
  56 + spacing_txt_y = wx.TextCtrl(self, -1, value=f"{sy:.5}", style=wx.TE_READONLY)
  57 + spacing_txt_z = wx.TextCtrl(self, -1, value=f"{sz:.5}", style=wx.TE_READONLY)
  58 +
  59 + name_sizer = wx.BoxSizer(wx.HORIZONTAL)
  60 + name_sizer.Add(wx.StaticText(self, -1, _('Name')), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
  61 + name_sizer.Add(self.name_txt, 1, wx.EXPAND | wx.ALL, 5)
  62 +
  63 + modality_sizer = wx.BoxSizer(wx.HORIZONTAL)
  64 + modality_sizer.Add(wx.StaticText(self, -1, _('Modality')), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
  65 + modality_sizer.Add(modality_txt, 1, wx.EXPAND | wx.ALL, 5)
  66 +
  67 + orientation_sizer = wx.BoxSizer(wx.HORIZONTAL)
  68 + orientation_sizer.Add(wx.StaticText(self, -1, _('Orientation')), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
  69 + orientation_sizer.Add(orientation_txt, 1, wx.EXPAND | wx.ALL, 5)
  70 +
  71 + spacing_sizer = wx.BoxSizer(wx.HORIZONTAL)
  72 + spacing_sizer.Add(wx.StaticText(self, -1, _('Spacing')), 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
  73 + spacing_sizer.Add(spacing_txt_x, 1, wx.EXPAND | wx.ALL, 5)
  74 + spacing_sizer.Add(spacing_txt_y, 1, wx.EXPAND | wx.ALL, 5)
  75 + spacing_sizer.Add(spacing_txt_z, 1, wx.EXPAND | wx.ALL, 5)
  76 +
  77 + btn_sizer = wx.StdDialogButtonSizer()
  78 + btn_ok = wx.Button(self, wx.ID_OK)
  79 + btn_ok.SetDefault()
  80 + btn_cancel = wx.Button(self, wx.ID_CANCEL)
  81 + btn_sizer.AddButton(btn_ok)
  82 + btn_sizer.AddButton(btn_cancel)
  83 + btn_sizer.Realize()
  84 +
  85 + main_sizer = wx.BoxSizer(wx.VERTICAL)
  86 + main_sizer.Add(name_sizer, 1, wx.EXPAND)
  87 + main_sizer.Add(modality_sizer, 1, wx.EXPAND)
  88 + main_sizer.Add(orientation_sizer, 1, wx.EXPAND)
  89 + main_sizer.Add(spacing_sizer, 1, wx.EXPAND)
  90 + main_sizer.Add(btn_sizer, 1, wx.EXPAND | wx.ALL, 5)
  91 +
  92 + self.SetSizer(main_sizer)
  93 + main_sizer.Fit(self)
  94 + self.Layout()
  95 +
... ...
invesalius/gui/utils.py 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +# --------------------------------------------------------------------
  2 +# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
  3 +# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
  4 +# Homepage: http://www.softwarepublico.gov.br
  5 +# Contact: invesalius@cti.gov.br
  6 +# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
  7 +# --------------------------------------------------------------------
  8 +# Este programa e software livre; voce pode redistribui-lo e/ou
  9 +# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
  10 +# publicada pela Free Software Foundation; de acordo com a versao 2
  11 +# da Licenca.
  12 +#
  13 +# Este programa eh distribuido na expectativa de ser util, mas SEM
  14 +# QUALQUER GARANTIA; sem mesmo a garantia implicita de
  15 +# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
  16 +# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
  17 +# detalhes.
  18 +# --------------------------------------------------------------------
  19 +
  20 +import wx
  21 +
  22 +
  23 +def calc_width_needed(widget, num_chars):
  24 + width, height = widget.GetTextExtent("M" * num_chars)
  25 + return width
... ...