Guest User

http://stackoverflow.com/questions/10267132/grid-and-sizers-

a guest
Apr 22nd, 2012
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.30 KB | None | 0 0
  1.  
  2. import wx
  3. import wx.grid
  4.  
  5. class SceRen:
  6.     pass
  7.  
  8.  
  9. class ScRenWindow(wx.Frame):
  10.    
  11.     dirname = ""
  12.     version = 0.1
  13.    
  14.     def __init__(self, parent, title):
  15.         self.sc_ren = SceRen("g:\\doesntexist\\", False, False)
  16.        
  17.         wx.Frame.__init__(self, parent, title=title)
  18.         panel = wx.Panel(self)
  19.        
  20.         vSizer = wx.BoxSizer(wx.VERTICAL)
  21.         grid = wx.GridBagSizer(hgap=5, vgap=5)
  22.        
  23.         label = wx.StaticText(panel, label="Select Folder")
  24.         grid.Add(label, pos=(0,0))
  25.        
  26.         textField = wx.TextCtrl(panel, size=(300, 23))
  27.         self.fieldOne = textField
  28.         grid.Add(textField, pos=(1,0))
  29.        
  30.         btn = wx.Button(panel, wx.ID_FIND, "Find")
  31.         self.Bind(wx.EVT_BUTTON, self.findFolder, btn)
  32.         grid.Add(btn, pos=(2,0))
  33.                
  34.         grid.Add((1, 20), pos=(3,0))
  35.        
  36.         label2 = wx.StaticText(panel, label="Files")
  37.         grid.Add(label2, pos=(4,0))
  38.        
  39.         # FileGrid
  40.         fileF = wx.grid.Grid(panel)
  41.         #fileF.SetMinSize(minSize=(400,200))
  42.         fileF.CreateGrid(1,3)
  43.         fileF.SetColLabelSize(0)
  44.         fileF.SetRowLabelSize(0)
  45.        
  46.         fileF.SetCellValue(0, 0, "Old")
  47.         fileF.SetCellValue(0, 1, "New")
  48.         fileF.SetCellValue(0, 2, "Update?")
  49.        
  50.         fileF.SetReadOnly(0,0)
  51.         fileF.SetReadOnly(0,1)
  52.         fileF.SetReadOnly(0,2)
  53.        
  54.         fileF.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.selectClick)
  55.         #wx.EVT_LEFT_DOWN(fileF, self.selectClick)
  56.         #wx.EVT_KEY_DOWN(fileF, self.selectClick)
  57.        
  58.         self.fileField = fileF
  59.         grid.Add(fileF, pos=(5,0))
  60.         # FileGrid end
  61.        
  62.        
  63.         runBtn = wx.Button(panel, wx.ID_APPLY, "Apply")
  64.         self.Bind(wx.EVT_BUTTON, self.applyScRen, runBtn)
  65.         grid.Add(runBtn, pos=(6,0))
  66.        
  67.         errlbl = wx.StaticText(panel, label="No Error")
  68.         grid.Add(errlbl, pos=(6,1))
  69.        
  70.         grid.Add((1, 40), pos=(7,0))
  71.        
  72.         # MENUBAR not used yet
  73.         filemenu = wx.Menu()
  74.         menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open a file")
  75.         self.Bind(wx.EVT_MENU, self.findFolder, menuOpen)
  76.         menuBar = wx.MenuBar()
  77.         menuBar.Append(filemenu,"&File")
  78.         self.SetMenuBar(menuBar)
  79.        
  80.         #panel.CreateStatusBar()
  81.         vSizer.Add(grid, 0, wx.ALL, 5)
  82.         panel.SetSizerAndFit(grid)
  83.         self.CreateStatusBar()
  84.         self.SetInitialSize()
  85.         self.Show(True)
  86.        
  87.     def findFolder(self, e):
  88.         dlg = wx.DirDialog(self, "Select Folder", ".", wx.DEFAULT_DIALOG_STYLE)
  89.         if dlg.ShowModal() == wx.ID_OK:
  90.             self.dirname = dlg.GetPath()
  91.         dlg.Destroy()
  92.         self.fieldOne.SetLabel(self.dirname)
  93.         self.populateGrid()
  94.         return True;
  95.    
  96.     def populateGrid(self):
  97.         pass
  98.        
  99.     def applyScRen(self, e):
  100.         pass
  101.        
  102.     def selectClick(self, e):
  103.         if (e.GetRow() > 0 and e.GetCol() == 2):
  104.             current = self.fileField.GetCellValue(e.GetRow(),e.GetCol()) == "y"
  105.             current = "n" if current else "y"
  106.             self.fileField.SetCellValue(e.GetRow(),e.GetCol(),current)
  107.        
  108. app = wx.App(False)
  109. frame = ScRenWindow(None, "Scren")
  110. app.MainLoop()
Add Comment
Please, Sign In to add comment