Commit eac24f4f8f25444c3f8036b7b53e54ebee8c29b2

Authored by Thiago Franco de Moraes
Committed by GitHub
1 parent 9eb75dca
Exists in master

Remove WX deprecated code, improve gradient (#182)

* using calllater instead of futurecall

* Using Append instead of AppendMenu in slice_menu

* Using Append instead of AppendItem in slice_menu

* Using Append instead of AppendItem in rest of source code

* Using Append instead of AppendMenu in rest of source code

* Using Bitmap instead of BitmapFromImage

* GetVirtualSizeTuple -> GetVirtualSize

* SetToolTipString -> SetToolTip

* ImageFromStream -> Image

* using self.bind to undo and redo tool

* wx.EmptyBitmapRGBA to wx.Bitmap

* EmptyImage -> Image

* InsertStringItem -> InsertItem

* SetStringItem -> SetItem

* wx.StockCursor to wx.Cursor

* GetSizeTuple -> GetSize

* Less time in dicom loading from cmdline

* Created an alternative class to SpinCtrl

* Using InvSpinCtrl in task_slice

* implementing float spinctrl

* Added InvFloatSpinCtrl

* Using InvSpinCtrl in task_surface

* Using InvSpinCtrl in regiongrowing dialog

* Using InvSpinCtrl in watershed config dialgo

* Using InvSpinCtrl in contextawaresmoothing config dialog

* Using InvSpinCtrl in fillholes auto config dialog

* Using InvSpinCtrl in the resizeimage dialog

* Using InvSpinCtrl in the bitmap spacing dialog

* removed all wx.predialog

* Using InvSpinCtrl gradient ctrl

* align to the right by default

* Added Spinbutton at inv_spinctrl

* formatation

* Using other way to calc invspinctrl size

* better size of spin button

* better size of spin button

* improvements

* better gradient code format

* Improvements in gradient ctrl

* Using gradientctrl instead of gradientslider in new mask

* better invspinctrl size to mac

* moved invspinctrl to widgets

* better size to mac
app.py
... ... @@ -247,9 +247,9 @@ class Inv3SplashScreen(SplashScreen):
247 247 self.main = Frame(None)
248 248 self.control = Controller(self.main)
249 249  
250   - self.fc = wx.FutureCall(1, self.ShowMain)
  250 + self.fc = wx.CallLater(200, self.ShowMain)
251 251 options, args = parse_comand_line()
252   - wx.FutureCall(1, use_cmd_optargs, options, args)
  252 + wx.CallLater(1, use_cmd_optargs, options, args)
253 253  
254 254 # Check for updates
255 255 from threading import Thread
... ...
invesalius/data/styles.py
... ... @@ -467,9 +467,9 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
467 467 else:
468 468 mx, my = self.viewer.interactor.GetEventPosition()
469 469 if self._verify_clicked_display(mx, my):
470   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
  470 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_HAND))
471 471 else:
472   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  472 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
473 473  
474 474 def OnLeaveMeasureInteractor(self, obj, evt):
475 475 if self.creating or self.selected:
... ... @@ -922,7 +922,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
922 922 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker)
923 923 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z))
924 924  
925   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
  925 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
926 926 self.viewer.interactor.Render()
927 927  
928 928 def CleanUp(self):
... ... @@ -931,7 +931,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
931 931 Publisher.unsubscribe(self.set_boperation, 'Set edition operation')
932 932  
933 933 self.viewer.slice_data.cursor.Show(0)
934   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  934 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
935 935 self.viewer.interactor.Render()
936 936  
937 937 def set_bsize(self, size):
... ... @@ -967,12 +967,12 @@ class EditorInteractorStyle(DefaultInteractorStyle):
967 967 if (self.viewer.slice_.buffer_slices[self.orientation].mask is None):
968 968 return
969 969 self.viewer.slice_data.cursor.Show()
970   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
  970 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
971 971 self.viewer.interactor.Render()
972 972  
973 973 def OnLeaveInteractor(self, obj, evt):
974 974 self.viewer.slice_data.cursor.Show(0)
975   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  975 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
976 976 self.viewer.interactor.Render()
977 977  
978 978 def OnBrushClick(self, obj, evt):
... ... @@ -1230,7 +1230,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1230 1230 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker)
1231 1231 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z))
1232 1232  
1233   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
  1233 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
1234 1234 self.viewer.interactor.Render()
1235 1235  
1236 1236 def CleanUp(self):
... ... @@ -1243,7 +1243,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1243 1243 self.viewer.OnScrollBar()
1244 1244  
1245 1245 self.viewer.slice_data.cursor.Show(0)
1246   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  1246 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
1247 1247 self.viewer.interactor.Render()
1248 1248  
1249 1249 def _create_mask(self):
... ... @@ -1290,12 +1290,12 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1290 1290 if (self.viewer.slice_.buffer_slices[self.orientation].mask is None):
1291 1291 return
1292 1292 self.viewer.slice_data.cursor.Show()
1293   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
  1293 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
1294 1294 self.viewer.interactor.Render()
1295 1295  
1296 1296 def OnLeaveInteractor(self, obj, evt):
1297 1297 self.viewer.slice_data.cursor.Show(0)
1298   - self.viewer.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  1298 + self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
1299 1299 self.viewer.interactor.Render()
1300 1300  
1301 1301 def WOnScrollBackward(self, obj, evt):
... ... @@ -1757,10 +1757,10 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
1757 1757 dist_center = ((mx - cx)**2 + (my - cy)**2)**0.5
1758 1758 if dist_center <= 15:
1759 1759 self._over_center = True
1760   - cursor = wx.StockCursor(wx.CURSOR_SIZENESW)
  1760 + cursor = wx.Cursor(wx.CURSOR_SIZENESW)
1761 1761 else:
1762 1762 self._over_center = False
1763   - cursor = wx.StockCursor(wx.CURSOR_DEFAULT)
  1763 + cursor = wx.Cursor(wx.CURSOR_DEFAULT)
1764 1764  
1765 1765 self.viewer.interactor.SetCursor(cursor)
1766 1766  
... ...
invesalius/data/viewer_slice.py
... ... @@ -49,6 +49,7 @@ import invesalius.session as ses
49 49 import invesalius.data.converters as converters
50 50 import invesalius.data.measures as measures
51 51  
  52 +from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl, InvFloatSpinCtrl
52 53 from invesalius.gui.widgets.canvas_renderer import CanvasRendererCTX
53 54  
54 55 if sys.platform == 'win32':
... ... @@ -73,25 +74,22 @@ ORIENTATIONS = {
73 74 class ContourMIPConfig(wx.Panel):
74 75 def __init__(self, prnt, orientation):
75 76 wx.Panel.__init__(self, prnt)
76   - self.mip_size_spin = wx.SpinCtrl(self, -1, min=1, max=240,
77   - initial=const.PROJECTION_MIP_SIZE)
78   - self.mip_size_spin.SetValue(const.PROJECTION_MIP_SIZE)
  77 + self.mip_size_spin = InvSpinCtrl(self, -1, value=const.PROJECTION_MIP_SIZE, min_value=1, max_value=240)
79 78 self.mip_size_spin.SetToolTip(wx.ToolTip(_("Number of slices used to compound the visualization.")))
80   - w, h = self.mip_size_spin.GetTextExtent('M')
81   - self.mip_size_spin.SetMinSize((5 * w + 10, -1))
82   - self.mip_size_spin.SetMaxSize((5 * w + 10, -1))
  79 + self.mip_size_spin.CalcSizeFromTextSize('MMM')
83 80  
84   - self.border_spin = FS.FloatSpin(self, -1, min_val=0, max_val=10,
  81 + self.border_spin = InvFloatSpinCtrl(self, -1, min_value=0, max_value=10,
85 82 increment=0.1,
86 83 value=const.PROJECTION_BORDER_SIZE,
87   - digits=1, agwStyle=FS.FS_LEFT)
  84 + digits=1)
88 85 self.border_spin.SetToolTip(wx.ToolTip(_("Controls the sharpness of the"
89 86 " contour. The greater the"
90 87 " value, the sharper the"
91 88 " contour.")))
92   - w, h = self.border_spin.GetTextExtent('M')
93   - self.border_spin.SetMinSize((5 * w + 10, -1))
94   - self.border_spin.SetMaxSize((5 * w + 10, -1))
  89 + self.border_spin.CalcSizeFromTextSize()
  90 + # w, h = self.border_spin.GetTextExtent('M')
  91 + # self.border_spin.SetMinSize((5 * w + 10, -1))
  92 + # self.border_spin.SetMaxSize((5 * w + 10, -1))
95 93  
96 94 self.inverted = wx.CheckBox(self, -1, _("Inverted order"))
97 95 self.inverted.SetToolTip(wx.ToolTip(_("If checked, the slices are"
... ... @@ -105,7 +103,7 @@ class ContourMIPConfig(wx.Panel):
105 103  
106 104 sizer = wx.BoxSizer(wx.HORIZONTAL)
107 105 sizer.Add(txt_mip_size, 0, wx.EXPAND | wx.ALL, 2)
108   - sizer.Add(self.mip_size_spin, 0, wx.EXPAND)
  106 + sizer.Add(self.mip_size_spin, 0)
109 107 try:
110 108 sizer.Add(10, 0)
111 109 except TypeError:
... ... @@ -883,19 +881,19 @@ class Viewer(wx.Panel):
883 881 self.Refresh()
884 882  
885 883 def SetDefaultCursor(self):
886   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
  884 + self.interactor.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
887 885  
888 886 def SetSizeNSCursor(self):
889   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
  887 + self.interactor.SetCursor(wx.Cursor(wx.CURSOR_SIZENS))
890 888  
891 889 def SetSizeWECursor(self):
892   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE))
  890 + self.interactor.SetCursor(wx.Cursor(wx.CURSOR_SIZEWE))
893 891  
894 892 def SetSizeNWSECursor(self):
895 893 if sys.platform.startswith('linux'):
896   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE))
  894 + self.interactor.SetCursor(wx.Cursor(wx.CURSOR_SIZENWSE))
897 895 else:
898   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
  896 + self.interactor.SetCursor(wx.Cursor(wx.CURSOR_SIZING))
899 897  
900 898 def SetFocus(self):
901 899 Publisher.sendMessage('Set viewer orientation focus',
... ...
invesalius/gui/bitmap_preview_panel.py
... ... @@ -115,7 +115,7 @@ class DicomPaintPanel(wx.Panel):
115 115 self.Bind(wx.EVT_SIZE, self.OnSize)
116 116  
117 117 def _build_bitmap(self, image):
118   - bmp = wx.BitmapFromImage(image)
  118 + bmp = wx.Bitmap(image)
119 119 return bmp
120 120  
121 121 def _image_resize(self, image):
... ...
invesalius/gui/data_notebook.py
... ... @@ -168,20 +168,20 @@ class MeasureButtonControlPanel(wx.Panel):
168 168 BMP_NEW,
169 169 style=button_style,
170 170 size = wx.Size(24, 20))
171   - button_new.SetToolTipString(_("Create a new measure"))
  171 + button_new.SetToolTip(_("Create a new measure"))
172 172 self.button_new = button_new
173 173  
174 174 button_remove = pbtn.PlateButton(self, BTN_REMOVE, "",
175 175 BMP_REMOVE,
176 176 style=button_style,
177 177 size = wx.Size(24, 20))
178   - button_remove.SetToolTipString(_("Remove measure"))
  178 + button_remove.SetToolTip(_("Remove measure"))
179 179  
180 180 button_duplicate = pbtn.PlateButton(self, BTN_DUPLICATE, "",
181 181 BMP_DUPLICATE,
182 182 style=button_style,
183 183 size = wx.Size(24, 20))
184   - button_duplicate.SetToolTipString(_("Duplicate measure"))
  184 + button_duplicate.SetToolTip(_("Duplicate measure"))
185 185 button_duplicate.Disable()
186 186  
187 187 # Add all controls to gui
... ... @@ -195,10 +195,10 @@ class MeasureButtonControlPanel(wx.Panel):
195 195 menu = wx.Menu()
196 196 item = wx.MenuItem(menu, const.MEASURE_LINEAR,
197 197 _("Measure distance"))
198   - menu.AppendItem(item)
  198 + menu.Append(item)
199 199 item = wx.MenuItem(menu, const.MEASURE_ANGULAR,
200 200 _("Measure angle"))
201   - menu.AppendItem(item)
  201 + menu.Append(item)
202 202 menu.Bind(wx.EVT_MENU, self.OnMenu)
203 203 self.menu = menu
204 204  
... ... @@ -286,19 +286,19 @@ class ButtonControlPanel(wx.Panel):
286 286 BMP_NEW,
287 287 style=button_style,
288 288 size = wx.Size(24, 20))
289   - button_new.SetToolTipString(_("Create a new mask"))
  289 + button_new.SetToolTip(_("Create a new mask"))
290 290  
291 291 button_remove = pbtn.PlateButton(self, BTN_REMOVE, "",
292 292 BMP_REMOVE,
293 293 style=button_style,
294 294 size = wx.Size(24, 20))
295   - button_remove.SetToolTipString(_("Remove mask"))
  295 + button_remove.SetToolTip(_("Remove mask"))
296 296  
297 297 button_duplicate = pbtn.PlateButton(self, BTN_DUPLICATE, "",
298 298 BMP_DUPLICATE,
299 299 style=button_style,
300 300 size = wx.Size(24, 20))
301   - button_duplicate.SetToolTipString(_("Duplicate mask"))
  301 + button_duplicate.SetToolTip(_("Duplicate mask"))
302 302  
303 303 # Add all controls to gui
304 304 sizer = wx.BoxSizer(wx.HORIZONTAL)
... ... @@ -474,13 +474,13 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckListCt
474 474 self.imagelist = wx.ImageList(16, 16)
475 475  
476 476 image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg"))
477   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  477 + bitmap = wx.Bitmap(image.Scale(16, 16))
478 478 bitmap.SetWidth(16)
479 479 bitmap.SetHeight(16)
480 480 img_null = self.imagelist.Add(bitmap)
481 481  
482 482 image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg"))
483   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  483 + bitmap = wx.Bitmap(image.Scale(16, 16))
484 484 bitmap.SetWidth(16)
485 485 bitmap.SetHeight(16)
486 486 img_check = self.imagelist.Add(bitmap)
... ... @@ -526,20 +526,20 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckListCt
526 526 for i in colour]
527 527 new_image.putpixel((x,y), tuple(pixel_colour))
528 528  
529   - wx_image = wx.EmptyImage(new_image.size[0],
530   - new_image.size[1])
  529 + wx_image = wx.Image(new_image.size[0],
  530 + new_image.size[1])
531 531 try:
532 532 wx_image.SetData(new_image.tostring())
533 533 except Exception:
534 534 wx_image.SetData(new_image.tobytes())
535   - return wx.BitmapFromImage(wx_image.Scale(16, 16))
  535 + return wx.Bitmap(wx_image.Scale(16, 16))
