Commit 40466824c428da396f37502b925f979af9da68b7

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

managing mask showing and name edition using click events

Showing 2 changed files with 41 additions and 23 deletions   Show diff stats
@@ -102,7 +102,7 @@ class InVesalius(wx.App): @@ -102,7 +102,7 @@ class InVesalius(wx.App):
102 """ 102 """
103 Initialize splash screen and main frame. 103 Initialize splash screen and main frame.
104 """ 104 """
105 - 105 +
106 from multiprocessing import freeze_support 106 from multiprocessing import freeze_support
107 freeze_support() 107 freeze_support()
108 108
@@ -183,18 +183,18 @@ class Inv3SplashScreen(SplashScreen): @@ -183,18 +183,18 @@ class Inv3SplashScreen(SplashScreen):
183 183
184 # session.SaveConfigFileBackup() 184 # session.SaveConfigFileBackup()
185 185
186 - 186 +
187 # Only after language was defined, splash screen will be 187 # Only after language was defined, splash screen will be
188 # shown 188 # shown
189 if lang: 189 if lang:
190 - 190 +
191 #import locale 191 #import locale
192 #try: 192 #try:
193 # locale.setlocale(locale.LC_ALL, '') 193 # locale.setlocale(locale.LC_ALL, '')
194 #except locale.Error: 194 #except locale.Error:
195 # pass 195 # pass
196 -  
197 - 196 +
  197 +
198 # For pt_BR, splash_pt.png should be used 198 # For pt_BR, splash_pt.png should be used
199 if (lang.startswith('pt')): 199 if (lang.startswith('pt')):
200 icon_file = "splash_pt.png" 200 icon_file = "splash_pt.png"
@@ -206,13 +206,13 @@ class Inv3SplashScreen(SplashScreen): @@ -206,13 +206,13 @@ class Inv3SplashScreen(SplashScreen):
206 abs_file_path = os.path.abspath(".." + os.sep) 206 abs_file_path = os.path.abspath(".." + os.sep)
207 path = abs_file_path 207 path = abs_file_path
208 path = os.path.join(path, 'icons', icon_file) 208 path = os.path.join(path, 'icons', icon_file)
209 - 209 +
210 else: 210 else:
211 211
212 path = os.path.join(".","icons", icon_file) 212 path = os.path.join(".","icons", icon_file)
213 if not os.path.exists(path): 213 if not os.path.exists(path):
214 path = os.path.join(".", "icons", "splash_en.png") 214 path = os.path.join(".", "icons", "splash_en.png")
215 - 215 +
216 bmp = wx.Image(path).ConvertToBitmap() 216 bmp = wx.Image(path).ConvertToBitmap()
217 217
218 try: 218 try:
@@ -236,10 +236,10 @@ class Inv3SplashScreen(SplashScreen): @@ -236,10 +236,10 @@ class Inv3SplashScreen(SplashScreen):
236 from invesalius.gui.frame import Frame 236 from invesalius.gui.frame import Frame
237 from invesalius.control import Controller 237 from invesalius.control import Controller
238 from invesalius.project import Project 238 from invesalius.project import Project
239 - 239 +
240 self.main = Frame(None) 240 self.main = Frame(None)
241 self.control = Controller(self.main) 241 self.control = Controller(self.main)
242 - 242 +
243 self.fc = wx.CallLater(200, self.ShowMain) 243 self.fc = wx.CallLater(200, self.ShowMain)
244 options, args = parse_comand_line() 244 options, args = parse_comand_line()
245 wx.CallLater(1, use_cmd_optargs, options, args) 245 wx.CallLater(1, use_cmd_optargs, options, args)
@@ -502,7 +502,7 @@ def main(): @@ -502,7 +502,7 @@ def main():
502 if __name__ == '__main__': 502 if __name__ == '__main__':
503 #Is needed because of pyinstaller 503 #Is needed because of pyinstaller
504 multiprocessing.freeze_support() 504 multiprocessing.freeze_support()
505 - 505 +
506 #Needed in win 32 exe 506 #Needed in win 32 exe
507 if hasattr(sys,"frozen") and sys.platform.startswith('win'): 507 if hasattr(sys,"frozen") and sys.platform.startswith('win'):
508 508
@@ -527,4 +527,3 @@ if __name__ == '__main__': @@ -527,4 +527,3 @@ if __name__ == '__main__':
527 527
528 # Init application 528 # Init application
529 main() 529 main()
530 -  
invesalius/gui/data_notebook.py
@@ -366,8 +366,9 @@ class MasksListCtrlPanel(wx.ListCtrl): @@ -366,8 +366,9 @@ class MasksListCtrlPanel(wx.ListCtrl):
366 def __bind_events_wx(self): 366 def __bind_events_wx(self):
367 self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel) 367 self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel)
368 self.Bind(wx.EVT_KEY_UP, self.OnKeyEvent) 368 self.Bind(wx.EVT_KEY_UP, self.OnKeyEvent)
369 - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) 369 + # self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
370 self.Bind(wx.EVT_LEFT_UP, self.OnClickItem) 370 self.Bind(wx.EVT_LEFT_UP, self.OnClickItem)
  371 + self.Bind(wx.EVT_LEFT_DCLICK, self.OnDblClickItem)
