Commit 40466824c428da396f37502b925f979af9da68b7
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
app.py
| ... | ... | @@ -102,7 +102,7 @@ class InVesalius(wx.App): |
| 102 | 102 | """ |
| 103 | 103 | Initialize splash screen and main frame. |
| 104 | 104 | """ |
| 105 | - | |
| 105 | + | |
| 106 | 106 | from multiprocessing import freeze_support |
| 107 | 107 | freeze_support() |
| 108 | 108 | |
| ... | ... | @@ -183,18 +183,18 @@ class Inv3SplashScreen(SplashScreen): |
| 183 | 183 | |
| 184 | 184 | # session.SaveConfigFileBackup() |
| 185 | 185 | |
| 186 | - | |
| 186 | + | |
| 187 | 187 | # Only after language was defined, splash screen will be |
| 188 | 188 | # shown |
| 189 | 189 | if lang: |
| 190 | - | |
| 190 | + | |
| 191 | 191 | #import locale |
| 192 | 192 | #try: |
| 193 | 193 | # locale.setlocale(locale.LC_ALL, '') |
| 194 | 194 | #except locale.Error: |
| 195 | 195 | # pass |
| 196 | - | |
| 197 | - | |
| 196 | + | |
| 197 | + | |
| 198 | 198 | # For pt_BR, splash_pt.png should be used |
| 199 | 199 | if (lang.startswith('pt')): |
| 200 | 200 | icon_file = "splash_pt.png" |
| ... | ... | @@ -206,13 +206,13 @@ class Inv3SplashScreen(SplashScreen): |
| 206 | 206 | abs_file_path = os.path.abspath(".." + os.sep) |
| 207 | 207 | path = abs_file_path |
| 208 | 208 | path = os.path.join(path, 'icons', icon_file) |
| 209 | - | |
| 209 | + | |
| 210 | 210 | else: |
| 211 | 211 | |
| 212 | 212 | path = os.path.join(".","icons", icon_file) |
| 213 | 213 | if not os.path.exists(path): |
| 214 | 214 | path = os.path.join(".", "icons", "splash_en.png") |
| 215 | - | |
| 215 | + | |
| 216 | 216 | bmp = wx.Image(path).ConvertToBitmap() |
| 217 | 217 | |
| 218 | 218 | try: |
| ... | ... | @@ -236,10 +236,10 @@ class Inv3SplashScreen(SplashScreen): |
| 236 | 236 | from invesalius.gui.frame import Frame |
| 237 | 237 | from invesalius.control import Controller |
| 238 | 238 | from invesalius.project import Project |
| 239 | - | |
| 239 | + | |
| 240 | 240 | self.main = Frame(None) |
| 241 | 241 | self.control = Controller(self.main) |
| 242 | - | |
| 242 | + | |
| 243 | 243 | self.fc = wx.CallLater(200, self.ShowMain) |
| 244 | 244 | options, args = parse_comand_line() |
| 245 | 245 | wx.CallLater(1, use_cmd_optargs, options, args) |
| ... | ... | @@ -502,7 +502,7 @@ def main(): |
| 502 | 502 | if __name__ == '__main__': |
| 503 | 503 | #Is needed because of pyinstaller |
| 504 | 504 | multiprocessing.freeze_support() |
| 505 | - | |
| 505 | + | |
| 506 | 506 | #Needed in win 32 exe |
| 507 | 507 | if hasattr(sys,"frozen") and sys.platform.startswith('win'): |
| 508 | 508 | |
| ... | ... | @@ -527,4 +527,3 @@ if __name__ == '__main__': |
| 527 | 527 | |
| 528 | 528 | # Init application |
| 529 | 529 | main() |
| 530 | - | ... | ... |
invesalius/gui/data_notebook.py
| ... | ... | @@ -366,8 +366,9 @@ class MasksListCtrlPanel(wx.ListCtrl): |
| 366 | 366 | def __bind_events_wx(self): |
| 367 | 367 | self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel) |
| 368 | 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 | 370 | self.Bind(wx.EVT_LEFT_UP, self.OnClickItem) |
| 371 | + self.Bind(wx.EVT_LEFT_DCLICK, self.OnDblClickItem) | |
| 371 | 372 | |
| 372 | 373 | def __bind_events(self): |
| 373 | 374 | Publisher.subscribe(self.AddMask, 'Add mask') |
| ... | ... | @@ -482,6 +483,16 @@ class MasksListCtrlPanel(wx.ListCtrl): |
| 482 | 483 | |
| 483 | 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 | 496 | def OnEditLabel(self, evt): |
| 486 | 497 | if not evt.IsEditCancelled(): |
| 487 | 498 | index = evt.GetIndex() |
| ... | ... | @@ -502,7 +513,8 @@ class MasksListCtrlPanel(wx.ListCtrl): |
| 502 | 513 | def OnClickItem(self, evt): |
| 503 | 514 | self._click_check = False |
| 504 | 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 | 518 | self._click_check = True |
| 507 | 519 | item = self.GetItem(item_idx, 0) |
| 508 | 520 | flag = not bool(item.GetImage()) |
| ... | ... | @@ -510,16 +522,23 @@ class MasksListCtrlPanel(wx.ListCtrl): |
| 510 | 522 | self.OnCheckItem(item_idx, flag) |
| 511 | 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 | 543 | def CreateColourBitmap(self, colour): |
| 525 | 544 | """ | ... | ... |