536 536  
537 537 def InsertNewItem(self, index=0, label=_("Mask"), threshold="(1000, 4500)",
538 538 colour=None):
539   - self.InsertStringItem(index, "")
540   - self.SetStringItem(index, 1, label,
  539 + self.InsertItem(index, "")
  540 + self.SetItem(index, 1, label,
541 541 imageId=self.mask_list_index[index])
542   - self.SetStringItem(index, 2, threshold)
  542 + self.SetItem(index, 2, threshold)
543 543 # self.SetItemImage(index, 1)
544 544 # for key in self.mask_list_index.keys():
545 545 # if key != index:
... ... @@ -553,7 +553,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckListCt
553 553 self.InsertNewItem(mask.index, mask.name, str(mask.threshold_range))
554 554  
555 555 def EditMaskThreshold(self, index, threshold_range):
556   - self.SetStringItem(index, 2, str(threshold_range))
  556 + self.SetItem(index, 2, str(threshold_range))
557 557  
558 558 def EditMaskColour(self, index, colour):
559 559 image = self.CreateColourBitmap(colour)
... ... @@ -631,25 +631,25 @@ class SurfaceButtonControlPanel(wx.Panel):
631 631 BMP_NEW,
632 632 style=button_style,
633 633 size = wx.Size(24, 20))
634   - button_new.SetToolTipString(_("Create a new surface"))
  634 + button_new.SetToolTip(_("Create a new surface"))
635 635  
636 636 button_remove = pbtn.PlateButton(self, BTN_REMOVE, "",
637 637 BMP_REMOVE,
638 638 style=button_style,
639 639 size = wx.Size(24, 20))
640   - button_remove.SetToolTipString(_("Remove surface"))
  640 + button_remove.SetToolTip(_("Remove surface"))
641 641  
642 642 button_duplicate = pbtn.PlateButton(self, BTN_DUPLICATE, "",
643 643 BMP_DUPLICATE,
644 644 style=button_style,
645 645 size = wx.Size(24, 20))
646   - button_duplicate.SetToolTipString(_("Duplicate surface"))
  646 + button_duplicate.SetToolTip(_("Duplicate surface"))
647 647  
648 648 button_open = pbtn.PlateButton(self, BTN_OPEN, "",
649 649 BMP_OPEN,
650 650 style=button_style,
651 651 size = wx.Size(24, 20))
652   - button_open.SetToolTipString(_("Import a surface file into InVesalius"))
  652 + button_open.SetToolTip(_("Import a surface file into InVesalius"))
653 653  
654 654 # Add all controls to gui
655 655 sizer = wx.BoxSizer(wx.HORIZONTAL)
... ... @@ -840,13 +840,13 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
840 840 self.imagelist = wx.ImageList(16, 16)
841 841  
842 842 image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg"))
843   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  843 + bitmap = wx.Bitmap(image.Scale(16, 16))
844 844 bitmap.SetWidth(16)
845 845 bitmap.SetHeight(16)
846 846 img_null = self.imagelist.Add(bitmap)
847 847  
848 848 image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg"))
849   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  849 + bitmap = wx.Bitmap(image.Scale(16, 16))
850 850 bitmap.SetWidth(16)
851 851 bitmap.SetHeight(16)
852 852 img_check = self.imagelist.Add(bitmap)
... ... @@ -923,23 +923,23 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
923 923  
924 924 def InsertNewItem(self, index=0, label="Surface 1", volume="0 mm3",
925 925 area="0 mm2", transparency="0%%", colour=None):
926   - self.InsertStringItem(index, "")
927   - self.SetStringItem(index, 1, label,
  926 + self.InsertItem(index, "")
  927 + self.SetItem(index, 1, label,
928 928 imageId = self.surface_list_index[index])
929   - self.SetStringItem(index, 2, volume)
930   - self.SetStringItem(index, 3, area)
931   - self.SetStringItem(index, 4, transparency)
  929 + self.SetItem(index, 2, volume)
  930 + self.SetItem(index, 3, area)
  931 + self.SetItem(index, 4, transparency)
932 932 self.SetItemImage(index, 1)
933 933  
934 934 def UpdateItemInfo(self, index=0, label="Surface 1", volume="0 mm3",
935 935 area="0 mm2", transparency="0%%", colour=None):
936 936 print("UpdateItemInfo", index)
937 937 # TODO: Retornar esse codigo
938   - self.SetStringItem(index, 1, label,
  938 + self.SetItem(index, 1, label,
939 939 imageId = self.surface_list_index[index])
940   - self.SetStringItem(index, 2, volume)
941   - self.SetStringItem(index, 3, area)
942   - self.SetStringItem(index, 4, transparency)
  940 + self.SetItem(index, 2, volume)
  941 + self.SetItem(index, 3, area)
  942 + self.SetItem(index, 4, transparency)
943 943 self.SetItemImage(index, 1)
944 944  
945 945 def CreateColourBitmap(self, colour):
... ... @@ -955,21 +955,21 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
955 955 for i in colour]
956 956 new_image.putpixel((x,y), tuple(pixel_colour))
957 957  
958   - wx_image = wx.EmptyImage(new_image.size[0],
959   - new_image.size[1])
  958 + wx_image = wx.Image(new_image.size[0],
  959 + new_image.size[1])
960 960 try:
961 961 wx_image.SetData(new_image.tostring())
962 962 except Exception:
963 963 wx_image.SetData(new_image.tobytes())
964 964  
965   - return wx.BitmapFromImage(wx_image.Scale(16, 16))
  965 + return wx.Bitmap(wx_image.Scale(16, 16))
966 966  
967 967 def EditSurfaceTransparency(self, surface_index, transparency):
968 968 """
969 969 Set actor transparency (oposite to opacity) according to given actor
970 970 index and value.
971 971 """
972   - self.SetStringItem(surface_index, 4, "%d%%"%(int(transparency*100)))
  972 + self.SetItem(surface_index, 4, "%d%%"%(int(transparency*100)))
973 973  
974 974 def EditSurfaceColour(self, surface_index, colour):
975 975 """
... ... @@ -1115,13 +1115,13 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
1115 1115 self.imagelist = wx.ImageList(16, 16)
1116 1116  
1117 1117 image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg"))
1118   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  1118 + bitmap = wx.Bitmap(image.Scale(16, 16))
1119 1119 bitmap.SetWidth(16)
1120 1120 bitmap.SetHeight(16)
1121 1121 img_null = self.imagelist.Add(bitmap)
1122 1122  
1123 1123 image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg"))
1124   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  1124 + bitmap = wx.Bitmap(image.Scale(16, 16))
1125 1125 bitmap.SetWidth(16)
1126 1126 bitmap.SetHeight(16)
1127 1127 img_check = self.imagelist.Add(bitmap)
... ... @@ -1217,22 +1217,22 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
1217 1217  
1218 1218 def InsertNewItem(self, index=0, label="Measurement 1", colour=None,
1219 1219 location="SURFACE", type_="LINEAR", value="0 mm"):
1220   - self.InsertStringItem(index, "")
1221   - self.SetStringItem(index, 1, label,
  1220 + self.InsertItem(index, "")
  1221 + self.SetItem(index, 1, label,
1222 1222 imageId = self._list_index[index])
1223   - self.SetStringItem(index, 2, location)
1224   - self.SetStringItem(index, 3, type_)
1225   - self.SetStringItem(index, 4, value)
  1223 + self.SetItem(index, 2, location)
  1224 + self.SetItem(index, 3, type_)
  1225 + self.SetItem(index, 4, value)
1226 1226 self.SetItemImage(index, 1)
1227 1227 self.Refresh()
1228 1228  
1229 1229 def UpdateItemInfo(self, index=0, label="Measurement 1", colour=None,
1230 1230 location="SURFACE", type_="LINEAR", value="0 mm"):
1231   - self.SetStringItem(index, 1, label,
  1231 + self.SetItem(index, 1, label,
1232 1232 imageId = self._list_index[index])
1233   - self.SetStringItem(index, 2, location)
1234   - self.SetStringItem(index, 3, type_)
1235   - self.SetStringItem(index, 4, value)
  1233 + self.SetItem(index, 2, location)
  1234 + self.SetItem(index, 3, type_)
  1235 + self.SetItem(index, 4, value)
1236 1236 self.SetItemImage(index, 1)
1237 1237 self.Refresh()
1238 1238  
... ... @@ -1249,13 +1249,13 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.CheckLis
1249 1249 for i in colour]
1250 1250 new_image.putpixel((x,y), tuple(pixel_colour))
1251 1251  
1252   - wx_image = wx.EmptyImage(new_image.size[0],
1253   - new_image.size[1])
  1252 + wx_image = wx.Image(new_image.size[0],
  1253 + new_image.size[1])
1254 1254 try:
1255 1255 wx_image.SetData(new_image.tostring())
1256 1256 except:
1257 1257 wx_image.SetData(new_image.tobytes())
1258   - return wx.BitmapFromImage(wx_image.Scale(16, 16))
  1258 + return wx.Bitmap(wx_image.Scale(16, 16))
1259 1259  
1260 1260 def EditItemColour(self, measure_index, colour):
1261 1261 """
... ... @@ -1310,19 +1310,19 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.Check
1310 1310 self.imagelist = wx.ImageList(16, 16)
1311 1311  
1312 1312 image = wx.Image(os.path.join(const.ICON_DIR, "object_visible.jpg"))
1313   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  1313 + bitmap = wx.Bitmap(image.Scale(16, 16))
1314 1314 bitmap.SetWidth(16)
1315 1315 bitmap.SetHeight(16)
1316 1316 img_check = self.imagelist.Add(bitmap)
1317 1317  
1318 1318 image = wx.Image(os.path.join(const.ICON_DIR, "object_invisible.jpg"))
1319   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  1319 + bitmap = wx.Bitmap(image.Scale(16, 16))
1320 1320 bitmap.SetWidth(16)
1321 1321 bitmap.SetHeight(16)
1322 1322 img_null = self.imagelist.Add(bitmap)
1323 1323  
1324 1324 image = wx.Image(os.path.join(const.ICON_DIR, "object_colour.jpg"))
1325   - bitmap = wx.BitmapFromImage(image.Scale(16, 16))
  1325 + bitmap = wx.Bitmap(image.Scale(16, 16))
1326 1326 bitmap.SetWidth(16)
1327 1327 bitmap.SetHeight(16)
1328 1328 self.img_colour = self.imagelist.Add(bitmap)
... ... @@ -1342,10 +1342,10 @@ class AnnotationsListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin, listmix.Check
1342 1342  
1343 1343 def InsertNewItem(self, index=0, name="Axial 1", type_="2d",
1344 1344 value="bla", colour=None):
1345   - self.InsertStringItem(index, "")
1346   - self.SetStringItem(index, 1, name, imageId = self.img_colour)
1347   - self.SetStringItem(index, 2, type_)
1348   - self.SetStringItem(index, 3, value)
  1345 + self.InsertItem(index, "")
  1346 + self.SetItem(index, 1, name, imageId = self.img_colour)
  1347 + self.SetItem(index, 2, type_)
  1348 + self.SetItem(index, 3, value)
1349 1349  
1350 1350 def Populate(self):
1351 1351 dict = ((0, "Axial 1", "2D", "blalbalblabllablalbla"),
... ...
invesalius/gui/default_tasks.py
... ... @@ -58,12 +58,12 @@ zzW\xcff&amp;\xb8,\x89\xa8@Q\xd6\xaaf\xdfRm,\xee\xb1BDxr#\xae\xf5|\xddo\xd6\xe2H\
58 58 \x00\x00\x00IEND\xaeB`\x82'
59 59  
60 60 def GetCollapsedIconBitmap():
61   - return wx.BitmapFromImage(GetCollapsedIconImage())
  61 + return wx.Bitmap(GetCollapsedIconImage())
62 62  
63 63 def GetCollapsedIconImage():
64 64 from io import BytesIO
65 65 stream = BytesIO(GetCollapsedIconData())
66   - return wx.ImageFromStream(stream)
  66 + return wx.Image(stream)
67 67  
68 68 def GetExpandedIconData():
69 69 return \
... ... @@ -89,12 +89,12 @@ b&#39;\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
89 89 `\x82'
90 90  
91 91 def GetExpandedIconBitmap():
92   - return wx.BitmapFromImage(GetExpandedIconImage())
  92 + return wx.Bitmap(GetExpandedIconImage())
93 93  
94 94 def GetExpandedIconImage():
95 95 from io import BytesIO
96 96 stream = BytesIO(GetExpandedIconData())
97   - return wx.ImageFromStream(stream)
  97 + return wx.Image(stream)
98 98  
99 99  
100 100 # Main panel
... ...
invesalius/gui/default_viewers.py
... ... @@ -506,7 +506,7 @@ class VolumeToolPanel(wx.Panel):
506 506 for name in const.RAYCASTING_TYPES:
507 507 id = wx.NewId()
508 508 item = wx.MenuItem(menu, id, name, kind=wx.ITEM_RADIO)
509   - menu.AppendItem(item)
  509 + menu.Append(item)
510 510 if name == const.RAYCASTING_OFF_LABEL:
511 511 self.off_item = item
512 512 item.Check(1)
... ... @@ -522,12 +522,12 @@ class VolumeToolPanel(wx.Panel):
522 522 self.id_cutplane = id
523 523  
524 524 item = wx.MenuItem(submenu, id, name, kind=wx.ITEM_CHECK)
525   - submenu.AppendItem(item)
  525 + submenu.Append(item)
526 526 ID_TO_TOOL[id] = name
527 527 ID_TO_TOOL_ITEM[id] = item
528 528 TOOL_STATE[id] = False
529 529 self.submenu_raycasting_tools = submenu
530   - menu.AppendMenu(RAYCASTING_TOOLS, _("Tools"), submenu)
  530 + menu.Append(RAYCASTING_TOOLS, _("Tools"), submenu)
531 531 menu.Enable(RAYCASTING_TOOLS, 0)
532 532  
533 533 self.menu_raycasting = menu
... ... @@ -544,7 +544,7 @@ class VolumeToolPanel(wx.Panel):
544 544 bmp = wx.Bitmap(ID_TO_BMP[id][1], wx.BITMAP_TYPE_PNG)
545 545 item = wx.MenuItem(menu, id, ID_TO_BMP[id][0])
546 546 item.SetBitmap(bmp)
547   - menu.AppendItem(item)
  547 + menu.Append(item)
548 548 menu.Bind(wx.EVT_MENU, self.OnMenuView)
549 549 self.menu_view = menu
550 550  
... ... @@ -558,7 +558,7 @@ class VolumeToolPanel(wx.Panel):
558 558 item = wx.MenuItem(slice_plane_menu, new_id, value,
559 559 kind = wx.ITEM_CHECK)
560 560 ID_TO_ITEMSLICEMENU[new_id] = item
561   - slice_plane_menu.AppendItem(item)
  561 + slice_plane_menu.Append(item)
562 562  
563 563 slice_plane_menu.Bind(wx.EVT_MENU, self.OnMenuPlaneSlice)
564 564  
... ... @@ -577,7 +577,7 @@ class VolumeToolPanel(wx.Panel):
577 577  
578 578 ID_TO_ITEM_3DSTEREO[new_id] = item
579 579 ID_TO_STEREO_NAME[new_id] = value
580   - stereo_menu.AppendItem(item)
  580 + stereo_menu.Append(item)
581 581  
582 582 stereo_menu.Bind(wx.EVT_MENU, self.OnMenuStereo)
583 583  
... ...
invesalius/gui/dialogs.py
... ... @@ -48,6 +48,7 @@ from wx.lib.agw import floatspin
48 48 from wx.lib.wordwrap import wordwrap
49 49 from wx.lib.pubsub import pub as Publisher
50 50  
  51 +
51 52 try:
52 53 from wx.adv import AboutDialogInfo, AboutBox
53 54 except ImportError:
... ... @@ -58,6 +59,7 @@ import invesalius.data.coordinates as dco
58 59 import invesalius.gui.widgets.gradient as grad
59 60 import invesalius.session as ses
60 61 import invesalius.utils as utils
  62 +from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl, InvFloatSpinCtrl
61 63 from invesalius.gui.widgets import clut_imagedata
62 64 from invesalius.gui.widgets.clut_imagedata import CLUTImageDataWidget, EVT_CLUT_NODE_CHANGED
63 65 import numpy as np
... ... @@ -78,16 +80,9 @@ EVT_MASK_SET = wx.PyEventBinder(myEVT_MASK_SET, 1)
78 80  
79 81 class NumberDialog(wx.Dialog):
80 82 def __init__(self, message, value=0):
81   - try:
82   - pre = wx.PreDialog()
83   - pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize,
84   - pos=wx.DefaultPosition,
85   - style=wx.DEFAULT_DIALOG_STYLE)
86   - self.PostCreate(pre)
87   - except AttributeError:
88   - wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize,
89   - pos=wx.DefaultPosition,
90   - style=wx.DEFAULT_DIALOG_STYLE)
  83 + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize,
  84 + pos=wx.DefaultPosition,
  85 + style=wx.DEFAULT_DIALOG_STYLE)
