Commit 366c43f403f7abcf46e566a94b55e4ee299ed66e
1 parent
345aba65
Exists in
master
and in
68 other branches
STL: Slice editor is using consts (not hardcoded anymore)
Showing
5 changed files
with
100 additions
and
90 deletions
Show diff stats
invesalius/constants.py
| @@ -43,11 +43,18 @@ MASK_COLOUR = [(0.33, 1, 0.33), | @@ -43,11 +43,18 @@ MASK_COLOUR = [(0.33, 1, 0.33), | ||
| 43 | #(0.66666666666666663, 0.792156862745098, 1.0)] | 43 | #(0.66666666666666663, 0.792156862745098, 1.0)] |
| 44 | 44 | ||
| 45 | # Related to slice editor brush | 45 | # Related to slice editor brush |
| 46 | -BRUSH_FORMAT = 0 # 0: circle, 1: square | ||
| 47 | -BRUSH_SIZE = 30 | ||
| 48 | -BRUSH_OP = 0 # 0: erase, 1: add, 2: threshold | ||
| 49 | -BRUSH_COLOUR = (0,0,1.0) | 46 | +BRUSH_CIRCLE = 0 # |
| 47 | +BRUSH_SQUARE = 1 | ||
| 48 | +DEFAULT_BRUSH_FORMAT = BRUSH_CIRCLE | ||
| 49 | + | ||
| 50 | +BRUSH_DRAW = 0 | ||
| 51 | +BRUSH_ERASE = 1 | ||
| 52 | +BRUSH_THRESH = 2 | ||
| 53 | +DEFAULT_BRUSH_OP = BRUSH_THRESH | ||
| 54 | +BRUSH_OP_NAME = ["Draw", "Erase", "Threshold"] | ||
| 50 | 55 | ||
| 56 | +BRUSH_COLOUR = (0,0,1.0) | ||
| 57 | +BRUSH_SIZE = 30 | ||
| 51 | 58 | ||
| 52 | # Surface creation values. Each element's list contains: | 59 | # Surface creation values. Each element's list contains: |
| 53 | # 0: imagedata reformat ratio | 60 | # 0: imagedata reformat ratio |
invesalius/control.py
| @@ -7,7 +7,7 @@ import data.imagedata_utils as utils | @@ -7,7 +7,7 @@ import data.imagedata_utils as utils | ||
| 7 | import data.surface as surface | 7 | import data.surface as surface |
| 8 | import data.volume as volume | 8 | import data.volume as volume |
| 9 | import reader.dicom_reader as dicom | 9 | import reader.dicom_reader as dicom |
| 10 | -#import reader.analyze_reader as analyze | 10 | +import reader.analyze_reader as analyze |
| 11 | 11 | ||
| 12 | DEFAULT_THRESH_MODE = 0 | 12 | DEFAULT_THRESH_MODE = 0 |
| 13 | 13 |
invesalius/data/slice_.py
| @@ -50,6 +50,21 @@ class Slice(object): | @@ -50,6 +50,21 @@ class Slice(object): | ||
| 50 | ps.Publisher().subscribe(self.__edit_mask_pixel, 'Edit mask pixel') | 50 | ps.Publisher().subscribe(self.__edit_mask_pixel, 'Edit mask pixel') |
| 51 | ps.Publisher().subscribe(self.__add_mask_pixel, 'Add mask pixel') | 51 | ps.Publisher().subscribe(self.__add_mask_pixel, 'Add mask pixel') |
| 52 | 52 | ||
| 53 | + ps.Publisher().subscribe(self.__set_current_mask_threshold_limits, | ||
| 54 | + 'Update threshold limits') | ||
| 55 | + | ||
| 56 | + def __set_current_mask_threshold_limits(self, pubsub_evt): | ||
| 57 | + thresh_min = pubsub_evt.data[0] | ||
| 58 | + thresh_max = pubsub_evt.data[1] | ||
| 59 | + print "***********" | ||
| 60 | + print thresh_min, thresh_max | ||
| 61 | + print "***********" | ||
| 62 | + if self.current_mask: | ||
| 63 | + index = self.current_mask.index | ||
| 64 | + self.SetMaskEditionThreshold(index, (thresh_min, thresh_max)) | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + | ||
| 53 | #--------------------------------------------------------------------------- | 68 | #--------------------------------------------------------------------------- |
| 54 | # BEGIN PUBSUB_EVT METHODS | 69 | # BEGIN PUBSUB_EVT METHODS |
| 55 | #--------------------------------------------------------------------------- | 70 | #--------------------------------------------------------------------------- |
| @@ -75,7 +90,6 @@ class Slice(object): | @@ -75,7 +90,6 @@ class Slice(object): | ||
| 75 | def __set_current_mask_threshold(self, evt_pubsub): | 90 | def __set_current_mask_threshold(self, evt_pubsub): |
| 76 | threshold_range = evt_pubsub.data | 91 | threshold_range = evt_pubsub.data |
| 77 | index = self.current_mask.index | 92 | index = self.current_mask.index |
| 78 | - self.current_mask.edited_points = {} | ||
| 79 | self.SetMaskThreshold(index, threshold_range) | 93 | self.SetMaskThreshold(index, threshold_range) |
| 80 | 94 | ||
| 81 | def __set_current_mask_colour(self, pubsub_evt): | 95 | def __set_current_mask_colour(self, pubsub_evt): |
| @@ -98,19 +112,16 @@ class Slice(object): | @@ -98,19 +112,16 @@ class Slice(object): | ||
| 98 | self.ShowMask(index, value) | 112 | self.ShowMask(index, value) |
| 99 | #--------------------------------------------------------------------------- | 113 | #--------------------------------------------------------------------------- |
| 100 | def __erase_mask_pixel(self, pubsub_evt): | 114 | def __erase_mask_pixel(self, pubsub_evt): |
| 101 | - positions = pubsub_evt.data | ||
| 102 | - for position in positions: | ||
| 103 | - self.ErasePixel(position) | 115 | + position = pubsub_evt.data |
| 116 | + self.ErasePixel(position) | ||
| 104 | 117 | ||
| 105 | def __edit_mask_pixel(self, pubsub_evt): | 118 | def __edit_mask_pixel(self, pubsub_evt): |
| 106 | - positions = pubsub_evt.data | ||
| 107 | - for position in positions: | ||
| 108 | - self.EditPixelBasedOnThreshold(position) | 119 | + position = pubsub_evt.data |
| 120 | + self.EditPixelBasedOnThreshold(position) | ||
| 109 | 121 | ||
| 110 | def __add_mask_pixel(self, pubsub_evt): | 122 | def __add_mask_pixel(self, pubsub_evt): |
| 111 | - positions = pubsub_evt.data | ||
| 112 | - for position in positions: | ||
| 113 | - self.DrawPixel(position) | 123 | + position = pubsub_evt.data |
| 124 | + self.DrawPixel(position) | ||
| 114 | #--------------------------------------------------------------------------- | 125 | #--------------------------------------------------------------------------- |
| 115 | # END PUBSUB_EVT METHODS | 126 | # END PUBSUB_EVT METHODS |
| 116 | #--------------------------------------------------------------------------- | 127 | #--------------------------------------------------------------------------- |
| @@ -191,19 +202,19 @@ class Slice(object): | @@ -191,19 +202,19 @@ class Slice(object): | ||
| 191 | def ErasePixel(self, position): | 202 | def ErasePixel(self, position): |
| 192 | "Delete pixel, based on x, y and z position coordinates." | 203 | "Delete pixel, based on x, y and z position coordinates." |
| 193 | x, y, z = position | 204 | x, y, z = position |
| 194 | - colour = self.imagedata.GetScalarRange()[0]# - 1 # Important to effect erase | 205 | + colour = self.imagedata.GetScalarRange()[0] |
| 195 | imagedata = self.current_mask.imagedata | 206 | imagedata = self.current_mask.imagedata |
| 196 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) | 207 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) |
| 197 | - #imagedata.Update() | 208 | + imagedata.Update() |
| 198 | self.current_mask.edited_points[(x, y, z)] = colour | 209 | self.current_mask.edited_points[(x, y, z)] = colour |
| 199 | 210 | ||
| 200 | def DrawPixel(self, position, colour=None): | 211 | def DrawPixel(self, position, colour=None): |
| 201 | "Draw pixel, based on x, y and z position coordinates." | 212 | "Draw pixel, based on x, y and z position coordinates." |
| 202 | x, y, z = position | 213 | x, y, z = position |
| 203 | - #if not colour: | ||
| 204 | colour = self.imagedata.GetScalarRange()[1] | 214 | colour = self.imagedata.GetScalarRange()[1] |
| 205 | imagedata = self.current_mask.imagedata | 215 | imagedata = self.current_mask.imagedata |
| 206 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) | 216 | imagedata.SetScalarComponentFromDouble(x, y, z, 0, colour) |
| 217 | + imagedata.Update() | ||
| 207 | self.current_mask.edited_points[(x, y, z)] = colour | 218 | self.current_mask.edited_points[(x, y, z)] = colour |
| 208 | 219 | ||
| 209 | def EditPixelBasedOnThreshold(self, position): | 220 | def EditPixelBasedOnThreshold(self, position): |
| @@ -392,7 +403,6 @@ class Slice(object): | @@ -392,7 +403,6 @@ class Slice(object): | ||
| 392 | 403 | ||
| 393 | # if not defined in the method call, this will have been computed on | 404 | # if not defined in the method call, this will have been computed on |
| 394 | # previous if | 405 | # previous if |
| 395 | - #future_mask.imagedata = imagedata | ||
| 396 | future_mask.imagedata = vtk.vtkImageData() | 406 | future_mask.imagedata = vtk.vtkImageData() |
| 397 | future_mask.imagedata.DeepCopy(imagedata) | 407 | future_mask.imagedata.DeepCopy(imagedata) |
| 398 | future_mask.imagedata.Update() | 408 | future_mask.imagedata.Update() |
| @@ -421,7 +431,6 @@ class Slice(object): | @@ -421,7 +431,6 @@ class Slice(object): | ||
| 421 | self.current_mask = future_mask | 431 | self.current_mask = future_mask |
| 422 | 432 | ||
| 423 | ps.Publisher().sendMessage('Change mask selected', future_mask.index) | 433 | ps.Publisher().sendMessage('Change mask selected', future_mask.index) |
| 424 | - #ps.Publisher().sendMessage('Show mask', (future_mask.index, 1)) | ||
| 425 | ps.Publisher().sendMessage('Update slice viewer') | 434 | ps.Publisher().sendMessage('Update slice viewer') |
| 426 | 435 | ||
| 427 | 436 |
invesalius/data/viewer_slice.py
| @@ -46,10 +46,10 @@ class Viewer(wx.Panel): | @@ -46,10 +46,10 @@ class Viewer(wx.Panel): | ||
| 46 | self.orientation = orientation | 46 | self.orientation = orientation |
| 47 | self.slice_number = 0 | 47 | self.slice_number = 0 |
| 48 | 48 | ||
| 49 | - self._brush_cursor_op = 'Draw' | ||
| 50 | - self._brush_cursor_size = 30 | ||
| 51 | - self._brush_cursor_colour = None | ||
| 52 | - self._brush_cursor_type = 'circle' | 49 | + self._brush_cursor_op = const.DEFAULT_BRUSH_OP |
| 50 | + self._brush_cursor_size = const.BRUSH_SIZE | ||
| 51 | + self._brush_cursor_colour = const.BRUSH_COLOUR | ||
| 52 | + self._brush_cursor_type = const.DEFAULT_BRUSH_OP | ||
| 53 | self.cursor = None | 53 | self.cursor = None |
| 54 | # VTK pipeline and actors | 54 | # VTK pipeline and actors |
| 55 | self.__config_interactor() | 55 | self.__config_interactor() |
| @@ -130,7 +130,6 @@ class Viewer(wx.Panel): | @@ -130,7 +130,6 @@ class Viewer(wx.Panel): | ||
| 130 | self.interactor.Render() | 130 | self.interactor.Render() |
| 131 | 131 | ||
| 132 | def ChangeBrushColour(self, pubsub_evt): | 132 | def ChangeBrushColour(self, pubsub_evt): |
| 133 | - print "********************* ChangeBrushColour" | ||
| 134 | vtk_colour = pubsub_evt.data[3] | 133 | vtk_colour = pubsub_evt.data[3] |
| 135 | self._brush_cursor_colour = vtk_colour | 134 | self._brush_cursor_colour = vtk_colour |
| 136 | if (self.cursor): | 135 | if (self.cursor): |
| @@ -150,9 +149,9 @@ class Viewer(wx.Panel): | @@ -150,9 +149,9 @@ class Viewer(wx.Panel): | ||
| 150 | self._brush_cursor_type = brush_type | 149 | self._brush_cursor_type = brush_type |
| 151 | self.ren.RemoveActor(self.cursor.actor) | 150 | self.ren.RemoveActor(self.cursor.actor) |
| 152 | 151 | ||
| 153 | - if brush_type == 'square': | 152 | + if brush_type == const.BRUSH_SQUARE: |
| 154 | cursor = ca.CursorRectangle() | 153 | cursor = ca.CursorRectangle() |
| 155 | - elif brush_type == 'circle': | 154 | + elif brush_type == const.BRUSH_CIRCLE: |
| 156 | cursor = ca.CursorCircle() | 155 | cursor = ca.CursorCircle() |
| 157 | self.cursor = cursor | 156 | self.cursor = cursor |
| 158 | 157 | ||
| @@ -188,16 +187,16 @@ class Viewer(wx.Panel): | @@ -188,16 +187,16 @@ class Viewer(wx.Panel): | ||
| 188 | self.__update_cursor_position(coord) | 187 | self.__update_cursor_position(coord) |
| 189 | self.ren.Render() | 188 | self.ren.Render() |
| 190 | 189 | ||
| 191 | - if self._brush_cursor_op == 'Erase': | ||
| 192 | - evt_msg = 'Erase mask pixel' | ||
| 193 | - elif self._brush_cursor_op == 'Draw': | ||
| 194 | - evt_msg = 'Add mask pixel' | ||
| 195 | - elif self._brush_cursor_op == 'Threshold': | ||
| 196 | - evt_msg = 'Edit mask pixel' | 190 | + evt_msg = {const.BRUSH_ERASE: 'Erase mask pixel', |
| 191 | + const.BRUSH_DRAW: 'Add mask pixel', | ||
| 192 | + const.BRUSH_THRESH: 'Edit mask pixel'} | ||
| 193 | + msg = evt_msg[self._brush_cursor_op] | ||
| 197 | 194 | ||
| 198 | pixels = itertools.ifilter(self.TestOperationPosition, | 195 | pixels = itertools.ifilter(self.TestOperationPosition, |
| 199 | self.cursor.GetPixels()) | 196 | self.cursor.GetPixels()) |
| 200 | - ps.Publisher().sendMessage(evt_msg, pixels) | 197 | + for coord in pixels: |
| 198 | + print coord | ||
| 199 | + ps.Publisher().sendMessage(msg, coord) | ||
| 201 | 200 | ||
| 202 | # FIXME: This is idiot, but is the only way that brush operations are | 201 | # FIXME: This is idiot, but is the only way that brush operations are |
| 203 | # working when cross is disabled | 202 | # working when cross is disabled |
| @@ -212,19 +211,20 @@ class Viewer(wx.Panel): | @@ -212,19 +211,20 @@ class Viewer(wx.Panel): | ||
| 212 | self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition()) | 211 | self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition()) |
| 213 | self.__update_cursor_position(coord) | 212 | self.__update_cursor_position(coord) |
| 214 | 213 | ||
| 215 | - if self._brush_cursor_op == 'Erase': | 214 | + if self._brush_cursor_op == const.BRUSH_ERASE: |
| 216 | evt_msg = 'Erase mask pixel' | 215 | evt_msg = 'Erase mask pixel' |
| 217 | - elif self._brush_cursor_op == 'Draw': | 216 | + elif self._brush_cursor_op == const.BRUSH_DRAW: |
| 218 | evt_msg = 'Add mask pixel' | 217 | evt_msg = 'Add mask pixel' |
| 219 | - elif self._brush_cursor_op == 'Threshold': | 218 | + elif self._brush_cursor_op == const.BRUSH_THRESH: |
| 220 | evt_msg = 'Edit mask pixel' | 219 | evt_msg = 'Edit mask pixel' |
| 221 | 220 | ||
| 222 | if self.mouse_pressed: | 221 | if self.mouse_pressed: |
| 223 | pixels = itertools.ifilter(self.TestOperationPosition, | 222 | pixels = itertools.ifilter(self.TestOperationPosition, |
| 224 | self.cursor.GetPixels()) | 223 | self.cursor.GetPixels()) |
| 225 | - ps.Publisher().sendMessage(evt_msg, pixels) | ||
| 226 | - ps.Publisher().sendMessage('Update slice viewer') | 224 | + for coord in pixels: |
| 225 | + ps.Publisher().sendMessage(evt_msg, coord) | ||
| 227 | self.interactor.Render() | 226 | self.interactor.Render() |
| 227 | + ps.Publisher().sendMessage('Update slice viewer') | ||
| 228 | 228 | ||
| 229 | def OnCrossMove(self, obj, evt_vtk): | 229 | def OnCrossMove(self, obj, evt_vtk): |
| 230 | coord = self.GetCoordinate() | 230 | coord = self.GetCoordinate() |
| @@ -477,8 +477,9 @@ class Viewer(wx.Panel): | @@ -477,8 +477,9 @@ class Viewer(wx.Panel): | ||
| 477 | "CORONAL": {1: self.slice_number}, | 477 | "CORONAL": {1: self.slice_number}, |
| 478 | "AXIAL": {2: self.slice_number}} | 478 | "AXIAL": {2: self.slice_number}} |
| 479 | 479 | ||
| 480 | - ps.Publisher().sendMessage('Update cursor single position in slice', | ||
| 481 | - position[self.orientation]) | 480 | + if 'DEFAULT' in self.modes: |
| 481 | + ps.Publisher().sendMessage('Update cursor single position in slice', | ||
| 482 | + position[self.orientation]) | ||
| 482 | 483 | ||
| 483 | def ChangeSliceNumber(self, pubsub_evt): | 484 | def ChangeSliceNumber(self, pubsub_evt): |
| 484 | index = pubsub_evt.data | 485 | index = pubsub_evt.data |
invesalius/gui/task_slice.py
| @@ -31,21 +31,15 @@ import gui.widgets.foldpanelbar as fpb | @@ -31,21 +31,15 @@ import gui.widgets.foldpanelbar as fpb | ||
| 31 | from project import Project | 31 | from project import Project |
| 32 | 32 | ||
| 33 | BTN_NEW = wx.NewId() | 33 | BTN_NEW = wx.NewId() |
| 34 | -MENU_SQUARE = wx.NewId() | ||
| 35 | -MENU_CIRCLE = wx.NewId() | ||
| 36 | - | ||
| 37 | -#THRESHOLD_LIST = ["Bone (CT)", "Soft Tissue (CT)", "Enamel (CT, Adult)", | ||
| 38 | -# "Enamel (CT, Child)", "Compact Bone (CT, Adult)", | ||
| 39 | -# "Compact Bone (CT, Child)", "Spongial Bone (CT, Adult)", | ||
| 40 | -# "Spongial Bone (CT, Child)", "Muscle Tissue (CT, Adult)", | ||
| 41 | -# "Muscle Tissue (CT, Child)", "Fat Tissue (CT, Adult)", | ||
| 42 | -# "Fat Tissue (CT, Adult)", "Skin Tissue (CT, Adult)", | ||
| 43 | -# "Skin Tissue (CT, Child)"] | ||
| 44 | 34 | ||
| 45 | -MASK_LIST = [] | 35 | +MENU_BRUSH_SQUARE = wx.NewId() |
| 36 | +MENU_BRUSH_CIRCLE = wx.NewId() | ||
| 46 | 37 | ||
| 47 | -OP_LIST = ["Draw", "Erase", "Threshold"] | 38 | +MENU_BRUSH_ADD = wx.NewId() |
| 39 | +MENU_BRUSH_DEL = wx.NewId() | ||
| 40 | +MENU_BRUSH_THRESH = wx.NewId() | ||
| 48 | 41 | ||
| 42 | +MASK_LIST = [] | ||
| 49 | 43 | ||
| 50 | class TaskPanel(wx.Panel): | 44 | class TaskPanel(wx.Panel): |
| 51 | def __init__(self, parent): | 45 | def __init__(self, parent): |
| @@ -227,12 +221,10 @@ class MaskProperties(wx.Panel): | @@ -227,12 +221,10 @@ class MaskProperties(wx.Panel): | ||
| 227 | style=wx.CB_DROPDOWN|wx.CB_READONLY) | 221 | style=wx.CB_DROPDOWN|wx.CB_READONLY) |
| 228 | combo_mask_name.SetSelection(0) # wx.CB_SORT | 222 | combo_mask_name.SetSelection(0) # wx.CB_SORT |
| 229 | combo_mask_name.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) | 223 | combo_mask_name.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
| 230 | - combo_mask_name.Bind(wx.EVT_COMBOBOX, self.OnComboName) | ||
| 231 | self.combo_mask_name = combo_mask_name | 224 | self.combo_mask_name = combo_mask_name |
| 232 | 225 | ||
| 233 | # Mask colour | 226 | # Mask colour |
| 234 | button_colour= csel.ColourSelect(self, 111,colour=(0,255,0),size=(-1,22)) | 227 | button_colour= csel.ColourSelect(self, 111,colour=(0,255,0),size=(-1,22)) |
| 235 | - button_colour.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour) | ||
| 236 | self.button_colour = button_colour | 228 | self.button_colour = button_colour |
| 237 | 229 | ||
| 238 | # Sizer which represents the first line | 230 | # Sizer which represents the first line |
| @@ -290,21 +282,20 @@ class MaskProperties(wx.Panel): | @@ -290,21 +282,20 @@ class MaskProperties(wx.Panel): | ||
| 290 | ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name') | 282 | ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name') |
| 291 | 283 | ||
| 292 | def __bind_events_wx(self): | 284 | def __bind_events_wx(self): |
| 285 | + self.Bind(grad.EVT_THRESHOLD_CHANGE, self.OnSlideChanged, self.gradient) | ||
| 293 | self.combo_thresh.Bind(wx.EVT_COMBOBOX, self.OnComboThresh) | 286 | self.combo_thresh.Bind(wx.EVT_COMBOBOX, self.OnComboThresh) |
| 294 | - self.Bind(grad.EVT_THRESHOLD_CHANGE, self.OnSlideChanged, | ||
| 295 | - self.gradient) | ||
| 296 | - | 287 | + self.combo_mask_name.Bind(wx.EVT_COMBOBOX, self.OnComboName) |
| 288 | + self.button_colour.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour) | ||
| 289 | + | ||
| 297 | def SelectMaskName(self, pubsub_evt): | 290 | def SelectMaskName(self, pubsub_evt): |
| 298 | index = pubsub_evt.data | 291 | index = pubsub_evt.data |
| 299 | self.combo_mask_name.SetSelection(index) | 292 | self.combo_mask_name.SetSelection(index) |
| 300 | 293 | ||
| 301 | - | ||
| 302 | def ChangeMaskName(self, pubsub_evt): | 294 | def ChangeMaskName(self, pubsub_evt): |
| 303 | index, name = pubsub_evt.data | 295 | index, name = pubsub_evt.data |
| 304 | self.combo_mask_name.SetString(index, name) | 296 | self.combo_mask_name.SetString(index, name) |
| 305 | self.combo_mask_name.Refresh() | 297 | self.combo_mask_name.Refresh() |
| 306 | 298 | ||
| 307 | - | ||
| 308 | def SetThresholdValues(self, pubsub_evt): | 299 | def SetThresholdValues(self, pubsub_evt): |
| 309 | thresh_min, thresh_max = pubsub_evt.data | 300 | thresh_min, thresh_max = pubsub_evt.data |
| 310 | self.bind_evt_gradient = False | 301 | self.bind_evt_gradient = False |
| @@ -376,42 +367,44 @@ class EditionTools(wx.Panel): | @@ -376,42 +367,44 @@ class EditionTools(wx.Panel): | ||
| 376 | text1 = wx.StaticText(self, -1, "Choose brush type, size or operation:") | 367 | text1 = wx.StaticText(self, -1, "Choose brush type, size or operation:") |
| 377 | 368 | ||
| 378 | ## LINE 2 | 369 | ## LINE 2 |
| 379 | - | ||
| 380 | - SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) | ||
| 381 | - CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) | ||
| 382 | - | ||
| 383 | menu = wx.Menu() | 370 | menu = wx.Menu() |
| 384 | - | ||
| 385 | - item = wx.MenuItem(menu, MENU_CIRCLE,"Circle") | 371 | + |
| 372 | + CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) | ||
| 373 | + item = wx.MenuItem(menu, MENU_BRUSH_CIRCLE, "Circle") | ||
| 386 | item.SetBitmap(CIRCLE_BMP) | 374 | item.SetBitmap(CIRCLE_BMP) |
| 387 | - item2 = wx.MenuItem(menu, MENU_SQUARE, "Square") | 375 | + |
| 376 | + SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) | ||
| 377 | + item2 = wx.MenuItem(menu, MENU_BRUSH_SQUARE, "Square") | ||
| 388 | item2.SetBitmap(SQUARE_BMP) | 378 | item2.SetBitmap(SQUARE_BMP) |
| 389 | - self.Bind(wx.EVT_MENU, self.OnMenu) | ||
| 390 | - | 379 | + |
| 391 | menu.AppendItem(item) | 380 | menu.AppendItem(item) |
| 392 | menu.AppendItem(item2) | 381 | menu.AppendItem(item2) |
| 393 | 382 | ||
| 394 | - btn_brush_type = pbtn.PlateButton(self, wx.ID_ANY,"", CIRCLE_BMP, | 383 | + bmp_brush_format = {const.BRUSH_CIRCLE: CIRCLE_BMP, |
| 384 | + const.BRUSH_SQUARE: SQUARE_BMP} | ||
| 385 | + selected_bmp = bmp_brush_format[const.DEFAULT_BRUSH_FORMAT] | ||
| 386 | + | ||
| 387 | + btn_brush_format = pbtn.PlateButton(self, wx.ID_ANY,"", selected_bmp, | ||
| 395 | style=pbtn.PB_STYLE_SQUARE) | 388 | style=pbtn.PB_STYLE_SQUARE) |
| 396 | - btn_brush_type.SetMenu(menu) | ||
| 397 | - self.btn_brush_type = btn_brush_type | 389 | + btn_brush_format.SetMenu(menu) |
| 390 | + self.btn_brush_format = btn_brush_format | ||
| 398 | 391 | ||
| 399 | spin_brush_size = wx.SpinCtrl(self, -1, "", (30, 50)) | 392 | spin_brush_size = wx.SpinCtrl(self, -1, "", (30, 50)) |
| 400 | spin_brush_size.SetRange(1,100) | 393 | spin_brush_size.SetRange(1,100) |
| 401 | - spin_brush_size.SetValue(30) | 394 | + spin_brush_size.SetValue(const.BRUSH_SIZE) |
| 402 | spin_brush_size.Bind(wx.EVT_TEXT, self.OnBrushSize) | 395 | spin_brush_size.Bind(wx.EVT_TEXT, self.OnBrushSize) |
| 403 | self.spin = spin_brush_size | 396 | self.spin = spin_brush_size |
| 404 | 397 | ||
| 405 | combo_brush_op = wx.ComboBox(self, -1, "", size=(15,-1), | 398 | combo_brush_op = wx.ComboBox(self, -1, "", size=(15,-1), |
| 406 | - choices= OP_LIST, | ||
| 407 | - style=wx.CB_DROPDOWN|wx.CB_READONLY) | ||
| 408 | - combo_brush_op.SetSelection(0) | 399 | + choices = const.BRUSH_OP_NAME, |
| 400 | + style = wx.CB_DROPDOWN|wx.CB_READONLY) | ||
| 401 | + combo_brush_op.SetSelection(const.DEFAULT_BRUSH_OP) | ||
| 409 | combo_brush_op.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) | 402 | combo_brush_op.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
| 410 | - combo_brush_op.Bind(wx.EVT_COMBOBOX, self.OnComboBrushOp) | 403 | + self.combo_brush_op = combo_brush_op |
| 411 | 404 | ||
| 412 | # Sizer which represents the second line | 405 | # Sizer which represents the second line |
| 413 | line2 = wx.BoxSizer(wx.HORIZONTAL) | 406 | line2 = wx.BoxSizer(wx.HORIZONTAL) |
| 414 | - line2.Add(btn_brush_type, 0, wx.EXPAND|wx.GROW|wx.TOP|wx.RIGHT, 0) | 407 | + line2.Add(btn_brush_format, 0, wx.EXPAND|wx.GROW|wx.TOP|wx.RIGHT, 0) |
| 415 | line2.Add(spin_brush_size, 0, wx.RIGHT, 5) | 408 | line2.Add(spin_brush_size, 0, wx.RIGHT, 5) |
| 416 | line2.Add(combo_brush_op, 1, wx.TOP|wx.RIGHT|wx.LEFT, 5) | 409 | line2.Add(combo_brush_op, 1, wx.TOP|wx.RIGHT|wx.LEFT, 5) |
| 417 | 410 | ||
| @@ -429,7 +422,8 @@ class EditionTools(wx.Panel): | @@ -429,7 +422,8 @@ class EditionTools(wx.Panel): | ||
| 429 | sizer.Add(text1, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 422 | sizer.Add(text1, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 430 | sizer.Add(line2, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 423 | sizer.Add(line2, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 431 | sizer.Add(text_thresh, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 424 | sizer.Add(text_thresh, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
| 432 | - sizer.Add(gradient_thresh, 0, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT|wx.BOTTOM, 6) | 425 | + sizer.Add(gradient_thresh, 0, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT| |
| 426 | + wx.BOTTOM, 6) | ||
| 433 | sizer.Fit(self) | 427 | sizer.Fit(self) |
| 434 | 428 | ||
| 435 | self.SetSizer(sizer) | 429 | self.SetSizer(sizer) |
| @@ -441,14 +435,14 @@ class EditionTools(wx.Panel): | @@ -441,14 +435,14 @@ class EditionTools(wx.Panel): | ||
| 441 | 435 | ||
| 442 | 436 | ||
| 443 | def __bind_events_wx(self): | 437 | def __bind_events_wx(self): |
| 438 | + self.Bind(wx.EVT_MENU, self.OnMenu) | ||
| 444 | self.Bind(grad.EVT_THRESHOLD_CHANGE, self.OnGradientChanged, | 439 | self.Bind(grad.EVT_THRESHOLD_CHANGE, self.OnGradientChanged, |
| 445 | self.gradient_thresh) | 440 | self.gradient_thresh) |
| 441 | + self.combo_brush_op.Bind(wx.EVT_COMBOBOX, self.OnComboBrushOp) | ||
| 446 | 442 | ||
| 447 | def __bind_events(self): | 443 | def __bind_events(self): |
| 448 | ps.Publisher().subscribe(self.SetThresholdBounds, | 444 | ps.Publisher().subscribe(self.SetThresholdBounds, |
| 449 | 'Update threshold limits') | 445 | 'Update threshold limits') |
| 450 | - #ps.Publisher().subscribe(self.SetThresholdValues, | ||
| 451 | - # 'Set threshold values in gradient') | ||
| 452 | ps.Publisher().subscribe(self.ChangeMaskColour, 'Change mask colour') | 446 | ps.Publisher().subscribe(self.ChangeMaskColour, 'Change mask colour') |
| 453 | ps.Publisher().subscribe(self.SetGradientColour, 'Add mask') | 447 | ps.Publisher().subscribe(self.SetGradientColour, 'Add mask') |
| 454 | 448 | ||
| @@ -471,7 +465,6 @@ class EditionTools(wx.Panel): | @@ -471,7 +465,6 @@ class EditionTools(wx.Panel): | ||
| 471 | def SetThresholdBounds(self, pubsub_evt): | 465 | def SetThresholdBounds(self, pubsub_evt): |
| 472 | thresh_min = pubsub_evt.data[0] | 466 | thresh_min = pubsub_evt.data[0] |
| 473 | thresh_max = pubsub_evt.data[1] | 467 | thresh_max = pubsub_evt.data[1] |
| 474 | - print thresh_min, thresh_max | ||
| 475 | self.gradient_thresh.SetMinRange(thresh_min) | 468 | self.gradient_thresh.SetMinRange(thresh_min) |
| 476 | self.gradient_thresh.SetMaxRange(thresh_max) | 469 | self.gradient_thresh.SetMaxRange(thresh_max) |
| 477 | self.gradient_thresh.SetMinValue(thresh_min) | 470 | self.gradient_thresh.SetMinValue(thresh_min) |
| @@ -485,17 +478,17 @@ class EditionTools(wx.Panel): | @@ -485,17 +478,17 @@ class EditionTools(wx.Panel): | ||
| 485 | (thresh_min, thresh_max)) | 478 | (thresh_min, thresh_max)) |
| 486 | 479 | ||
| 487 | def OnMenu(self, evt): | 480 | def OnMenu(self, evt): |
| 488 | - """Button's menu event""" | ||
| 489 | SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) | 481 | SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) |
| 490 | CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) | 482 | CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) |
| 491 | 483 | ||
| 492 | - name = {MENU_CIRCLE:"circle", MENU_SQUARE:"square"} | ||
| 493 | - bitmap = {MENU_CIRCLE:CIRCLE_BMP, MENU_SQUARE:SQUARE_BMP} | 484 | + brush = {MENU_BRUSH_CIRCLE: const.BRUSH_CIRCLE, |
| 485 | + MENU_BRUSH_SQUARE: const.BRUSH_SQUARE} | ||
| 486 | + bitmap = {MENU_BRUSH_CIRCLE: CIRCLE_BMP, | ||
| 487 | + MENU_BRUSH_SQUARE: SQUARE_BMP} | ||
| 494 | 488 | ||
| 495 | - self.btn_brush_type.SetBitmap(bitmap[evt.GetId()]) | 489 | + self.btn_brush_format.SetBitmap(bitmap[evt.GetId()]) |
| 496 | 490 | ||
| 497 | - print "TODO: Send Signal - Change brush format to %s"% name[evt.GetId()] | ||
| 498 | - ps.Publisher().sendMessage('Set brush format', name[evt.GetId()]) | 491 | + ps.Publisher().sendMessage('Set brush format', brush[evt.GetId()]) |
| 499 | 492 | ||
| 500 | def OnBrushSize(self, evt): | 493 | def OnBrushSize(self, evt): |
| 501 | """ """ | 494 | """ """ |
| @@ -505,7 +498,7 @@ class EditionTools(wx.Panel): | @@ -505,7 +498,7 @@ class EditionTools(wx.Panel): | ||
| 505 | ps.Publisher().sendMessage('Set edition brush size',self.spin.GetValue()) | 498 | ps.Publisher().sendMessage('Set edition brush size',self.spin.GetValue()) |
| 506 | 499 | ||
| 507 | def OnComboBrushOp(self, evt): | 500 | def OnComboBrushOp(self, evt): |
| 508 | - print "TODO: Send Signal - Change brush operation: %s" %(evt.GetString()) | ||
| 509 | - ps.Publisher().sendMessage('Set edition operation',evt.GetString()) | 501 | + brush_op_id = evt.GetSelection() |
| 502 | + ps.Publisher().sendMessage('Set edition operation', brush_op_id) | ||
| 510 | 503 | ||
| 511 | 504 |