dialogs/ActionBlockDialog.py
changeset 714 131ea7f237b9
parent 606 d65122c61eaf
child 757 628dd4762b57
equal deleted inserted replaced
713:95a0a427f3ef 714:131ea7f237b9
    21 #License along with this library; if not, write to the Free Software
    21 #License along with this library; if not, write to the Free Software
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 
    23 
    24 import wx
    24 import wx
    25 import wx.grid
    25 import wx.grid
       
    26 import wx.lib.buttons
    26 
    27 
    27 from controls import CustomGrid, CustomTable
    28 from controls import CustomGrid, CustomTable
    28 
    29 from utils.BitmapLibrary import GetBitmap
    29 #-------------------------------------------------------------------------------
    30 
    30 #                            Action Block Dialog
    31 #-------------------------------------------------------------------------------
       
    32 #                                  Helpers
    31 #-------------------------------------------------------------------------------
    33 #-------------------------------------------------------------------------------
    32 
    34 
    33 def GetActionTableColnames():
    35 def GetActionTableColnames():
    34     _ = lambda x: x
    36     _ = lambda x: x
    35     return [_("Qualifier"), _("Duration"), _("Type"), _("Value"), _("Indicator")]
    37     return [_("Qualifier"), _("Duration"), _("Type"), _("Value"), _("Indicator")]
    36 
    38 
    37 def GetTypeList():
    39 def GetTypeList():
    38     _ = lambda x: x
    40     _ = lambda x: x
    39     return [_("Action"), _("Variable"), _("Inline")]
    41     return [_("Action"), _("Variable"), _("Inline")]
       
    42 
       
    43 #-------------------------------------------------------------------------------
       
    44 #                               Action Table
       
    45 #-------------------------------------------------------------------------------
    40 
    46 
    41 class ActionTable(CustomTable):
    47 class ActionTable(CustomTable):
    42     
    48     
    43     def GetValue(self, row, col):
    49     def GetValue(self, row, col):
    44         if row < self.GetNumberRows():
    50         if row < self.GetNumberRows():
   103                 grid.SetReadOnly(row, col, readonly)
   109                 grid.SetReadOnly(row, col, readonly)
   104                 
   110                 
   105                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
   111                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
   106             self.ResizeRow(grid, row)
   112             self.ResizeRow(grid, row)
   107 
   113 
   108 
   114 #-------------------------------------------------------------------------------
   109 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, 
   115 #                            Action Block Dialog
   110  ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON,
   116 #-------------------------------------------------------------------------------
   111  ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, 
       
   112  ID_ACTIONBLOCKDIALOGDOWNBUTTON, 
       
   113 ] = [wx.NewId() for _init_ctrls in range(7)]
       
   114 
   117 
   115 class ActionBlockDialog(wx.Dialog):
   118 class ActionBlockDialog(wx.Dialog):
   116     
   119     
   117     if wx.VERSION < (2, 6, 0):
   120     def __init__(self, parent):
   118         def Bind(self, event, function, id = None):
   121         wx.Dialog.__init__(self, parent,
   119             if id is not None:
   122               size=wx.Size(500, 300), title=_('Edit action block properties'))
   120                 event(self, id, function)
   123         
   121             else:
   124         main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
   122                 event(self, function)
   125         main_sizer.AddGrowableCol(0)
   123     
   126         main_sizer.AddGrowableRow(1)
   124     def _init_coll_flexGridSizer1_Items(self, parent):
   127         
   125         parent.AddSizer(self.TopSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
   128         top_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
   126         parent.AddSizer(self.GridButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT)
   129         top_sizer.AddGrowableCol(0)
   127         parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
   130         top_sizer.AddGrowableRow(0)
   128         
   131         main_sizer.AddSizer(top_sizer, border=20,
   129     def _init_coll_flexGridSizer1_Growables(self, parent):
   132               flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
   130         parent.AddGrowableCol(0)
   133         
   131         parent.AddGrowableRow(0)
   134         actions_label = wx.StaticText(self, label=_('Actions:'))
   132         
   135         top_sizer.AddWindow(actions_label, flag=wx.ALIGN_BOTTOM)
   133     def _init_coll_TopSizer_Items(self, parent):
   136         
   134         parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
   137         for name, bitmap, help in [
   135         parent.AddWindow(self.ActionsGrid, 0, border=0, flag=wx.GROW)
   138                 ("AddButton", "add_element", _("Add action")),
   136     
   139                 ("DeleteButton", "remove_element", _("Remove action")),
   137     def _init_coll_TopSizer_Growables(self, parent):
   140                 ("UpButton", "up", _("Move action up")),
   138         parent.AddGrowableCol(0)
   141                 ("DownButton", "down", _("Move action down"))]:
   139         parent.AddGrowableRow(1)
   142             button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
   140 
   143                   size=wx.Size(28, 28), style=wx.NO_BORDER)
   141     def _init_coll_GridButtonSizer_Items(self, parent):
   144             button.SetToolTipString(help)
   142         parent.AddWindow(self.AddButton, 0, border=10, flag=wx.GROW|wx.LEFT)
   145             setattr(self, name, button)
   143         parent.AddWindow(self.DeleteButton, 0, border=10, flag=wx.GROW|wx.LEFT)
   146             top_sizer.AddWindow(button)
   144         parent.AddWindow(self.UpButton, 0, border=10, flag=wx.GROW|wx.LEFT)
   147         
   145         parent.AddWindow(self.DownButton, 0, border=10, flag=wx.GROW|wx.LEFT)
   148         self.ActionsGrid = CustomGrid(self, style=wx.VSCROLL)
   146 
       
   147     def _init_sizers(self):
       
   148         self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
       
   149         self.TopSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
       
   150         self.GridButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
       
   151         
       
   152         self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
       
   153         self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
       
   154         self._init_coll_TopSizer_Items(self.TopSizer)
       
   155         self._init_coll_TopSizer_Growables(self.TopSizer)
       
   156         self._init_coll_GridButtonSizer_Items(self.GridButtonSizer)
       
   157         
       
   158         self.SetSizer(self.flexGridSizer1)
       
   159     
       
   160     def _init_ctrls(self, prnt):
       
   161         wx.Dialog.__init__(self, id=ID_ACTIONBLOCKDIALOG,
       
   162               name='ActionBlockDialog', parent=prnt,
       
   163               size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
       
   164               title=_('Edit action block properties'))
       
   165         self.SetClientSize(wx.Size(500, 300))
       
   166 
       
   167         self.staticText1 = wx.StaticText(id=ID_ACTIONBLOCKDIALOGSTATICTEXT1,
       
   168               label=_('Actions:'), name='staticText1', parent=self,
       
   169               pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
       
   170 
       
   171         self.ActionsGrid = CustomGrid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID,
       
   172               name='ActionsGrid', parent=self, pos=wx.Point(0, 0), 
       
   173               size=wx.Size(0, 0), style=wx.VSCROLL)
       
   174         self.ActionsGrid.DisableDragGridSize()
   149         self.ActionsGrid.DisableDragGridSize()
   175         self.ActionsGrid.EnableScrolling(False, True)
   150         self.ActionsGrid.EnableScrolling(False, True)
   176         if wx.VERSION >= (2, 6, 0):
   151         self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
   177             self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange)
   152                               self.OnActionsGridCellChange)
   178         else:
   153         main_sizer.AddSizer(self.ActionsGrid, border=20,
   179             wx.grid.EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange)
   154               flag=wx.GROW|wx.LEFT|wx.RIGHT)
   180         
   155         
   181         self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label=_('Add'),
   156         button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
   182               name='AddButton', parent=self, pos=wx.Point(0, 0),
   157         self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
   183               size=wx.DefaultSize, style=0)
   158         main_sizer.AddSizer(button_sizer, border=20, 
   184         
   159               flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
   185         self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label=_('Delete'),
   160         
   186               name='DeleteButton', parent=self, pos=wx.Point(0, 0),
   161         self.SetSizer(main_sizer)
   187               size=wx.DefaultSize, style=0)
       
   188         
       
   189         self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^',
       
   190               name='UpButton', parent=self, pos=wx.Point(0, 0),
       
   191               size=wx.Size(32, 32), style=0)
       
   192         
       
   193         self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v',
       
   194               name='DownButton', parent=self, pos=wx.Point(0, 0),
       
   195               size=wx.Size(32, 32), style=0)
       
   196         
       
   197         self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
       
   198         if wx.VERSION >= (2, 5, 0):
       
   199             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
       
   200         else:
       
   201             self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
       
   202         
       
   203         self._init_sizers()
       
   204 
       
   205     def __init__(self, parent):
       
   206         self._init_ctrls(parent)
       
   207         
   162         
   208         self.Table = ActionTable(self, [], GetActionTableColnames())
   163         self.Table = ActionTable(self, [], GetActionTableColnames())
   209         typelist = GetTypeList()       
   164         typelist = GetTypeList()       
   210         self.TypeList = ",".join(map(_,typelist))
   165         self.TypeList = ",".join(map(_,typelist))
   211         self.TranslateType = dict([(_(value), value) for value in typelist])
   166         self.TranslateType = dict([(_(value), value) for value in typelist])