91 86  
92 87 # Static text which contains message to user
93 88 label = wx.StaticText(self, -1, message)
... ... @@ -133,16 +128,9 @@ class NumberDialog(wx.Dialog):
133 128 class ResizeImageDialog(wx.Dialog):
134 129  
135 130 def __init__(self):#, message, value=0):
136   - try:
137   - pre = self.pre = wx.PreDialog()
138   - pre.Create(None, -1, "InVesalius 3", size=wx.DefaultSize,
139   - pos=wx.DefaultPosition,
140   - style=wx.DEFAULT_DIALOG_STYLE)
141   - self.PostCreate(pre)
142   - except AttributeError:
143   - wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize,
144   - pos=wx.DefaultPosition,
145   - style=wx.DEFAULT_DIALOG_STYLE)
  131 + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=wx.DefaultSize,
  132 + pos=wx.DefaultPosition,
  133 + style=wx.DEFAULT_DIALOG_STYLE)
146 134  
147 135 lbl_message = wx.StaticText(self, -1, _("InVesalius is running on a 32-bit operating system or has insufficient memory. \nIf you want to work with 3D surfaces or volume rendering, \nit is recommended to reduce the medical images resolution."))
148 136 icon = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MESSAGE_BOX, (32,32))
... ... @@ -160,8 +148,7 @@ class ResizeImageDialog(wx.Dialog):
160 148  
161 149 lbl_message_percent = wx.StaticText(self, -1,_("Percentage of original resolution"))
162 150  
163   - num_ctrl_percent = wx.SpinCtrl(self, -1)
164   - num_ctrl_percent.SetRange(20,100)
  151 + num_ctrl_percent = InvSpinCtrl(self, -1, value=100, min_value=20, max_value=100)
