dialogs/ActionBlockDialog.py
changeset 714 131ea7f237b9
parent 606 d65122c61eaf
child 757 628dd4762b57
--- a/dialogs/ActionBlockDialog.py	Fri Jun 15 18:03:25 2012 +0200
+++ b/dialogs/ActionBlockDialog.py	Mon Jun 25 20:03:53 2012 +0200
@@ -23,11 +23,13 @@
 
 import wx
 import wx.grid
+import wx.lib.buttons
 
 from controls import CustomGrid, CustomTable
-
-#-------------------------------------------------------------------------------
-#                            Action Block Dialog
+from utils.BitmapLibrary import GetBitmap
+
+#-------------------------------------------------------------------------------
+#                                  Helpers
 #-------------------------------------------------------------------------------
 
 def GetActionTableColnames():
@@ -38,6 +40,10 @@
     _ = lambda x: x
     return [_("Action"), _("Variable"), _("Inline")]
 
+#-------------------------------------------------------------------------------
+#                               Action Table
+#-------------------------------------------------------------------------------
+
 class ActionTable(CustomTable):
     
     def GetValue(self, row, col):
@@ -105,105 +111,54 @@
                 grid.SetCellBackgroundColour(row, col, wx.WHITE)
             self.ResizeRow(grid, row)
 
-
-[ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, 
- ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON,
- ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, 
- ID_ACTIONBLOCKDIALOGDOWNBUTTON, 
-] = [wx.NewId() for _init_ctrls in range(7)]
+#-------------------------------------------------------------------------------
+#                            Action Block Dialog
+#-------------------------------------------------------------------------------
 
 class ActionBlockDialog(wx.Dialog):
     
-    if wx.VERSION < (2, 6, 0):
-        def Bind(self, event, function, id = None):
-            if id is not None:
-                event(self, id, function)
-            else:
-                event(self, function)
-    
-    def _init_coll_flexGridSizer1_Items(self, parent):
-        parent.AddSizer(self.TopSizer, 0, border=20, flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
-        parent.AddSizer(self.GridButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT)
-        parent.AddSizer(self.ButtonSizer, 0, border=20, flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
-        
-    def _init_coll_flexGridSizer1_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableRow(0)
-        
-    def _init_coll_TopSizer_Items(self, parent):
-        parent.AddWindow(self.staticText1, 0, border=0, flag=wx.GROW)
-        parent.AddWindow(self.ActionsGrid, 0, border=0, flag=wx.GROW)
-    
-    def _init_coll_TopSizer_Growables(self, parent):
-        parent.AddGrowableCol(0)
-        parent.AddGrowableRow(1)
-
-    def _init_coll_GridButtonSizer_Items(self, parent):
-        parent.AddWindow(self.AddButton, 0, border=10, flag=wx.GROW|wx.LEFT)
-        parent.AddWindow(self.DeleteButton, 0, border=10, flag=wx.GROW|wx.LEFT)
-        parent.AddWindow(self.UpButton, 0, border=10, flag=wx.GROW|wx.LEFT)
-        parent.AddWindow(self.DownButton, 0, border=10, flag=wx.GROW|wx.LEFT)
-
-    def _init_sizers(self):
-        self.flexGridSizer1 = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
-        self.TopSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
-        self.GridButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
-        
-        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
-        self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
-        self._init_coll_TopSizer_Items(self.TopSizer)
-        self._init_coll_TopSizer_Growables(self.TopSizer)
-        self._init_coll_GridButtonSizer_Items(self.GridButtonSizer)
-        
-        self.SetSizer(self.flexGridSizer1)
-    
-    def _init_ctrls(self, prnt):
-        wx.Dialog.__init__(self, id=ID_ACTIONBLOCKDIALOG,
-              name='ActionBlockDialog', parent=prnt,
-              size=wx.Size(500, 300), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER,
-              title=_('Edit action block properties'))
-        self.SetClientSize(wx.Size(500, 300))
-
-        self.staticText1 = wx.StaticText(id=ID_ACTIONBLOCKDIALOGSTATICTEXT1,
-              label=_('Actions:'), name='staticText1', parent=self,
-              pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
-
-        self.ActionsGrid = CustomGrid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID,
-              name='ActionsGrid', parent=self, pos=wx.Point(0, 0), 
-              size=wx.Size(0, 0), style=wx.VSCROLL)
+    def __init__(self, parent):
+        wx.Dialog.__init__(self, parent,
+              size=wx.Size(500, 300), title=_('Edit action block properties'))
+        
+        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10)
+        main_sizer.AddGrowableCol(0)
+        main_sizer.AddGrowableRow(1)
+        
+        top_sizer = wx.FlexGridSizer(cols=5, hgap=5, rows=1, vgap=0)
+        top_sizer.AddGrowableCol(0)
+        top_sizer.AddGrowableRow(0)
+        main_sizer.AddSizer(top_sizer, border=20,
+              flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
+        
+        actions_label = wx.StaticText(self, label=_('Actions:'))
+        top_sizer.AddWindow(actions_label, flag=wx.ALIGN_BOTTOM)
+        
+        for name, bitmap, help in [
+                ("AddButton", "add_element", _("Add action")),
+                ("DeleteButton", "remove_element", _("Remove action")),
+                ("UpButton", "up", _("Move action up")),
+                ("DownButton", "down", _("Move action down"))]:
+            button = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap(bitmap), 
+                  size=wx.Size(28, 28), style=wx.NO_BORDER)
+            button.SetToolTipString(help)
+            setattr(self, name, button)
+            top_sizer.AddWindow(button)
+        
+        self.ActionsGrid = CustomGrid(self, style=wx.VSCROLL)
         self.ActionsGrid.DisableDragGridSize()
         self.ActionsGrid.EnableScrolling(False, True)
-        if wx.VERSION >= (2, 6, 0):
-            self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange)
-        else:
-            wx.grid.EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange)
-        
-        self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label=_('Add'),
-              name='AddButton', parent=self, pos=wx.Point(0, 0),
-              size=wx.DefaultSize, style=0)
-        
-        self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label=_('Delete'),
-              name='DeleteButton', parent=self, pos=wx.Point(0, 0),
-              size=wx.DefaultSize, style=0)
-        
-        self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^',
-              name='UpButton', parent=self, pos=wx.Point(0, 0),
-              size=wx.Size(32, 32), style=0)
-        
-        self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v',
-              name='DownButton', parent=self, pos=wx.Point(0, 0),
-              size=wx.Size(32, 32), style=0)
-        
-        self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
-        if wx.VERSION >= (2, 5, 0):
-            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
-        else:
-            self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId())
-        
-        self._init_sizers()
-
-    def __init__(self, parent):
-        self._init_ctrls(parent)
+        self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, 
+                              self.OnActionsGridCellChange)
+        main_sizer.AddSizer(self.ActionsGrid, border=20,
+              flag=wx.GROW|wx.LEFT|wx.RIGHT)
+        
+        button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
+        self.Bind(wx.EVT_BUTTON, self.OnOK, button_sizer.GetAffirmativeButton())
+        main_sizer.AddSizer(button_sizer, border=20, 
+              flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
+        
+        self.SetSizer(main_sizer)
         
         self.Table = ActionTable(self, [], GetActionTableColnames())
         typelist = GetTypeList()