491 grid.SetCellEditor(row, col, editor) |
491 grid.SetCellEditor(row, col, editor) |
492 grid.SetCellRenderer(row, col, renderer) |
492 grid.SetCellRenderer(row, col, renderer) |
493 |
493 |
494 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
494 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
495 self.ResizeRow(grid, row) |
495 self.ResizeRow(grid, row) |
496 |
496 |
497 |
|
498 [ID_VARIABLESEDITOR, ID_VARIABLESEDITORVARIABLESGRID, |
|
499 ID_VARIABLESEDITORADDVARIABLEBUTTON, ID_VARIABLESEDITORDELETEVARIABLEBUTTON, |
|
500 ID_VARIABLESEDITORUPVARIABLEBUTTON, ID_VARIABLESEDITORDOWNVARIABLEBUTTON |
|
501 ] = [wx.NewId() for _init_ctrls in range(6)] |
|
502 |
497 |
503 class VariablesEditor(wx.Panel): |
498 class VariablesEditor(wx.Panel): |
504 |
499 |
505 if wx.VERSION < (2, 6, 0): |
|
506 def Bind(self, event, function, id = None): |
|
507 if id is not None: |
|
508 event(self, id, function) |
|
509 else: |
|
510 event(self, function) |
|
511 |
|
512 def _init_coll_MainSizer_Growables(self, parent): |
|
513 parent.AddGrowableCol(0) |
|
514 parent.AddGrowableRow(0) |
|
515 |
|
516 def _init_coll_MainSizer_Items(self, parent): |
|
517 parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW) |
|
518 parent.AddSizer(self.ButtonsSizer, 0, border=0, flag=wx.GROW) |
|
519 |
|
520 def _init_coll_ButtonsSizer_Growables(self, parent): |
|
521 parent.AddGrowableCol(0) |
|
522 parent.AddGrowableRow(0) |
|
523 |
|
524 def _init_coll_ButtonsSizer_Items(self, parent): |
|
525 parent.AddWindow(self.AddVariableButton, 0, border=0, flag=wx.ALIGN_RIGHT) |
|
526 parent.AddWindow(self.DeleteVariableButton, 0, border=0, flag=0) |
|
527 parent.AddWindow(self.UpVariableButton, 0, border=0, flag=0) |
|
528 parent.AddWindow(self.DownVariableButton, 0, border=0, flag=0) |
|
529 |
|
530 def _init_sizers(self): |
|
531 self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
|
532 self.ButtonsSizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0) |
|
533 |
|
534 self._init_coll_MainSizer_Growables(self.MainSizer) |
|
535 self._init_coll_MainSizer_Items(self.MainSizer) |
|
536 self._init_coll_ButtonsSizer_Growables(self.ButtonsSizer) |
|
537 self._init_coll_ButtonsSizer_Items(self.ButtonsSizer) |
|
538 |
|
539 self.SetSizer(self.MainSizer) |
|
540 |
|
541 def _init_ctrls(self, prnt): |
|
542 wx.Panel.__init__(self, id=ID_VARIABLESEDITOR, name='', parent=prnt, |
|
543 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL) |
|
544 |
|
545 self.VariablesGrid = CustomGrid(id=ID_VARIABLESEDITORVARIABLESGRID, |
|
546 name='VariablesGrid', parent=self, pos=wx.Point(0, 0), |
|
547 size=wx.Size(-1, -1), style=wx.VSCROLL) |
|
548 if wx.VERSION >= (2, 5, 0): |
|
549 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
|
550 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
|
551 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
|
552 else: |
|
553 wx.grid.EVT_GRID_CELL_CHANGE(self.VariablesGrid, self.OnVariablesGridCellChange) |
|
554 wx.grid.EVT_GRID_CELL_LEFT_CLICK(self.VariablesGrid, self.OnVariablesGridCellLeftClick) |
|
555 wx.grid.EVT_GRID_EDITOR_SHOWN(self.VariablesGrid, self.OnVariablesGridEditorShown) |
|
556 |
|
557 self.AddVariableButton = wx.Button(id=ID_VARIABLESEDITORADDVARIABLEBUTTON, label='Add Variable', |
|
558 name='AddVariableButton', parent=self, pos=wx.Point(0, 0), |
|
559 size=wx.Size(122, 32), style=0) |
|
560 |
|
561 self.DeleteVariableButton = wx.Button(id=ID_VARIABLESEDITORDELETEVARIABLEBUTTON, label='Delete Variable', |
|
562 name='DeleteVariableButton', parent=self, pos=wx.Point(0, 0), |
|
563 size=wx.Size(122, 32), style=0) |
|
564 |
|
565 self.UpVariableButton = wx.Button(id=ID_VARIABLESEDITORUPVARIABLEBUTTON, label='^', |
|
566 name='UpVariableButton', parent=self, pos=wx.Point(0, 0), |
|
567 size=wx.Size(32, 32), style=0) |
|
568 |
|
569 self.DownVariableButton = wx.Button(id=ID_VARIABLESEDITORDOWNVARIABLEBUTTON, label='v', |
|
570 name='DownVariableButton', parent=self, pos=wx.Point(0, 0), |
|
571 size=wx.Size(32, 32), style=0) |
|
572 |
|
573 self._init_sizers() |
|
574 |
|
575 def __init__(self, parent, window, controler): |
500 def __init__(self, parent, window, controler): |
576 self._init_ctrls(parent) |
501 wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) |
577 |
502 |
|
503 main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=4) |
|
504 main_sizer.AddGrowableCol(0) |
|
505 main_sizer.AddGrowableRow(0) |
|
506 |
|
507 self.VariablesGrid = CustomGrid(self, style=wx.VSCROLL) |
|
508 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnVariablesGridCellChange) |
|
509 self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnVariablesGridCellLeftClick) |
|
510 self.VariablesGrid.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.OnVariablesGridEditorShown) |
|
511 main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW) |
|
512 |
|
513 controls_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
514 main_sizer.AddSizer(controls_sizer, border=5, flag=wx.TOP|wx.ALIGN_RIGHT) |
|
515 |
|
516 for name, bitmap, help in [ |
|
517 ("AddVariableButton", "add_element", _("Add variable")), |
|
518 ("DeleteVariableButton", "remove_element", _("Remove variable")), |
|
519 ("UpVariableButton", "up", _("Move variable up")), |
|
520 ("DownVariableButton", "down", _("Move variable down"))]: |
|
521 button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), |
|
522 size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
523 button.SetToolTipString(help) |
|
524 setattr(self, name, button) |
|
525 controls_sizer.AddWindow(button, border=5, flag=wx.LEFT) |
|
526 |
|
527 self.SetSizer(main_sizer) |
|
528 |
578 self.ParentWindow = window |
529 self.ParentWindow = window |
579 self.Controler = controler |
530 self.Controler = controler |
580 |
531 |
581 self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""} |
532 self.VariablesDefaultValue = {"Name" : "", "Class" : "input", "Type" : ""} |
582 self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"]) |
533 self.Table = VariablesTable(self, [], ["#", "Name", "Class", "Type"]) |