165 152 self.num_ctrl_porcent = num_ctrl_percent
166 153  
167 154 sizer_percent = wx.BoxSizer(wx.HORIZONTAL)
... ... @@ -675,14 +662,8 @@ def ShowLoadRegistrationDialog():
675 662  
676 663 class MessageDialog(wx.Dialog):
677 664 def __init__(self, message):
678   - try:
679   - pre = wx.PreDialog()
680   - pre.Create(None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition,
681   - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
682   - self.PostCreate(pre)
683   - except AttributeError:
684   - wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition,
685   - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
  665 + wx.Dialog.__init__(self, None, -1, "InVesalius 3", size=(360, 370), pos=wx.DefaultPosition,
  666 + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
686 667  
687 668 # Static text which contains message to user
688 669 label = wx.StaticText(self, -1, message)
... ... @@ -721,14 +702,8 @@ class UpdateMessageDialog(wx.Dialog):
721 702 title=_("Invesalius Update")
722 703 self.url = url
723 704  
724   - try:
725   - pre = wx.PreDialog()
726   - pre.Create(None, -1, title, size=(360, 370), pos=wx.DefaultPosition,
727   - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
728   - self.PostCreate(pre)
729   - except AttributeError:
730   - wx.Dialog.__init__(self, None, -1, title, size=(360, 370), pos=wx.DefaultPosition,
731   - style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
  705 + wx.Dialog.__init__(self, None, -1, title, size=(360, 370), pos=wx.DefaultPosition,
  706 + style=wx.DEFAULT_DIALOG_STYLE|wx.ICON_INFORMATION)
732 707  
733 708 # Static text which contains message to user
734 709 label = wx.StaticText(self, -1, msg)
... ... @@ -1066,22 +1041,8 @@ class NewMask(wx.Dialog):
1066 1041 import invesalius.data.mask as mask
1067 1042 import invesalius.project as prj
1068 1043  
1069   - try:
1070   - # Instead of calling wx.Dialog.__init__ we precreate the dialog
1071   - # so we can set an extra style that must be set before
1072   - # creation, and then we create the GUI object using the Create
1073   - # method.
1074   - pre = wx.PreDialog()
1075   - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1076   - pre.Create(parent, ID, title, pos, (500,300), style)
1077   - # This next step is the most important, it turns this Python
1078   - # object into the real wrapper of the dialog (instead of pre)
1079   - # as far as the wxPython extension is concerned.
1080   - self.PostCreate(pre)
1081   - except AttributeError:
1082   - wx.Dialog.__init__(self, parent, ID, title, pos, (500,300), style)
1083   - self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1084   -
  1044 + wx.Dialog.__init__(self, parent, ID, title, pos, style=style)
  1045 + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1085 1046  
1086 1047 self.CenterOnScreen()
1087 1048  
... ... @@ -1127,10 +1088,10 @@ class NewMask(wx.Dialog):
1127 1088 self.colour = original_colour
1128 1089 colour = [255*i for i in original_colour]
1129 1090 colour.append(100)
1130   - gradient = grad.GradientSlider(self, -1, int(bound_min),
1131   - int(bound_max),
1132   - int(thresh_min), int(thresh_max),
1133   - colour)
  1091 + gradient = grad.GradientCtrl(self, -1, int(bound_min),
  1092 + int(bound_max),
  1093 + int(thresh_min), int(thresh_max),
  1094 + colour)
1134 1095 self.gradient = gradient
1135 1096  
1136 1097 # OVERVIEW
... ... @@ -1162,11 +1123,12 @@ class NewMask(wx.Dialog):
1162 1123 # Merge all sizers and checkboxes
1163 1124 sizer = wx.BoxSizer(wx.VERTICAL)
1164 1125 sizer.Add(fixed_sizer, 0, wx.ALL|wx.GROW|wx.EXPAND, 15)
1165   - sizer.Add(gradient, 1, wx.BOTTOM|wx.RIGHT|wx.LEFT|wx.EXPAND|wx.GROW, 20)
  1126 + sizer.Add(gradient, 0, wx.BOTTOM|wx.RIGHT|wx.LEFT|wx.EXPAND|wx.GROW, 20)
1166 1127 sizer.Add(btnsizer, 0, wx.ALIGN_RIGHT|wx.BOTTOM, 10)
1167 1128  
1168 1129 self.SetSizer(sizer)
1169 1130 sizer.Fit(self)
  1131 + self.Layout()
1170 1132  
1171 1133 self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnSlideChanged, self.gradient)
1172 1134 self.combo_thresh.Bind(wx.EVT_COMBOBOX, self.OnComboThresh)
... ... @@ -1362,22 +1324,8 @@ class NewSurfaceDialog(wx.Dialog):
1362 1324 import invesalius.data.surface as surface
1363 1325 import invesalius.project as prj
1364 1326  
1365   - try:
1366   - # Instead of calling wx.Dialog.__init__ we precreate the dialog
1367   - # so we can set an extra style that must be set before
1368   - # creation, and then we create the GUI object using the Create
1369   - # method.
1370   - pre = wx.PreDialog()
1371   - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1372   - pre.Create(parent, ID, title, pos, (500,300), style)
1373   -
1374   - # This next step is the most important, it turns this Python
1375   - # object into the real wrapper of the dialog (instead of pre)
1376   - # as far as the wxPython extension is concerned.
1377   - self.PostCreate(pre)
1378   - except AttributeError:
1379   - wx.Dialog.__init__(self, parent, ID, title, pos, (500,300), style)
1380   - self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
  1327 + wx.Dialog.__init__(self, parent, ID, title, pos, (500,300), style)
  1328 + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1381 1329  
1382 1330 self.CenterOnScreen()
1383 1331  
... ... @@ -1579,28 +1527,10 @@ class SurfaceCreationDialog(wx.Dialog):
1579 1527 style=wx.DEFAULT_DIALOG_STYLE, useMetal=False,
1580 1528 mask_edited=False):
1581 1529  
1582   - # Instead of calling wx.Dialog.__init__ we precreate the dialog
1583   - # so we can set an extra style that must be set before
1584   - # creation, and then we create the GUI object using the Create
1585   - # method.
1586   - try:
1587   - pre = wx.PreDialog()
1588   - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1589   - pre.Create(parent, ID, title, pos, (500,300), style)
1590   -
1591   - # This extra style can be set after the UI object has been created.
1592   - if 'wxMac' in wx.PlatformInfo and useMetal:
1593   - self.SetExtraStyle(wx.DIALOG_EX_METAL)
1594   -
1595   - # This next step is the most important, it turns this Python
1596   - # object into the real wrapper of the dialog (instead of pre)
1597   - # as far as the wxPython extension is concerned.
1598   - self.PostCreate(pre)
1599   - except AttributeError:
1600   - wx.Dialog.__init__(self, parent, ID, title, pos, size, style)
1601   - self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
1602   - if 'wxMac' in wx.PlatformInfo and useMetal:
1603   - self.SetExtraStyle(wx.DIALOG_EX_METAL)
  1530 + wx.Dialog.__init__(self, parent, ID, title, pos, size, style)
  1531 + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
  1532 + if 'wxMac' in wx.PlatformInfo and useMetal:
  1533 + self.SetExtraStyle(wx.DIALOG_EX_METAL)
1604 1534  
1605 1535 self.CenterOnScreen()
1606 1536  
... ... @@ -1772,19 +1702,19 @@ class CAOptions(wx.Panel):
1772 1702  
1773 1703 def _build_widgets(self):
1774 1704 sb = wx.StaticBox(self, -1, _('Options'))
1775   - self.angle = floatspin.FloatSpin(self, -1, value=0.7, min_val=0.0,
1776   - max_val=1.0, increment=0.1,
1777   - digits=1)
  1705 + self.angle = InvFloatSpinCtrl(self, -1, value=0.7, min_value=0.0,
  1706 + max_value=1.0, increment=0.1,
  1707 + digits=1)
1778 1708  
1779   - self.max_distance = floatspin.FloatSpin(self, -1, value=3.0, min_val=0.0,
1780   - max_val=100.0, increment=0.1,
  1709 + self.max_distance = InvFloatSpinCtrl(self, -1, value=3.0, min_value=0.0,
  1710 + max_value=100.0, increment=0.1,
1781 1711 digits=2)
1782 1712  
1783   - self.min_weight = floatspin.FloatSpin(self, -1, value=0.5, min_val=0.0,
1784   - max_val=1.0, increment=0.1,
  1713 + self.min_weight = InvFloatSpinCtrl(self, -1, value=0.5, min_value=0.0,
  1714 + max_value=1.0, increment=0.1,
1785 1715 digits=1)
1786 1716  
1787   - self.steps = wx.SpinCtrl(self, -1, value='10', min=1, max=100)
  1717 + self.steps = InvSpinCtrl(self, -1, value=10, min_value=1, max_value=100)
1788 1718  
1789 1719 layout_sizer = wx.FlexGridSizer(rows=4, cols=2, hgap=5, vgap=5)
1790 1720 layout_sizer.Add(wx.StaticText(self, -1, _(u'Angle:')), 0, wx.EXPAND)
... ... @@ -1826,12 +1756,12 @@ class SurfaceMethodPanel(wx.Panel):
1826 1756 choices=[i for i in sorted(self.alg_types)
1827 1757 if not (self.mask_edited and i in self.edited_imp)],
1828 1758 style=wx.CB_READONLY)
1829   - w, h = self.cb_types.GetSizeTuple()
  1759 + w, h = self.cb_types.GetSize()
1830 1760  
1831 1761 icon = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_MESSAGE_BOX,
1832 1762 (h * 0.8, h * 0.8))
1833 1763 self.bmp = wx.StaticBitmap(self, -1, icon)
1834   - self.bmp.SetToolTipString(_("It is not possible to use the Default method because the mask was edited."))
  1764 + self.bmp.SetToolTip(_("It is not possible to use the Default method because the mask was edited."))
1835 1765  
1836 1766 self.method_sizer = wx.BoxSizer(wx.HORIZONTAL)
1837 1767 self.method_sizer.Add(wx.StaticText(self, -1, _(u'Method:')), 0,
... ... @@ -1906,12 +1836,7 @@ class SurfaceMethodPanel(wx.Panel):
1906 1836  
1907 1837 class ClutImagedataDialog(wx.Dialog):
1908 1838 def __init__(self, histogram, init, end, nodes=None):
1909   - try:
1910   - pre = wx.PreDialog()
1911   - pre.Create(wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
1912   - self.PostCreate(pre)
1913   - except AttributeError:
1914   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
  1839 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
1915 1840  
1916 1841 self.histogram = histogram
1917 1842 self.init = init
... ... @@ -1981,8 +1906,8 @@ class WatershedOptionsPanel(wx.Panel):
1981 1906 style=wx.NO_BORDER | wx.HORIZONTAL)
1982 1907 self.choice_3dcon.SetSelection(self.con3d_choices.index(self.config.con_3d))
1983 1908  
1984   - self.gaussian_size = wx.SpinCtrl(self, -1, "", min=1, max=10)
1985   - self.gaussian_size.SetValue(self.config.mg_size)
  1909 + self.gaussian_size = InvSpinCtrl(self, -1, value=self.config.mg_size,
  1910 + min_value=1, max_value=10)
1986 1911  
1987 1912 box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Conectivity"), wx.VERTICAL)
1988 1913 box_sizer.Add(self.choice_2dcon, 0, wx.ALIGN_CENTER_VERTICAL,2)
... ... @@ -2010,12 +1935,7 @@ class WatershedOptionsPanel(wx.Panel):
2010 1935  
2011 1936 class WatershedOptionsDialog(wx.Dialog):
2012 1937 def __init__(self, config, ID=-1, title=_(u'Watershed'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP):
2013   - try:
2014   - pre = wx.PreDialog()
2015   - pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2016   - self.PostCreate(pre)
2017   - except AttributeError:
2018   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
  1938 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2019 1939  
2020 1940 self.config = config
2021 1941  
... ... @@ -2054,12 +1974,7 @@ class WatershedOptionsDialog(wx.Dialog):
2054 1974  
2055 1975 class MaskBooleanDialog(wx.Dialog):
2056 1976 def __init__(self, masks, ID=-1, title=_(u"Boolean operations"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP):
2057   - try:
2058   - pre = wx.PreDialog()
2059   - pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2060   - self.PostCreate(pre)
2061   - except AttributeError:
2062   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
  1977 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2063 1978  
2064 1979 self._init_gui(masks)
2065 1980 self.CenterOnScreen()
... ... @@ -2138,12 +2053,7 @@ class MaskBooleanDialog(wx.Dialog):
2138 2053  
2139 2054 class ReorientImageDialog(wx.Dialog):
2140 2055 def __init__(self, ID=-1, title=_(u'Image reorientation'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP):
2141   - try:
2142   - pre = wx.PreDialog()
2143   - pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2144   - self.PostCreate(pre)
2145   - except AttributeError:
2146   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
  2056 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2147 2057  
2148 2058 self._closed = False
2149 2059  
... ... @@ -2263,16 +2173,10 @@ class ImportBitmapParameters(wx.Dialog):
2263 2173 else:
2264 2174 size=wx.Size(380,210)
2265 2175  
2266   - try:
2267   - pre = wx.PreDialog()
2268   - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Create project from bitmap"),size=size,
2269   - style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2270   - self.PostCreate(pre)
2271   - except AttributeError:
2272   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1,
2273   - _(u"Create project from bitmap"),
2274   - size=size,
2275   - style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
  2176 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1,
  2177 + _(u"Create project from bitmap"),
  2178 + size=size,
  2179 + style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2276 2180  
2277 2181 self.interval = 0
2278 2182  
... ... @@ -2325,16 +2229,16 @@ class ImportBitmapParameters(wx.Dialog):
2325 2229 gbs_spacing = wx.GridBagSizer(2, 6)
2326 2230  
2327 2231 stx_spacing_x = stx_spacing_x = wx.StaticText(p, -1, _(u"X:"))
2328   - fsp_spacing_x = self.fsp_spacing_x = FS.FloatSpin(p, -1, min_val=0,\
  2232 + fsp_spacing_x = self.fsp_spacing_x = InvFloatSpinCtrl(p, -1, min_value=0, max_value=1000000000,
2329 2233 increment=0.25, value=1.0, digits=8)
2330 2234  
2331 2235  
2332 2236 stx_spacing_y = stx_spacing_y = wx.StaticText(p, -1, _(u"Y:"))
2333   - fsp_spacing_y = self.fsp_spacing_y = FS.FloatSpin(p, -1, min_val=0,\
  2237 + fsp_spacing_y = self.fsp_spacing_y = InvFloatSpinCtrl(p, -1, min_value=0, max_value=1000000000,
2334 2238 increment=0.25, value=1.0, digits=8)
2335 2239  
2336 2240 stx_spacing_z = stx_spacing_z = wx.StaticText(p, -1, _(u"Z:"))
2337   - fsp_spacing_z = self.fsp_spacing_z = FS.FloatSpin(p, -1, min_val=0,\
  2241 + fsp_spacing_z = self.fsp_spacing_z = InvFloatSpinCtrl(p, -1, min_value=0, max_value=1000000000,
2338 2242 increment=0.25, value=1.0, digits=8)
2339 2243  
2340 2244  
... ... @@ -2594,12 +2498,11 @@ class PanelFFillDynamic(wx.Panel):
2594 2498 self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW&WL"))
2595 2499 self.use_ww_wl.SetValue(self.config.use_ww_wl)
2596 2500  
2597   - self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000)
2598   - w, h = self.deviation_min.GetTextExtent('M')
2599   - self.deviation_min.SetMinSize((w*5, -1))
  2501 + self.deviation_min = InvSpinCtrl(self, -1, value=self.config.dev_min, min_value=0, max_value=10000)
  2502 + self.deviation_min.CalcSizeFromTextSize()
2600 2503  
2601   - self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000)
2602   - self.deviation_max.SetMinSize((w*5, -1))
  2504 + self.deviation_max = InvSpinCtrl(self, -1, value=self.config.dev_max, min_value=0, max_value=10000)
  2505 + self.deviation_max.CalcSizeFromTextSize()
2603 2506  
2604 2507 sizer = wx.GridBagSizer(5, 5)
2605 2508  
... ... @@ -2656,17 +2559,16 @@ class PanelFFillConfidence(wx.Panel):
2656 2559 self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW&WL"))
2657 2560 self.use_ww_wl.SetValue(self.config.use_ww_wl)
2658 2561  
2659   - self.spin_mult = floatspin.FloatSpin(self, -1,
2660   - value=self.config.confid_mult,
2661   - min_val=1.0, max_val=10.0,
2662   - increment=0.1, digits=1,
2663   - style=wx.TE_PROCESS_TAB|wx.TE_PROCESS_ENTER,
2664   - agwStyle=floatspin.FS_RIGHT)
2665   - w, h = self.spin_mult.GetTextExtent('M')
2666   - self.spin_mult.SetMinSize((w*7, -1))
  2562 + self.spin_mult = InvFloatSpinCtrl(self, -1,
  2563 + value=self.config.confid_mult,
  2564 + min_value=1.0, max_value=10.0,
  2565 + increment=0.1, digits=1)
  2566 + # style=wx.TE_PROCESS_TAB|wx.TE_PROCESS_ENTER,
  2567 + # agwStyle=floatspin.FS_RIGHT)
  2568 + self.spin_mult.CalcSizeFromTextSize()
2667 2569  
2668   - self.spin_iters = wx.SpinCtrl(self, -1, value='%d' % self.config.confid_iters, min=0, max=100)
2669   - self.spin_iters.SetMinSize((w*7, -1))
  2570 + self.spin_iters = InvSpinCtrl(self, -1, value=self.config.confid_iters, min_value=0, max_value=100)
  2571 + self.spin_iters.CalcSizeFromTextSize()
2670 2572  
2671 2573 sizer = wx.GridBagSizer(5, 5)
2672 2574  
... ... @@ -2713,12 +2615,7 @@ class PanelFFillConfidence(wx.Panel):
2713 2615  
2714 2616 class FFillOptionsDialog(wx.Dialog):
2715 2617 def __init__(self, title, config):
2716   - try:
2717   - pre = wx.PreDialog()
2718   - pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2719   - self.PostCreate(pre)
2720   - except AttributeError:
2721   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
  2618 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2722 2619  
2723 2620 self.config = config
2724 2621  
... ... @@ -2826,12 +2723,7 @@ class FFillOptionsDialog(wx.Dialog):
2826 2723  
2827 2724 class SelectPartsOptionsDialog(wx.Dialog):
2828 2725 def __init__(self, config):
2829   - try:
2830   - pre = wx.PreDialog()
2831   - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2832   - self.PostCreate(pre)
2833   - except AttributeError:
2834   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
  2726 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Select mask parts"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
2835 2727  
2836 2728 self.config = config
2837 2729  
... ... @@ -2911,12 +2803,7 @@ class SelectPartsOptionsDialog(wx.Dialog):
2911 2803  
2912 2804 class FFillSegmentationOptionsDialog(wx.Dialog):
2913 2805 def __init__(self, config, ID=-1, title=_(u"Region growing"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP):
2914   - try:
2915   - pre = wx.PreDialog()
2916   - pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2917   - self.PostCreate(pre)
2918   - except AttributeError:
2919   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
  2806 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
2920 2807  
2921 2808 self.config = config
2922 2809  
... ... @@ -3117,15 +3004,7 @@ class CropOptionsDialog(wx.Dialog):
3117 3004  
3118 3005 def __init__(self, config, ID=-1, title=_(u"Crop mask"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP):
3119 3006 self.config = config
3120   - try:
3121   - pre = wx.PreDialog()
3122   -
3123   - pre.Create(wx.GetApp().GetTopWindow(), ID, title=title, style=style)
3124   - self.PostCreate(pre)
3125   - except AttributeError:
3126   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
3127   -
3128   -
  3007 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), ID, title=title, style=style)
3129 3008 self._init_gui()
3130 3009  
3131 3010 def UpdateValues(self, limits):
... ... @@ -3236,13 +3115,7 @@ class CropOptionsDialog(wx.Dialog):
3236 3115  
3237 3116 class FillHolesAutoDialog(wx.Dialog):
3238 3117 def __init__(self, title):
3239   - try:
3240   - pre = wx.PreDialog()
3241   - pre.Create(wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
3242   - self.PostCreate(pre)
3243   - except AttributeError:
3244   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
3245   -
  3118 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
3246 3119 self._init_gui()
3247 3120  
3248 3121 def _init_gui(self):
... ... @@ -3251,7 +3124,7 @@ class FillHolesAutoDialog(wx.Dialog):
3251 3124 else:
3252 3125 border_style = wx.SUNKEN_BORDER
3253 3126  
3254   - self.spin_size = wx.SpinCtrl(self, -1, value='1000', min=1, max=1000000000)
  3127 + self.spin_size = InvSpinCtrl(self, -1, value=1000, min_value=1, max_value=1000000000)
3255 3128 self.panel_target = PanelTargeFFill(self, style=border_style|wx.TAB_TRAVERSAL)
3256 3129 self.panel2dcon = Panel2DConnectivity(self, show_orientation=True, style=border_style|wx.TAB_TRAVERSAL)
3257 3130 self.panel3dcon = Panel3DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL)
... ... @@ -3340,14 +3213,8 @@ class FillHolesAutoDialog(wx.Dialog):
3340 3213  
3341 3214 class MaskDensityDialog(wx.Dialog):
3342 3215 def __init__(self, title):
3343   - try:
3344   - pre = wx.PreDialog()
3345   - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Mask density"), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT)
3346   - self.PostCreate(pre)
3347   - except AttributeError:
3348   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Mask density"),
3349   - style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT)
3350   -
  3216 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Mask density"),
  3217 + style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT)
3351 3218 self._init_gui()
3352 3219 self._bind_events()
3353 3220  
... ... @@ -3456,14 +3323,8 @@ class ObjectCalibrationDialog(wx.Dialog):
3456 3323 self.obj_fiducials = np.full([5, 3], np.nan)
3457 3324 self.obj_orients = np.full([5, 3], np.nan)
3458 3325  
3459   - try:
3460   - pre = wx.PreDialog()
3461   - pre.Create(wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440),
3462   - style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
3463   - self.PostCreate(pre)
3464   - except AttributeError:
3465   - wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440),
3466   - style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
  3326 + wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, _(u"Object calibration"), size=(450, 440),
  3327 + style=wx.DEFAULT_DIALOG_STYLE | wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP)
3467 3328  
3468 3329 self._init_gui()
3469 3330 self.LoadObject()
... ...
invesalius/gui/dicom_preview_panel.py
... ... @@ -149,7 +149,7 @@ class DicomPaintPanel(wx.Panel):
149 149 self.Bind(wx.EVT_SIZE, self.OnSize)
150 150  
151 151 def _build_bitmap(self, image):
152   - bmp = wx.BitmapFromImage(image)
  152 + bmp = wx.Bitmap(image)
153 153 return bmp
154 154  
155 155 def _image_resize(self, image):
... ...
invesalius/gui/frame.py
... ... @@ -820,7 +820,7 @@ class MenuBar(wx.MenuBar):
820 820 app = file_menu.Append
821 821 app(const.ID_DICOM_IMPORT, _("Import DICOM...\tCtrl+I"))
822 822 #app(const.ID_DICOM_NETWORK, _("Retrieve DICOM from PACS"))
823   - file_menu.AppendMenu(const.ID_IMPORT_OTHERS_FILES, _("Import other files..."), others_file_menu)
  823 + file_menu.Append(const.ID_IMPORT_OTHERS_FILES, _("Import other files..."), others_file_menu)
824 824 app(const.ID_PROJECT_OPEN, _("Open project...\tCtrl+O"))
825 825 app(const.ID_PROJECT_SAVE, _("Save project\tCtrl+S"))
826 826 app(const.ID_PROJECT_SAVE_AS, _("Save project as...\tCtrl+Shift+S"))
... ... @@ -848,12 +848,12 @@ class MenuBar(wx.MenuBar):
848 848  
849 849 file_edit_item_undo = wx.MenuItem(file_edit, wx.ID_UNDO, _("Undo\tCtrl+Z"))
850 850 file_edit_item_undo.SetBitmap(self.BMP_UNDO)
851   - file_edit.AppendItem(file_edit_item_undo)
  851 + file_edit.Append(file_edit_item_undo)
852 852 file_edit_item_undo.Enable(False)
853 853  
854 854 file_edit_item_redo = wx.MenuItem(file_edit, wx.ID_REDO, _("Redo\tCtrl+Y"))
855 855 file_edit_item_redo.SetBitmap(self.BMP_REDO)
856   - file_edit.AppendItem(file_edit_item_redo)
  856 + file_edit.Append(file_edit_item_redo)
857 857 file_edit_item_redo.Enable(False)
858 858 else:
859 859 file_edit.Append(wx.ID_UNDO, _("Undo\tCtrl+Z")).Enable(False)
... ... @@ -925,17 +925,17 @@ class MenuBar(wx.MenuBar):
925 925 swap_axes_menu.Append(const.ID_SWAP_XZ, _("From Right-Left to Top-Bottom")).Enable(False)
926 926 swap_axes_menu.Append(const.ID_SWAP_YZ, _("From Anterior-Posterior to Top-Bottom")).Enable(False)
927 927  
928   - image_menu.AppendMenu(wx.NewId(), _('Flip'), flip_menu)
929   - image_menu.AppendMenu(wx.NewId(), _('Swap axes'), swap_axes_menu)
  928 + image_menu.Append(wx.NewId(), _('Flip'), flip_menu)
  929 + image_menu.Append(wx.NewId(), _('Swap axes'), swap_axes_menu)
930 930  
931 931 mask_density_menu = image_menu.Append(const.ID_MASK_DENSITY_MEASURE, _(u'Mask Density measure'))
932 932 reorient_menu = image_menu.Append(const.ID_REORIENT_IMG, _(u'Reorient image\tCtrl+Shift+R'))
933 933  
934 934 reorient_menu.Enable(False)
935   - tools_menu.AppendMenu(-1, _(u'Image'), image_menu)
936   - tools_menu.AppendMenu(-1, _(u"Mask"), mask_menu)
937   - tools_menu.AppendMenu(-1, _(u"Segmentation"), segmentation_menu)
938   - tools_menu.AppendMenu(-1, _(u"Surface"), surface_menu)
  935 + tools_menu.Append(-1, _(u'Image'), image_menu)
  936 + tools_menu.Append(-1, _(u"Mask"), mask_menu)
  937 + tools_menu.Append(-1, _(u"Segmentation"), segmentation_menu)
  938 + tools_menu.Append(-1, _(u"Surface"), surface_menu)
939 939  
940 940 #View
941 941 self.view_menu = view_menu = wx.Menu()
... ... @@ -961,7 +961,7 @@ class MenuBar(wx.MenuBar):
961 961  
962 962 #view_menu = wx.Menu()
963 963 #app = view_menu.Append
964   - #appm = view_menu.AppendMenu
  964 + #appm = view_menu.Append
965 965 #appm(-1, "Toolbars",view_tool_menu)
966 966 #appm(-1, "Layout", view_layout_menu)
967 967 #view_menu.AppendSeparator()
... ... @@ -2007,8 +2007,8 @@ class HistoryToolBar(AuiToolBar):
2007 2007 Bind normal events from wx (except pubsub related).
2008 2008 """
2009 2009 #self.Bind(wx.EVT_TOOL, self.OnToggle)
2010   - wx.EVT_TOOL( self, wx.ID_UNDO, self.OnUndo )
2011   - wx.EVT_TOOL( self, wx.ID_REDO, self.OnRedo )
  2010 + self.Bind(wx.EVT_TOOL, self.OnUndo, id=wx.ID_UNDO)
  2011 + self.Bind(wx.EVT_TOOL, self.OnRedo, id=wx.ID_REDO)
2012 2012  
2013 2013 def __init_items(self):
2014 2014 """
... ...
invesalius/gui/import_network_panel.py
... ... @@ -675,24 +675,24 @@ class NodesPanel(wx.Panel):
675 675  
676 676 self.hosts[0] = [True, "localhost", "", "invesalius"]
677 677 try:
678   - index = self.tree_node.InsertStringItem(sys.maxsize, "")
  678 + index = self.tree_node.InsertItem(sys.maxsize, "")
679 679 except (OverflowError, AssertionError):
680   - index = self.tree_node.InsertStringItem(sys.maxint, "")
681   - self.tree_node.SetStringItem(index, 1, "localhost")
682   - self.tree_node.SetStringItem(index, 2, "")
683   - self.tree_node.SetStringItem(index, 3, "invesalius")
684   - self.tree_node.SetStringItem(index, 4, "ok")
  680 + index = self.tree_node.InsertItem(sys.maxint, "")
  681 + self.tree_node.SetItem(index, 1, "localhost")
  682 + self.tree_node.SetItem(index, 2, "")
  683 + self.tree_node.SetItem(index, 3, "invesalius")
  684 + self.tree_node.SetItem(index, 4, "ok")
685 685 self.tree_node.CheckItem(index)
686 686 self.tree_node.SetItemBackgroundColour(index, wx.Colour(245,245,245))
687 687 #print ">>>>>>>>>>>>>>>>>>>>>", sys.maxint
688   - #index = self.tree_node.InsertStringItem(sys.maxint, "")#adiciona vazio a coluna de check
689   - #self.tree_node.SetStringItem(index, 1, "200.144.114.19")
690   - #self.tree_node.SetStringItem(index, 2, "80")
  688 + #index = self.tree_node.InsertItem(sys.maxint, "")#adiciona vazio a coluna de check
  689 + #self.tree_node.SetItem(index, 1, "200.144.114.19")
  690 + #self.tree_node.SetItem(index, 2, "80")
691 691 #self.tree_node.SetItemData(index, 0)
692 692  
693   - #index2 = self.tree_node.InsertStringItem(sys.maxint, "")#adiciona vazio a coluna de check
694   - #self.tree_node.SetStringItem(index2, 1, "200.144.114.19")
695   - #self.tree_node.SetStringItem(index2, 2, "80")
  693 + #index2 = self.tree_node.InsertItem(sys.maxint, "")#adiciona vazio a coluna de check
  694 + #self.tree_node.SetItem(index2, 1, "200.144.114.19")
  695 + #self.tree_node.SetItem(index2, 2, "80")
696 696 #self.tree_node.SetItemData(index2, 0)
697 697  
698 698 self.btn_add = wx.Button(self, -1, _("Add"))
... ... @@ -732,12 +732,12 @@ class NodesPanel(wx.Panel):
732 732  
733 733 def OnButtonAdd(self, evt):
734 734 #adiciona vazio a coluna de check
735   - index = self.tree_node.InsertStringItem(sys.maxsize, "")
  735 + index = self.tree_node.InsertItem(sys.maxsize, "")
736 736  
737 737 self.hosts[index] = [True, "localhost", "80", ""]
738   - self.tree_node.SetStringItem(index, 1, "localhost")
739   - self.tree_node.SetStringItem(index, 2, "80")
740   - self.tree_node.SetStringItem(index, 3, "")
  738 + self.tree_node.SetItem(index, 1, "localhost")
  739 + self.tree_node.SetItem(index, 2, "80")
  740 + self.tree_node.SetItem(index, 3, "")
741 741 self.tree_node.CheckItem(index)
742 742  
743 743 def OnLeftDown(self, evt):
... ... @@ -770,9 +770,9 @@ class NodesPanel(wx.Panel):
770 770 dn.SetAETitle(self.hosts[0][3])
771 771  
772 772 if dn.RunCEcho():
773   - self.tree_node.SetStringItem(key, 4, _("ok"))
  773 + self.tree_node.SetItem(key, 4, _("ok"))
774 774 else:
775   - self.tree_node.SetStringItem(key, 4, _("error"))
  775 + self.tree_node.SetItem(key, 4, _("error"))
776 776  
777 777 def RightButton(self,evt):
778 778 event.Skip()
... ...
invesalius/gui/preferences.py
... ... @@ -17,15 +17,8 @@ class Preferences(wx.Dialog):
17 17 def __init__( self, parent, id = ID, title = _("Preferences"), size=wx.DefaultSize,\
18 18 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
19 19  
20   - try:
21   - pre = wx.PreDialog()
22   - pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
23   - pre.Create(parent, ID, title, pos, size, style)
24   -
25   - self.PostCreate(pre)
26   - except AttributeError:
27   - wx.Dialog.__init__(self, parent, ID, title, pos, size, style)
28   - self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
  20 + wx.Dialog.__init__(self, parent, ID, title, pos, size, style)
  21 + self.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
29 22  
30 23 sizer = wx.BoxSizer(wx.VERTICAL)
31 24  
... ...
invesalius/gui/task_exporter.py
... ... @@ -257,7 +257,7 @@ class InnerTaskPanel(wx.Panel):
257 257  
258 258 for id in self.id_to_name:
259 259 item = wx.MenuItem(menu, id, self.id_to_name[id])
260   - menu.AppendItem(item)
  260 + menu.Append(item)
261 261  
262 262 self.menu_picture = menu
263 263 menu.Bind(wx.EVT_MENU, self.OnMenuPicture)
... ...
invesalius/gui/task_navigator.py
... ... @@ -1093,7 +1093,7 @@ class MarkersPanel(wx.Panel):
1093 1093 if id_label == 'TARGET':
1094 1094 id_label = ''
1095 1095 dlg.InvalidTargetID()
1096   - self.lc.SetStringItem(list_index, 4, id_label)
  1096 + self.lc.SetItem(list_index, 4, id_label)
1097 1097 # Add the new ID to exported list
1098 1098 if len(self.list_coord[list_index]) > 8:
1099 1099 self.list_coord[list_index][10] = str(id_label)
... ... @@ -1107,7 +1107,7 @@ class MarkersPanel(wx.Panel):
1107 1107 if self.tgt_flag:
1108 1108 self.lc.SetItemBackgroundColour(self.tgt_index, 'white')
1109 1109 Publisher.sendMessage('Set target transparency', status=False, index=self.tgt_index)
1110   - self.lc.SetStringItem(self.tgt_index, 4, '')
  1110 + self.lc.SetItem(self.tgt_index, 4, '')
1111 1111 # Add the new ID to exported list
1112 1112 if len(self.list_coord[self.tgt_index]) > 8:
1113 1113 self.list_coord[self.tgt_index][10] = str('')
... ... @@ -1197,7 +1197,7 @@ class MarkersPanel(wx.Panel):
1197 1197 del self.list_coord[i]
1198 1198 self.lc.DeleteItem(i)
1199 1199 for n in range(0, self.lc.GetItemCount()):
1200   - self.lc.SetStringItem(n, 0, str(n+1))
  1200 + self.lc.SetItem(n, 0, str(n+1))
1201 1201 self.marker_ind -= 1
1202 1202 Publisher.sendMessage('Remove marker', index=index)
1203 1203  
... ... @@ -1312,11 +1312,11 @@ class MarkersPanel(wx.Panel):
1312 1312  
1313 1313 # Add item to list control in panel
1314 1314 num_items = self.lc.GetItemCount()
1315   - self.lc.InsertStringItem(num_items, str(num_items + 1))
1316   - self.lc.SetStringItem(num_items, 1, str(round(coord[0], 2)))
1317   - self.lc.SetStringItem(num_items, 2, str(round(coord[1], 2)))
1318   - self.lc.SetStringItem(num_items, 3, str(round(coord[2], 2)))
1319   - self.lc.SetStringItem(num_items, 4, str(marker_id))
  1315 + self.lc.InsertItem(num_items, str(num_items + 1))
  1316 + self.lc.SetItem(num_items, 1, str(round(coord[0], 2)))
  1317 + self.lc.SetItem(num_items, 2, str(round(coord[1], 2)))
  1318 + self.lc.SetItem(num_items, 3, str(round(coord[2], 2)))
  1319 + self.lc.SetItem(num_items, 4, str(marker_id))
1320 1320 self.lc.EnsureVisible(num_items)
1321 1321  
1322 1322 def GetSelectedItems(self):
... ...
invesalius/gui/task_slice.py
... ... @@ -38,6 +38,7 @@ import invesalius.data.slice_ as slice_
38 38 import invesalius.constants as const
39 39 import invesalius.gui.dialogs as dlg
40 40 import invesalius.gui.widgets.gradient as grad
  41 +from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl
41 42  
42 43 from invesalius.project import Project
43 44 import invesalius.session as ses
... ... @@ -693,8 +694,8 @@ class EditionTools(wx.Panel):
693 694 item2 = wx.MenuItem(menu, MENU_BRUSH_SQUARE, _("Square"))
694 695 item2.SetBitmap(SQUARE_BMP)
695 696  
696   - menu.AppendItem(item)
697   - menu.AppendItem(item2)
  697 + menu.Append(item)
  698 + menu.Append(item2)
698 699  
699 700 bmp_brush_format = {const.BRUSH_CIRCLE: CIRCLE_BMP,
700 701 const.BRUSH_SQUARE: SQUARE_BMP}
... ... @@ -705,14 +706,9 @@ class EditionTools(wx.Panel):
705 706 btn_brush_format.SetMenu(menu)
706 707 self.btn_brush_format = btn_brush_format
707 708  
  709 + spin_brush_size = InvSpinCtrl(self, -1, value=const.BRUSH_SIZE, min_value=1, max_value=1000, spin_button=False)
708 710 # To calculate best width to spinctrl
709   - dc = wx.WindowDC(self)
710   - dc.SetFont(self.GetFont())
711   - width, height = dc.GetTextExtent("MMM")
712   -
713   - spin_brush_size = wx.SpinCtrl(self, -1, "", size=(width + 20, -1))
714   - spin_brush_size.SetRange(1,100)
715   - spin_brush_size.SetValue(const.BRUSH_SIZE)
  711 + spin_brush_size.CalcSizeFromTextSize("MMMM")
716 712 spin_brush_size.Bind(wx.EVT_SPINCTRL, self.OnBrushSize)
717 713 self.spin = spin_brush_size
718 714  
... ... @@ -861,8 +857,8 @@ class WatershedTool(EditionTools):
861 857 item2 = wx.MenuItem(menu, MENU_BRUSH_SQUARE, _("Square"))
862 858 item2.SetBitmap(SQUARE_BMP)
863 859  
864   - menu.AppendItem(item)
865   - menu.AppendItem(item2)
  860 + menu.Append(item)
  861 + menu.Append(item2)
866 862  
867 863 bmp_brush_format = {const.BRUSH_CIRCLE: CIRCLE_BMP,
868 864 const.BRUSH_SQUARE: SQUARE_BMP}
... ... @@ -873,14 +869,9 @@ class WatershedTool(EditionTools):
873 869 btn_brush_format.SetMenu(menu)
874 870 self.btn_brush_format = btn_brush_format
875 871  
  872 + spin_brush_size = InvSpinCtrl(self, -1, value=const.BRUSH_SIZE, min_value=1, max_value=1000, spin_button=False)
876 873 # To calculate best width to spinctrl
877   - dc = wx.WindowDC(self)
878   - dc.SetFont(self.GetFont())
879   - width, height = dc.GetTextExtent("MMM")
880   -
881   - spin_brush_size = wx.SpinCtrl(self, -1, "", size=(width + 20, -1))
882   - spin_brush_size.SetRange(1,100)
883   - spin_brush_size.SetValue(const.BRUSH_SIZE)
  874 + spin_brush_size.CalcSizeFromTextSize("MMMM")
884 875 spin_brush_size.Bind(wx.EVT_SPINCTRL, self.OnBrushSize)
885 876 self.spin = spin_brush_size
886 877  
... ...
invesalius/gui/task_surface.py
... ... @@ -38,6 +38,8 @@ import wx.lib.platebtn as pbtn
38 38 import invesalius.project as prj
39 39 import invesalius.utils as utl
40 40  
  41 +from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl, InvFloatSpinCtrl
  42 +
41 43 #INTERPOLATION_MODE_LIST = ["Cubic", "Linear", "NearestNeighbor"]
42 44 MIN_TRANSPARENCY = 0
43 45 MAX_TRANSPARENCY = 100
... ... @@ -620,9 +622,7 @@ class QualityAdjustment(wx.Panel):
620 622  
621 623 text_decimate = wx.StaticText(self, -1, _("Decimate resolution:"))
622 624  
623   - spin_decimate = wx.SpinCtrl(self, -1, "", (30, 50))
624   - spin_decimate.SetRange(1,100)
625   - spin_decimate.SetValue(30)
  625 + spin_decimate = InvSpinCtrl(self, -1, value=30, min_value=1, max_value=100, size=(30, 50))
626 626 #spin_decimate.Bind(wx.EVT_TEXT, self.OnDecimate)
627 627  
628 628 # LINE 3
... ... @@ -630,9 +630,7 @@ class QualityAdjustment(wx.Panel):
630 630  
631 631 text_smooth = wx.StaticText(self, -1, _("Smooth iterations:"))
632 632  
633   - spin_smooth = wx.SpinCtrl(self, -1, "", (30, 50))
634   - spin_smooth.SetRange(1,100)
635   - spin_smooth.SetValue(0)
  633 + spin_smooth = InvSpinCtrl(self, -1, value=0, min_value=1, max_values=100, size=(30, 50))
636 634  
637 635 # MIXED LINE 2 AND 3
638 636 flag_link = wx.EXPAND|wx.GROW|wx.RIGHT|wx.LEFT
... ...
invesalius/gui/widgets/canvas_renderer.py
... ... @@ -140,7 +140,7 @@ class CanvasRendererCTX:
140 140 self.rgb = np.zeros((h, w, 3), dtype=np.uint8)
141 141 self.alpha = np.zeros((h, w, 1), dtype=np.uint8)
142 142  
143   - self.bitmap = wx.EmptyBitmapRGBA(w, h)
  143 + self.bitmap = wx.Bitmap.FromRGBA(w, h)
144 144 try:
145 145 self.image = wx.Image(w, h, self.rgb, self.alpha)
146 146 except TypeError:
... ... @@ -155,7 +155,7 @@ class CanvasRendererCTX:
155 155 self.rgb = np.zeros((h, w, 3), dtype=np.uint8)
156 156 self.alpha = np.zeros((h, w, 1), dtype=np.uint8)
157 157  
158   - self.bitmap = wx.EmptyBitmapRGBA(w, h)
  158 + self.bitmap = wx.Bitmap.FromRGBA(w, h)
159 159 try:
160 160 self.image = wx.Image(w, h, self.rgb, self.alpha)
161 161 except TypeError:
... ... @@ -379,7 +379,7 @@ class CanvasRendererCTX:
379 379 if size is None:
380 380 size = self.canvas_renderer.GetSize()
381 381 w, h = size
382   - image = wx.EmptyImage(w, h)
  382 + image = wx.Image(w, h)
383 383 image.Clear()
384 384  
385 385 arr = np.zeros((h, w, 4), dtype=np.uint8)
... ...
invesalius/gui/widgets/clut_raycasting.py
... ... @@ -383,7 +383,7 @@ class CLUTRaycastingWidget(wx.Panel):
383 383 self.to_render = True
384 384 i,j = self.point_dragged
385 385  
386   - width, height= self.GetVirtualSizeTuple()
  386 + width, height= self.GetVirtualSize()
387 387  
388 388 if y >= height - self.padding:
389 389 y = height - self.padding
... ... @@ -525,7 +525,7 @@ class CLUTRaycastingWidget(wx.Panel):
525 525 x,y = node.x, node.y
526 526 value = node.graylevel
527 527 alpha = node.opacity
528   - widget_width, widget_height = self.GetVirtualSizeTuple()
  528 + widget_width, widget_height = self.GetVirtualSize()
529 529  
530 530 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
531 531 font.SetWeight(wx.BOLD)
... ... @@ -600,7 +600,7 @@ class CLUTRaycastingWidget(wx.Panel):
600 600  
601 601 def Render(self, dc):
602 602 ctx = wx.GraphicsContext.Create(dc)
603   - width, height= self.GetVirtualSizeTuple()
  603 + width, height= self.GetVirtualSize()
604 604 height -= (self.padding * 2)
605 605 width -= self.padding
606 606  
... ... @@ -614,7 +614,7 @@ class CLUTRaycastingWidget(wx.Panel):
614 614 self._draw_selected_point_text(ctx)
615 615  
616 616 def _build_histogram(self):
617   - width, height = self.GetVirtualSizeTuple()
  617 + width, height = self.GetVirtualSize()
618 618 width -= self.padding
619 619 height -= (self.padding * 2)
620 620 x_init = self.Histogram.init
... ... @@ -638,7 +638,7 @@ class CLUTRaycastingWidget(wx.Panel):
638 638 width = img.GetWidth()
639 639 height = img.GetHeight()
640 640 self.save_button = Button()
641   - self.save_button.image = wx.BitmapFromImage(img)
  641 + self.save_button.image = wx.Bitmap(img)
642 642 self.save_button.size = (width, height)
643 643  
644 644 def __sort_pixel_points(self):
... ... @@ -684,7 +684,7 @@ class CLUTRaycastingWidget(wx.Panel):
684 684 """
685 685 Given a Hounsfield point returns a pixel point in the canvas.
686 686 """
687   - width,height = self.GetVirtualSizeTuple()
  687 + width,height = self.GetVirtualSize()
688 688 width -= (TOOLBAR_SIZE)
689 689 proportion = width * 1.0 / (self.end - self.init)
690 690 x = (graylevel - self.init) * proportion + TOOLBAR_SIZE
... ... @@ -694,7 +694,7 @@ class CLUTRaycastingWidget(wx.Panel):
694 694 """
695 695 Given a Opacity point returns a pixel point in the canvas.
696 696 """
697   - width,height = self.GetVirtualSizeTuple()
  697 + width,height = self.GetVirtualSize()
698 698 height -= (self.padding * 2)
699 699 y = height - (opacity * height) + self.padding
700 700 return y
... ... @@ -703,7 +703,7 @@ class CLUTRaycastingWidget(wx.Panel):
703 703 """
704 704 Translate from pixel point to Hounsfield scale.
705 705 """
706   - width, height= self.GetVirtualSizeTuple()
  706 + width, height= self.GetVirtualSize()
707 707 width -= (TOOLBAR_SIZE)
708 708 proportion = width * 1.0 / (self.end - self.init)
709 709 graylevel = (x - TOOLBAR_SIZE) / proportion - abs(self.init)
... ... @@ -713,7 +713,7 @@ class CLUTRaycastingWidget(wx.Panel):
713 713 """
714 714 Translate from pixel point to opacity.
715 715 """
716   - width, height= self.GetVirtualSizeTuple()
  716 + width, height= self.GetVirtualSize()
717 717 height -= (self.padding * 2)
718 718 opacity = (height - y + self.padding) * 1.0 / height
719 719 return opacity
... ...
invesalius/gui/widgets/gradient.py
1 1 # -*- coding: UTF-8 -*-
2 2  
3   -#--------------------------------------------------------------------------
  3 +# --------------------------------------------------------------------------
4 4 # Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
5 5 # Copyright: (C) 2001 Centro de Pesquisas Renato Archer
6 6 # Homepage: http://www.softwarepublico.gov.br
7 7 # Contact: invesalius@cti.gov.br
8 8 # License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
9   -#--------------------------------------------------------------------------
  9 +# --------------------------------------------------------------------------
10 10 # Este programa e software livre; voce pode redistribui-lo e/ou
11 11 # modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
12 12 # publicada pela Free Software Foundation; de acordo com a versao 2
... ... @@ -17,14 +17,15 @@
17 17 # COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
18 18 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
19 19 # detalhes.
20   -#--------------------------------------------------------------------------
  20 +# --------------------------------------------------------------------------
21 21 import sys
22 22  
23 23 import numpy
24 24 import wx
25   -
26 25 from wx.lib import intctrl
27 26  
  27 +from invesalius.gui.widgets.inv_spinctrl import InvSpinCtrl
  28 +
28 29 PUSH_WIDTH = 7
29 30  
30 31 myEVT_SLIDER_CHANGED = wx.NewEventType()
... ... @@ -39,14 +40,16 @@ EVT_THRESHOLD_CHANGED = wx.PyEventBinder(myEVT_THRESHOLD_CHANGED, 1)
39 40 myEVT_THRESHOLD_CHANGING = wx.NewEventType()
40 41 EVT_THRESHOLD_CHANGING = wx.PyEventBinder(myEVT_THRESHOLD_CHANGING, 1)
41 42  
  43 +
42 44 class SliderEvent(wx.PyCommandEvent):
43   - def __init__(self , evtType, id, minRange, maxRange, minValue, maxValue):
44   - wx.PyCommandEvent.__init__(self, evtType, id,)
  45 + def __init__(self, evtType, id, minRange, maxRange, minValue, maxValue):
  46 + wx.PyCommandEvent.__init__(self, evtType, id)
45 47 self.min_range = minRange
46 48 self.max_range = maxRange
47 49 self.minimun = minValue
48 50 self.maximun = maxValue
49 51  
  52 +
50 53 class GradientSlider(wx.Panel):
51 54 # This widget is formed by a gradient background (black-white), two push
52 55 # buttons change the min and max values respectively and a slider which you can drag to
... ... @@ -57,7 +60,7 @@ class GradientSlider(wx.Panel):
57 60 # minValue: the least value in the range
58 61 # maxValue: the most value in the range
59 62 # colour: colour used in this widget.
60   - super(GradientSlider, self).__init__(parent, id, size = (100, 25))
  63 + super(GradientSlider, self).__init__(parent, id)
61 64 self._bind_events_wx()
62 65  
63 66 self.min_range = minRange
... ... @@ -75,24 +78,50 @@ class GradientSlider(wx.Panel):
75 78 self.Bind(wx.EVT_PAINT, self.OnPaint)
76 79 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackGround)
77 80  
78   - if sys.platform == 'win32':
  81 + if sys.platform == "win32":
79 82 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
80 83  
81 84 self.Bind(wx.EVT_MOTION, self.OnMotion)
82 85 self.Bind(wx.EVT_SIZE, self.OnSize)
83 86  
84 87 def OnLeaveWindow(self, evt):
  88 + if self.selected == 0:
  89 + return
  90 +
  91 + x = evt.GetX()
  92 + w, h = self.GetSize()
  93 +
  94 + if self.selected == 1:
  95 + if x - PUSH_WIDTH < 0:
  96 + x = PUSH_WIDTH
  97 + elif x >= self.max_position:
  98 + x = self.max_position
  99 + value = self._min_position_to_minimun(x)
  100 + self.minimun = value
  101 + self.min_position = x
  102 +
  103 + # The user is moving the second push (Max)
  104 + elif self.selected == 2:
  105 + if x + PUSH_WIDTH > w:
  106 + x = w - PUSH_WIDTH
  107 + elif x < self.min_position:
  108 + x = self.min_position
  109 +
  110 + value = self._max_position_to_maximun(x)
  111 + self.maximun = value
  112 + self.max_position = x
  113 +
85 114 self.selected = 0
  115 + self._generate_event(myEVT_SLIDER_CHANGED)
86 116 evt.Skip()
87 117  
88   -
89 118 def OnPaint(self, evt):
90 119 # Where the magic happens. Here the controls are drawn.
91 120 dc = wx.BufferedPaintDC(self)
92 121 dc.Clear()
93   -
  122 +
94 123 w, h = self.GetSize()
95   - width_gradient = w - 2*PUSH_WIDTH
  124 + width_gradient = w - 2 * PUSH_WIDTH
96 125 height_gradient = h
97 126 x_init_gradient = PUSH_WIDTH
98 127 y_init_gradient = 0
... ... @@ -117,9 +146,11 @@ class GradientSlider(wx.Panel):
117 146 dc.DrawRectangle(x_init_gradient + width_gradient, 0, PUSH_WIDTH, h)
118 147  
119 148 # Drawing the gradient.
120   - dc.GradientFillLinear((x_init_gradient, y_init_gradient,
121   - width_gradient, height_gradient),
122   - (0, 0, 0), (255,255, 255))
  149 + dc.GradientFillLinear(
  150 + (x_init_gradient, y_init_gradient, width_gradient, height_gradient),
  151 + (0, 0, 0),
  152 + (255, 255, 255),
  153 + )
123 154  
124 155 try:
125 156 n = wx.RendererNative.Get()
... ... @@ -131,9 +162,9 @@ class GradientSlider(wx.Panel):
131 162 n.DrawPushButton(self, dc, (x_init_push2, 0, PUSH_WIDTH, h))
132 163  
133 164 # Drawing the transparent slider.
134   - bytes = numpy.array(self.colour * width_transparency * h, 'B')
  165 + bytes = numpy.array(self.colour * width_transparency * h, "B")
135 166 try:
136   - slider = wx.BitmapFromBufferRGBA(width_transparency, h, bytes)
  167 + slider = wx.Bitmap.FromBufferRGBA(width_transparency, h, bytes)
137 168 except:
138 169 pass
139 170 else:
... ... @@ -151,7 +182,7 @@ class GradientSlider(wx.Panel):
151 182 if not self.selected:
152 183 # The user is over a push button, change the cursor.
153 184 if self._is_over_what(x) in (1, 2):
154   - self.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE))
  185 + self.SetCursor(wx.Cursor(wx.CURSOR_SIZEWE))
155 186 else:
156 187 self.SetCursor(wx.NullCursor)
157 188  
... ... @@ -168,7 +199,7 @@ class GradientSlider(wx.Panel):
168 199 self.min_position = x
169 200 self._generate_event(myEVT_SLIDER_CHANGING)
170 201 self.Refresh()
171   -
  202 +
172 203 # The user is moving the second push (Max)
173 204 elif self.selected == 2:
174 205 x -= self._delta
... ... @@ -188,13 +219,13 @@ class GradientSlider(wx.Panel):
188 219 x -= self._delta
189 220 slider_size = self.max_position - self.min_position
190 221 diff_values = self.maximun - self.minimun
191   -
  222 +
192 223 if x - PUSH_WIDTH < 0:
193 224 min_x = PUSH_WIDTH
194 225 self.minimun = self._min_position_to_minimun(min_x)
195 226 self.maximun = self.minimun + diff_values
196 227 self.CalculateControlPositions()
197   -
  228 +
198 229 elif x + slider_size + PUSH_WIDTH > w:
199 230 max_x = w - PUSH_WIDTH
200 231 self.maximun = self._max_position_to_maximun(max_x)
... ... @@ -211,7 +242,6 @@ class GradientSlider(wx.Panel):
211 242 self.Refresh()
212 243 evt.Skip()
213 244  
214   -
215 245 def OnClick(self, evt):
216 246 x = evt.GetX()
217 247 self.selected = self._is_over_what(x)
... ... @@ -240,34 +270,34 @@ class GradientSlider(wx.Panel):
240 270 widget.
241 271 """
242 272 w, h = self.GetSize()
243   - window_width = w - 2*PUSH_WIDTH
  273 + window_width = w - 2 * PUSH_WIDTH
244 274 proportion = window_width / float(self.max_range - self.min_range)
245 275  
246   - self.min_position = int(round((self.minimun - self.min_range) * \
247   - proportion)) + PUSH_WIDTH
248   - self.max_position = int(round((self.maximun - self.min_range) * \
249   - proportion)) + PUSH_WIDTH
  276 + self.min_position = (
  277 + int(round((self.minimun - self.min_range) * proportion)) + PUSH_WIDTH
  278 + )
  279 + self.max_position = (
  280 + int(round((self.maximun - self.min_range) * proportion)) + PUSH_WIDTH
  281 + )
250 282  
251 283 def _max_position_to_maximun(self, max_position):
252   - """
  284 + """
253 285 Calculates the min and max value based on the control positions.
254 286 """
255 287 w, h = self.GetSize()
256   - window_width = w - 2*PUSH_WIDTH
  288 + window_width = w - 2 * PUSH_WIDTH
257 289 proportion = window_width / float(self.max_range - self.min_range)
258 290  
259   - maximun = int(round((max_position - PUSH_WIDTH)/proportion + \
260   - self.min_range))
  291 + maximun = int(round((max_position - PUSH_WIDTH) / proportion + self.min_range))
261 292  
262 293 return maximun
263 294  
264 295 def _min_position_to_minimun(self, min_position):
265 296 w, h = self.GetSize()
266   - window_width = w - 2*PUSH_WIDTH
  297 + window_width = w - 2 * PUSH_WIDTH
267 298 proportion = window_width / float(self.max_range - self.min_range)
268 299  
269   - minimun = int(round((min_position - PUSH_WIDTH)/proportion + \
270   - self.min_range))
  300 + minimun = int(round((min_position - PUSH_WIDTH) / proportion + self.min_range))
271 301  
272 302 return minimun
273 303  
... ... @@ -313,18 +343,20 @@ class GradientSlider(wx.Panel):
313 343 return self.minimun
314 344  
315 345 def _generate_event(self, event):
316   - evt = SliderEvent(event, self.GetId(), self.min_range,
317   - self.max_range, self.minimun, self.maximun)
  346 + evt = SliderEvent(
  347 + event,
  348 + self.GetId(),
  349 + self.min_range,
  350 + self.max_range,
  351 + self.minimun,
  352 + self.maximun,
  353 + )
318 354 self.GetEventHandler().ProcessEvent(evt)
319 355  
320 356  
321 357 class GradientCtrl(wx.Panel):
322 358 def __init__(self, parent, id, minRange, maxRange, minValue, maxValue, colour):
323 359 super(GradientCtrl, self).__init__(parent, id)
324   - self.sizer = wx.BoxSizer(wx.HORIZONTAL)
325   - self.SetSizer(self.sizer)
326   - self.sizer.Fit(self)
327   - self.SetAutoLayout(1)
328 360 self.min_range = minRange
329 361 self.max_range = maxRange
330 362 self.minimun = minValue
... ... @@ -336,43 +368,56 @@ class GradientCtrl(wx.Panel):
336 368 self.Show()
337 369  
338 370 def _draw_controls(self):
339   - self.gradient_slider = GradientSlider(self, -1, self.min_range,
340   - self.max_range, self.minimun,
341   - self.maximun, self.colour)
342   -
343   - self.spin_min = intctrl.IntCtrl(self, size=(40,20),
344   - style=wx.TE_PROCESS_ENTER)
345   - self.spin_min.SetValue(self.minimun)
346   - if sys.platform != 'win32':
  371 + self.gradient_slider = GradientSlider(
  372 + self,
  373 + -1,
  374 + self.min_range,
  375 + self.max_range,
  376 + self.minimun,
  377 + self.maximun,
  378 + self.colour,
  379 + )
  380 +
  381 + self.spin_min = InvSpinCtrl(
  382 + self,
  383 + value=self.minimun,
  384 + min_value=self.min_range,
  385 + max_value=self.max_range,
  386 + spin_button=False,
  387 + )
  388 + if sys.platform != "win32":
347 389 self.spin_min.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
348 390  
349   - self.spin_max = intctrl.IntCtrl(self, size=(40,20),
350   - style=wx.TE_PROCESS_ENTER)
351   - self.spin_max.SetValue(self.maximun)
352   - if sys.platform != 'win32':
  391 + self.spin_max = InvSpinCtrl(
  392 + self,
  393 + value=self.maximun,
  394 + min_value=self.min_range,
  395 + max_value=self.max_range,
  396 + spin_button=False,
  397 + )
  398 + if sys.platform != "win32":
353 399 self.spin_max.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
354 400  
  401 + self.spin_min.CalcSizeFromTextSize()
  402 + self.spin_max.CalcSizeFromTextSize()
  403 +
355 404 sizer = wx.BoxSizer(wx.HORIZONTAL)
356   - sizer.Add(self.spin_min, 0, wx.EXPAND | wx.RIGHT, 2)
  405 + sizer.Add(self.spin_min, 0, wx.RIGHT, 2)
357 406 sizer.Add(self.gradient_slider, 1, wx.EXPAND)
358   - sizer.Add(self.spin_max, 0, wx.EXPAND | wx.LEFT, 2)
  407 + sizer.Add(self.spin_max, 0, wx.LEFT, 2)
  408 +
  409 + self.sizer = wx.BoxSizer(wx.HORIZONTAL)
359 410 self.sizer.Add(sizer, 1, wx.EXPAND)
  411 + self.SetSizer(self.sizer)
  412 + self.sizer.Fit(self)
  413 + # self.SetAutoLayout(1)
360 414  
361 415 def _bind_events_wx(self):
362 416 self.gradient_slider.Bind(EVT_SLIDER_CHANGING, self.OnSliding)
363 417 self.gradient_slider.Bind(EVT_SLIDER_CHANGED, self.OnSlider)
364 418  
365   - # self.spin_min.Bind(wx.lib.intctrl.EVT_INT, self.ChangeMinValue)
366   - self.spin_min.Bind(wx.EVT_LEAVE_WINDOW, self._FireSpinMinChange)
367   - self.spin_min.Bind(wx.EVT_KILL_FOCUS, self._FireSpinMinChange)
368   - #self.spin_min.Bind(wx.EVT_KEY_DOWN, self._FireSpinMinChange)
369   - self.spin_min.Bind(wx.EVT_MOUSEWHEEL, self.OnMinMouseWheel)
370   -
371   - # self.spin_max.Bind(wx.lib.intctrl.EVT_INT, self.ChangeMaxValue)
372   - self.spin_max.Bind(wx.EVT_LEAVE_WINDOW, self._FireSpinMaxChange)
373   - self.spin_max.Bind(wx.EVT_KILL_FOCUS, self._FireSpinMaxChange)
374   - #self.spin_max.Bind(wx.EVT_KEY_DOWN, self._FireSpinMaxChange)
375   - self.spin_max.Bind(wx.EVT_MOUSEWHEEL, self.OnMaxMouseWheel)
  419 + self.spin_min.Bind(wx.EVT_SPINCTRL, self.OnMinMouseWheel)
  420 + self.spin_max.Bind(wx.EVT_SPINCTRL, self.OnMaxMouseWheel)
376 421  
377 422 def OnSlider(self, evt):
378 423 self.spin_min.SetValue(evt.minimun)
... ... @@ -419,23 +464,23 @@ class GradientCtrl(wx.Panel):
419 464 self._GenerateEvent(myEVT_THRESHOLD_CHANGED)
420 465  
421 466 def OnMinMouseWheel(self, e):
422   - """
  467 + """
423 468 When the user wheel the mouse over min texbox
424 469 """
425   - v = self.GetMinValue() + e.GetWheelRotation()/e.GetWheelDelta()
  470 + v = self.spin_min.GetValue()
426 471 self.SetMinValue(v)
427 472 self._GenerateEvent(myEVT_THRESHOLD_CHANGING)
428 473  
429 474 def OnMaxMouseWheel(self, e):
430   - """
  475 + """
431 476 When the user wheel the mouse over max texbox
432 477 """
433   - v = self.GetMaxValue() + e.GetWheelRotation()/e.GetWheelDelta()
  478 + v = self.spin_max.GetValue()
434 479 self.SetMaxValue(v)
435 480 self._GenerateEvent(myEVT_THRESHOLD_CHANGING)
436 481  
437 482 def SetColour(self, colour):
438   - colour = list(colour[:3]) + [90,]
  483 + colour = list(colour[:3]) + [90]
439 484 self.colour = colour
440 485 self.gradient_slider.SetColour(colour)
441 486 self.gradient_slider.Refresh()
... ... @@ -443,24 +488,40 @@ class GradientCtrl(wx.Panel):
443 488 def SetMaxRange(self, value):
444 489 self.spin_min.SetMax(value)
445 490 self.spin_max.SetMax(value)
  491 + self.spin_min.CalcSizeFromTextSize()
  492 + self.spin_max.CalcSizeFromTextSize()
446 493 self.gradient_slider.SetMaxRange(value)
447 494 self.max_range = value
448 495 if value > self.max_range:
449 496 value = self.max_range
450 497  
  498 + self.spin_min.CalcSizeFromTextSize()
  499 + self.spin_max.CalcSizeFromTextSize()
  500 + self.Layout()
  501 +
451 502 def SetMinRange(self, value):
452 503 self.spin_min.SetMin(value)
453 504 self.spin_max.SetMin(value)
  505 + self.spin_min.CalcSizeFromTextSize()
  506 + self.spin_max.CalcSizeFromTextSize()
454 507 self.gradient_slider.SetMinRange(value)
455 508 self.min_range = value
456 509 if value < self.min_range:
457 510 value = self.min_range
458 511  
  512 + self.spin_min.CalcSizeFromTextSize()
  513 + self.spin_max.CalcSizeFromTextSize()
  514 + self.Layout()
  515 +
459 516 def SetMaxValue(self, value):
460 517 if value is not None:
461 518 value = int(value)
462 519 if value > self.max_range:
463 520 value = int(self.max_range)
  521 + if value < self.min_range:
  522 + value = int(self.min_range)
  523 + if value < self.minimun:
  524 + value = int(self.minimun)
464 525 self.spin_max.SetValue(value)
465 526 self.gradient_slider.SetMaximun(value)
466 527 self.maximun = value
... ... @@ -470,6 +531,10 @@ class GradientCtrl(wx.Panel):
470 531 value = int(value)
471 532 if value < self.min_range:
472 533 value = int(self.min_range)
  534 + if value > self.max_range:
  535 + value = int(self.max_range)
  536 + if value > self.maximun:
  537 + value = int(self.maximun)
473 538 self.spin_min.SetValue(value)
474 539 self.gradient_slider.SetMinimun(value)
475 540 self.minimun = value
... ... @@ -497,9 +562,15 @@ class GradientCtrl(wx.Panel):
497 562 def _GenerateEvent(self, event):
498 563 if event == myEVT_THRESHOLD_CHANGING:
499 564 self.changed = True
500   - elif event == myEVT_THRESHOLD_CHANGED :
  565 + elif event == myEVT_THRESHOLD_CHANGED:
501 566 self.changed = False
502 567  
503   - evt = SliderEvent(event, self.GetId(), self.min_range,
504   - self.max_range, self.minimun, self.maximun)
  568 + evt = SliderEvent(
  569 + event,
  570 + self.GetId(),
  571 + self.min_range,
  572 + self.max_range,
  573 + self.minimun,
  574 + self.maximun,
  575 + )
505 576 self.GetEventHandler().ProcessEvent(evt)
... ...
invesalius/gui/widgets/inv_spinctrl.py 0 → 100644
... ... @@ -0,0 +1,331 @@
  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 +import decimal
  20 +
  21 +import wx
  22 +
  23 +
  24 +class InvSpinCtrl(wx.Panel):
  25 + def __init__(
  26 + self,
  27 + parent,
  28 + id=wx.ID_ANY,
  29 + value=0,
  30 + min_value=1,
  31 + max_value=100,
  32 + increment=1,
  33 + spin_button=True,
  34 + size=wx.DefaultSize,
  35 + style=wx.TE_RIGHT,
  36 + ):
  37 + super().__init__(parent, id, size=size)
  38 +
  39 + self._textctrl = wx.TextCtrl(self, -1, style=style)
  40 + if spin_button and wx.Platform != "__WXGTK__":
  41 + self._spinbtn = wx.SpinButton(self, -1)
  42 + else:
  43 + self._spinbtn = None
  44 +
  45 + self._value = 0
  46 + self._last_value = 0
  47 + self._min_value = 0
  48 + self._max_value = 100
  49 + self._increment = 1
  50 +
  51 + self.SetMin(min_value)
  52 + self.SetMax(max_value)
  53 + self.SetValue(value)
  54 + self.SetIncrement(increment)
  55 +
  56 + sizer = wx.BoxSizer(wx.HORIZONTAL)
  57 + sizer.Add(self._textctrl, 1, wx.EXPAND)
  58 + if self._spinbtn:
  59 + sizer.Add(self._spinbtn, 0, wx.EXPAND)
  60 +
  61 + self.SetSizer(sizer)
  62 + sizer.Fit(self)
  63 +
  64 + self.__bind_events()
  65 +
  66 + def __bind_events(self):
  67 + self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
  68 + self._textctrl.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
  69 + if self._spinbtn:
  70 + self._spinbtn.Bind(wx.EVT_SPIN_UP, self.OnSpinUp)
  71 + self._spinbtn.Bind(wx.EVT_SPIN_DOWN, self.OnSpinDown)
  72 +
  73 + def SetIncrement(self, increment):
  74 + self._increment = increment
  75 +
  76 + def SetMin(self, min_value):
  77 + self._min_value = min_value
  78 + self.SetValue(self._value)
  79 +
  80 + def SetMax(self, max_value):
  81 + self._max_value = max_value
  82 + self.SetValue(self._value)
  83 +
  84 + def SetRange(self, min_value, max_value):
  85 + self.SetMin(min_value)
  86 + self.SetMax(max_value)
  87 +
  88 + def GetValue(self):
  89 + return self._value
  90 +
  91 + def SetValue(self, value):
  92 + try:
  93 + value = int(value)
  94 + except ValueError:
  95 + value = self._last_value
  96 +
  97 + if value < self._min_value:
  98 + value = self._min_value
  99 +
  100 + if value > self._max_value:
  101 + value = self._max_value
  102 +
  103 + self._value = value
  104 + self._textctrl.SetValue("{}".format(self._value))
  105 + self._last_value = self._value
  106 +
  107 + def CalcSizeFromTextSize(self, text=None):
  108 + # To calculate best width to spinctrl
  109 + if text is None:
  110 + text = "{}".format(
  111 + max(len(str(self._max_value)), len(str(self._min_value))) * "M"
  112 + )
  113 +
  114 + dc = wx.WindowDC(self)
  115 + dc.SetFont(self.GetFont())
  116 + width, height = dc.GetTextExtent(text)
  117 +
  118 + if self._spinbtn:
  119 + spin = wx.SpinCtrl(self, -1)
  120 + spin_width, spin_height = spin.GetBestSize()
  121 + spin.Destroy()
  122 +
  123 + spinb = wx.SpinButton(self, -1)
  124 + spinb_width, spinb_height = spinb.GetBestSize()
  125 + spinb.Destroy()
  126 +
  127 + width += spinb_width
  128 + if wx.Platform == "__WXMAC":
  129 + height = max(height, spin_height, spinb_height)
  130 + else:
  131 + height = spin_height
  132 + else:
  133 + height = -1
  134 +
  135 + self.SetMinSize((width, height))
  136 + self.Layout()
  137 +
  138 + def OnMouseWheel(self, evt):
  139 + r = evt.GetWheelRotation()
  140 + if r > 0:
  141 + self.SetValue(self.GetValue() + self._increment)
  142 + else:
  143 + self.SetValue(self.GetValue() - self._increment)
  144 + self.raise_event()
  145 + evt.Skip()
  146 +
  147 + def OnKillFocus(self, evt):
  148 + value = self._textctrl.GetValue()
  149 + self.SetValue(value)
  150 + self.raise_event()
  151 + evt.Skip()
  152 +
  153 + def OnSpinDown(self, evt):
  154 + self.SetValue(self.GetValue() - self._increment)
  155 + self.raise_event()
  156 + evt.Skip()
  157 +
  158 + def OnSpinUp(self, evt):
  159 + self.SetValue(self.GetValue() + self._increment)
  160 + self.raise_event()
  161 + evt.Skip()
  162 +
  163 + def raise_event(self):
  164 + event = wx.PyCommandEvent(wx.EVT_SPINCTRL.typeId, self.GetId())
  165 + self.GetEventHandler().ProcessEvent(event)
  166 +
  167 +
  168 +class InvFloatSpinCtrl(wx.Panel):
  169 + def __init__(
  170 + self,
  171 + parent,
  172 + id=wx.ID_ANY,
  173 + value=0.0,
  174 + min_value=1.0,
  175 + max_value=100.0,
  176 + increment=0.1,
  177 + digits=1,
  178 + spin_button=True,
  179 + size=wx.DefaultSize,
  180 + style=wx.TE_RIGHT,
  181 + ):
  182 + super().__init__(parent, id, size=size)
  183 +
  184 + self._textctrl = wx.TextCtrl(self, -1, style=style)
  185 + if spin_button and wx.Platform != "__WXGTK__":
  186 + self._spinbtn = wx.SpinButton(self, -1)
  187 + else:
  188 + self._spinbtn = None
  189 +
  190 + self._digits = digits
  191 + self._dec_context = decimal.Context(prec=digits)
  192 +
  193 + self._value = decimal.Decimal("0", self._dec_context)
  194 + self._last_value = self._value
  195 + self._min_value = decimal.Decimal("0", self._dec_context)
  196 + self._max_value = decimal.Decimal("100", self._dec_context)
  197 + self._increment = decimal.Decimal("0.1", self._dec_context)
  198 +
  199 + self.SetIncrement(increment)
  200 + self.SetMin(min_value)
  201 + self.SetMax(max_value)
  202 + self.SetValue(value)
  203 +
  204 + sizer = wx.BoxSizer(wx.HORIZONTAL)
  205 + sizer.Add(self._textctrl, 1, wx.EXPAND)
  206 + if self._spinbtn:
  207 + sizer.Add(self._spinbtn, 0, wx.EXPAND)
  208 +
  209 + self.SetSizer(sizer)
  210 + sizer.Fit(self)
  211 +
  212 + self.__bind_events()
  213 +
  214 + def __bind_events(self):
  215 + self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
  216 + self._textctrl.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
  217 + if self._spinbtn:
  218 + self._spinbtn.Bind(wx.EVT_SPIN_UP, self.OnSpinUp)
  219 + self._spinbtn.Bind(wx.EVT_SPIN_DOWN, self.OnSpinDown)
  220 +
  221 + def _to_decimal(self, value):
  222 + if not isinstance(value, str):
  223 + value = "{:.{digits}f}".format(value, digits=self._digits)
  224 + return decimal.Decimal(value, self._dec_context)
  225 +
  226 + def SetDigits(self, digits):
  227 + self._digits = digits
  228 + self._dec_context = decimal.Context(prec=digits)
  229 +
  230 + self.SetIncrement(self._increment)
  231 + self.SetMin(self._min_value)
  232 + self.SetMax(self._max_value)
  233 + self.SetValue(self._value)
  234 +
  235 + def SetIncrement(self, increment):
  236 + self._increment = self._to_decimal(increment)
  237 +
  238 + def SetMin(self, min_value):
  239 + self._min_value = self._to_decimal(min_value)
  240 + self.SetValue(self._value)
  241 +
  242 + def SetMax(self, max_value):
  243 + self._max_value = self._to_decimal(max_value)
  244 + self.SetValue(self._value)
  245 +
  246 + def SetRange(self, min_value, max_value):
  247 + self.SetMin(min_value)
  248 + self.SetMax(max_value)
  249 +
  250 + def GetValue(self):
  251 + return float(self._value)
  252 +
  253 + def SetValue(self, value):
  254 + try:
  255 + value = self._to_decimal(value)
  256 + except decimal.InvalidOperation:
  257 + value = self._last_value
  258 +
  259 + if value < self._min_value:
  260 + value = self._min_value
  261 +
  262 + if value > self._max_value:
  263 + value = self._max_value
  264 +
  265 + self._value = value
  266 + self._textctrl.SetValue("{}".format(self._value))
  267 + self._last_value = self._value
  268 +
  269 + def CalcSizeFromTextSize(self, text=None):
  270 + # To calculate best width to spinctrl
  271 + if text is None:
  272 + text = "{}".format(
  273 + max(len(str(self._max_value)), len(str(self._min_value))) * "M"
  274 + )
  275 +
  276 + dc = wx.WindowDC(self)
  277 + dc.SetFont(self.GetFont())
  278 + width, height = dc.GetTextExtent(text)
  279 +
  280 + spin = wx.SpinCtrl(self, -1)
  281 + spin_width, spin_height = spin.GetBestSize()
  282 + spin.Destroy()
  283 +
  284 + if self._spinbtn:
  285 + spin = wx.SpinCtrl(self, -1)
  286 + spin_width, spin_height = spin.GetBestSize()
  287 + spin.Destroy()
  288 +
  289 + spinb = wx.SpinButton(self, -1)
  290 + spinb_width, spinb_height = spinb.GetBestSize()
  291 + spinb.Destroy()
  292 +
  293 + width += spinb_width
  294 + if wx.Platform == "__WXMAC":
  295 + height = max(height, spin_height, spinb_height)
  296 + else:
  297 + height = spin_height
  298 + else:
  299 + height = -1
  300 +
  301 + self.SetMinSize((width, height))
  302 + self.Layout()
  303 +
  304 + def OnMouseWheel(self, evt):
  305 + r = evt.GetWheelRotation()
  306 + if r > 0:
  307 + self.SetValue(self._value + self._increment)
  308 + else:
  309 + self.SetValue(self._value - self._increment)
  310 + self.raise_event()
  311 + evt.Skip()
  312 +
  313 + def OnKillFocus(self, evt):
  314 + value = self._textctrl.GetValue()
  315 + self.SetValue(value)
  316 + self.raise_event()
  317 + evt.Skip()
  318 +
  319 + def OnSpinDown(self, evt):
  320 + self.SetValue(self._value - self._increment)
  321 + self.raise_event()
  322 + evt.Skip()
  323 +
  324 + def OnSpinUp(self, evt):
  325 + self.SetValue(self._value + self._increment)
  326 + self.raise_event()
  327 + evt.Skip()
  328 +
  329 + def raise_event(self):
  330 + event = wx.PyCommandEvent(wx.EVT_SPINCTRL.typeId, self.GetId())
  331 + self.GetEventHandler().ProcessEvent(event)
... ...
invesalius/gui/widgets/listctrl.py
... ... @@ -739,7 +739,7 @@ class TextEditMixin:
739 739 # data source
740 740 self.SetVirtualData(self.curRow, self.curCol, text)
741 741 else:
742   - self.SetStringItem(self.curRow, self.curCol, text)
  742 + self.SetItem(self.curRow, self.curCol, text)
743 743 self.RefreshItem(self.curRow)
744 744  
745 745 def _SelectIndex(self, row):
... ...
invesalius/gui/widgets/slice_menu.py
... ... @@ -57,14 +57,14 @@ class SliceMenu(wx.Menu):
57 57 new_id = self.id_wl_first = wx.NewId()
58 58 wl_item = wx.MenuItem(submenu_wl, new_id,\
59 59 _('Default'), kind=wx.ITEM_RADIO)
60   - submenu_wl.AppendItem(wl_item)
  60 + submenu_wl.Append(wl_item)
61 61 self.ID_TO_TOOL_ITEM[new_id] = wl_item
62 62  
63 63 #Case the user change window and level
64 64 new_id = self.other_wl_id = wx.NewId()
65 65 wl_item = wx.MenuItem(submenu_wl, new_id,\
66 66 _('Manual'), kind=wx.ITEM_RADIO)
67   - submenu_wl.AppendItem(wl_item)
  67 + submenu_wl.Append(wl_item)
68 68 self.ID_TO_TOOL_ITEM[new_id] = wl_item
69 69  
70 70 for name in sorted(const.WINDOW_LEVEL):
... ... @@ -72,7 +72,7 @@ class SliceMenu(wx.Menu):
72 72 new_id = wx.NewId()
73 73 wl_item = wx.MenuItem(submenu_wl, new_id,\
74 74 name, kind=wx.ITEM_RADIO)
75   - submenu_wl.AppendItem(wl_item)
  75 + submenu_wl.Append(wl_item)
76 76 self.ID_TO_TOOL_ITEM[new_id] = wl_item
77 77  
78 78 #----------- Sub menu of the save and load options ---------
... ... @@ -84,7 +84,7 @@ class SliceMenu(wx.Menu):
84 84 # new_id = wx.NewId()
85 85 # wl_item = wx.MenuItem(submenu_wl, new_id,\
86 86 # name)
87   - # submenu_wl.AppendItem(wl_item)
  87 + # submenu_wl.Append(wl_item)
88 88 # self.ID_TO_TOOL_ITEM[new_id] = wl_item
89 89  
90 90  
... ... @@ -100,7 +100,7 @@ class SliceMenu(wx.Menu):
100 100 new_id = self.id_pseudo_first = wx.NewId()
101 101 color_item = wx.MenuItem(submenu_pseudo_colours, new_id,\
102 102 _("Default "), kind=mkind)
103   - submenu_pseudo_colours.AppendItem(color_item)
  103 + submenu_pseudo_colours.Append(color_item)
104 104 color_item.Check(1)
105 105 self.ID_TO_TOOL_ITEM[new_id] = color_item
106 106 self.pseudo_color_items[new_id] = color_item
... ... @@ -110,7 +110,7 @@ class SliceMenu(wx.Menu):
110 110 new_id = wx.NewId()
111 111 color_item = wx.MenuItem(submenu_wl, new_id,\
112 112 name, kind=mkind)
113   - submenu_pseudo_colours.AppendItem(color_item)
  113 + submenu_pseudo_colours.Append(color_item)
114 114 self.ID_TO_TOOL_ITEM[new_id] = color_item
115 115 self.pseudo_color_items[new_id] = color_item
116 116  
... ... @@ -119,14 +119,14 @@ class SliceMenu(wx.Menu):
119 119 new_id = wx.NewId()
120 120 color_item = wx.MenuItem(submenu_wl, new_id, name,
121 121 kind=mkind)
122   - submenu_pseudo_colours.AppendItem(color_item)
  122 + submenu_pseudo_colours.Append(color_item)
123 123 self.ID_TO_TOOL_ITEM[new_id] = color_item
124 124 self.pseudo_color_items[new_id] = color_item
125 125  
126 126 new_id = wx.NewId()
127 127 color_item = wx.MenuItem(submenu_wl, new_id, _('Custom'),
128 128 kind=mkind)
129   - submenu_pseudo_colours.AppendItem(color_item)
  129 + submenu_pseudo_colours.Append(color_item)
130 130 self.ID_TO_TOOL_ITEM[new_id] = color_item
131 131 self.pseudo_color_items[new_id] = color_item
132 132  
... ... @@ -137,7 +137,7 @@ class SliceMenu(wx.Menu):
137 137 new_id = wx.NewId()
138 138 projection_item = wx.MenuItem(submenu_projection, new_id, name,
139 139 kind=wx.ITEM_RADIO)
140   - submenu_projection.AppendItem(projection_item)
  140 + submenu_projection.Append(projection_item)
141 141 self.ID_TO_TOOL_ITEM[new_id] = projection_item
142 142 self.projection_items[PROJECTIONS_ID[name]] = projection_item
143 143  
... ... @@ -148,7 +148,7 @@ class SliceMenu(wx.Menu):
148 148 new_id = wx.NewId()
149 149 image_tiling_item = wx.MenuItem(submenu_image_tiling, new_id,\
150 150 name, kind=wx.ITEM_RADIO)
151   - submenu_image_tiling.AppendItem(image_tiling_item)
  151 + submenu_image_tiling.Append(image_tiling_item)
152 152 self.ID_TO_TOOL_ITEM[new_id] = image_tiling_item
153 153  
154 154 #Save first id item
... ... @@ -157,10 +157,10 @@ class SliceMenu(wx.Menu):
157 157 flag_tiling = True
158 158  
159 159 # Add sub itens in the menu
160   - self.AppendMenu(-1, _("Window width and level"), submenu_wl)
161   - self.AppendMenu(-1, _("Pseudo color"), submenu_pseudo_colours)
162   - self.AppendMenu(-1, _("Projection type"), submenu_projection)
163   - ###self.AppendMenu(-1, _("Image Tiling"), submenu_image_tiling)
  160 + self.Append(-1, _("Window width and level"), submenu_wl)
  161 + self.Append(-1, _("Pseudo color"), submenu_pseudo_colours)
  162 + self.Append(-1, _("Projection type"), submenu_projection)
  163 + ###self.Append(-1, _("Image Tiling"), submenu_image_tiling)
164 164  
165 165 # It doesn't work in Linux
166 166 self.Bind(wx.EVT_MENU, self.OnPopup)
... ...