371 372
372 def __bind_events(self): 373 def __bind_events(self):
373 Publisher.subscribe(self.AddMask, 'Add mask') 374 Publisher.subscribe(self.AddMask, 'Add mask')
@@ -482,6 +483,16 @@ class MasksListCtrlPanel(wx.ListCtrl): @@ -482,6 +483,16 @@ class MasksListCtrlPanel(wx.ListCtrl):
482 483
483 self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) 484 self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg"))
484 485
  486 + def get_column_clicked(self, position):
  487 + epx, epy = position
  488 + wpx, wpy = self.GetPosition()
  489 + width_sum = 0
  490 + for i in range(self.GetColumnCount()):
  491 + width_sum += self.GetColumnWidth(i)
  492 + if (epx - wpx) <= width_sum:
  493 + return i
  494 + return -1
  495 +
485 def OnEditLabel(self, evt): 496 def OnEditLabel(self, evt):
486 if not evt.IsEditCancelled(): 497 if not evt.IsEditCancelled():
487 index = evt.GetIndex() 498 index = evt.GetIndex()
@@ -502,7 +513,8 @@ class MasksListCtrlPanel(wx.ListCtrl): @@ -502,7 +513,8 @@ class MasksListCtrlPanel(wx.ListCtrl):
502 def OnClickItem(self, evt): 513 def OnClickItem(self, evt):
503 self._click_check = False 514 self._click_check = False
504 item_idx, flag = (self.HitTest(evt.GetPosition())) 515 item_idx, flag = (self.HitTest(evt.GetPosition()))
505 - if flag == wx.LIST_HITTEST_ONITEMICON: 516 + column_clicked = self.get_column_clicked(evt.GetPosition())
  517 + if column_clicked == 0:
506 self._click_check = True 518 self._click_check = True
507 item = self.GetItem(item_idx, 0) 519 item = self.GetItem(item_idx, 0)
508 flag = not bool(item.GetImage()) 520 flag = not bool(item.GetImage())
@@ -510,16 +522,23 @@ class MasksListCtrlPanel(wx.ListCtrl): @@ -510,16 +522,23 @@ class MasksListCtrlPanel(wx.ListCtrl):
510 self.OnCheckItem(item_idx, flag) 522 self.OnCheckItem(item_idx, flag)
511 evt.Skip() 523 evt.Skip()
512 524
513 - def OnItemActivated(self, evt):  
514 - if not self._click_check:  
515 - item = self.GetItem(evt.GetItem().GetId(), 1)  
516 - ctrl = self.EditLabel(item.GetId())  
517 - w, h = ctrl.GetClientSize()  
518 - w = self.GetColumnWidth(1)  
519 - ctrl.SetClientSize(w, h)  
520 - ctrl.SetValue(item.GetText())  
521 - ctrl.SelectAll()  
522 - evt.Skip() 525 + def OnDblClickItem(self, evt):
  526 + self._click_check = False
  527 + item_idx, flag = (self.HitTest(evt.GetPosition()))
  528 + column_clicked = self.get_column_clicked(evt.GetPosition())
  529 + if column_clicked == 1:
  530 + item = self.GetItem(item_idx, 1)
  531 + self.enter_edition(item)
  532 + evt.Skip()
  533 +
  534 + def enter_edition(self, item):
  535 + print("Enter edition")
  536 + ctrl = self.EditLabel(item.GetId())
  537 + w, h = ctrl.GetClientSize()
  538 + w = self.GetColumnWidth(1)
  539 + ctrl.SetClientSize(w, h)
  540 + ctrl.SetValue(item.GetText())
  541 + ctrl.SelectAll()
523 542
524 def CreateColourBitmap(self, colour): 543 def CreateColourBitmap(self, colour):
525 """ 544 """