Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python -tt | |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Edit buttons for bmpblock object""" | |
| 7 | |
| 8 import wx | |
| 9 | |
| 10 class Frame(wx.Frame): | |
| 11 | |
| 12 def __init__(self, bmpblock=None, title=None): | |
| 13 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(200,400)) | |
| 14 menuFile = wx.Menu() | |
| 15 m_about = menuFile.Append(wx.ID_ANY, "About...\tCtrl+A") | |
| 16 menuFile.AppendSeparator() | |
| 17 m_reload = menuFile.Append(wx.ID_ANY, "Reload\tCtrl+R") | |
| 18 m_quit = menuFile.Append(wx.ID_ANY, "Quit\tCtrl+Q") | |
| 19 menuBar = wx.MenuBar() | |
| 20 menuBar.Append(menuFile, "&File") | |
| 21 self.SetMenuBar(menuBar) | |
| 22 self.CreateStatusBar() | |
| 23 self.Bind(wx.EVT_MENU, self.OnAbout, m_about) | |
| 24 self.Bind(wx.EVT_MENU, self.OnReload, m_reload) | |
| 25 self.Bind(wx.EVT_MENU, self.OnQuit, m_quit) | |
| 26 self.Bind(wx.EVT_CLOSE, self.OnQuit) | |
| 27 | |
| 28 acctbl = wx.AcceleratorTable([ | |
| 29 (wx.ACCEL_CTRL, ord('A'), m_about.GetId()), | |
| 30 (wx.ACCEL_CTRL, ord('R'), m_reload.GetId()), | |
| 31 (wx.ACCEL_CTRL, ord('Q'), m_quit.GetId()) | |
| 32 ]) | |
| 33 | |
| 34 self.SetAcceleratorTable(acctbl) | |
| 35 | |
|
Randall Spangler
2011/03/01 17:37:18
Extra newline
| |
| 36 | |
| 37 # create UI components | |
| 38 panel = wx.Panel(self) | |
| 39 button_reload = wx.Button(panel, label="Reload File") | |
| 40 self.screenlist = wx.ListBox(panel, wx.ID_ANY) | |
| 41 | |
| 42 # connect events | |
| 43 self.Bind(wx.EVT_BUTTON, self.OnReload, button_reload) | |
| 44 self.Bind(wx.EVT_LISTBOX, self.OnSelected, self.screenlist) | |
| 45 self.Bind(wx.EVT_IDLE, self.OnIdle) | |
| 46 | |
| 47 # place the componenents | |
| 48 sizer = wx.BoxSizer(wx.VERTICAL) | |
| 49 sizer.Add(button_reload) | |
| 50 sizer.Add(wx.StaticText(panel, wx.ID_ANY, "Screens")) | |
| 51 sizer.Add(self.screenlist, 1, wx.EXPAND) | |
| 52 | |
| 53 panel.SetSizer(sizer) | |
| 54 panel.Fit() | |
| 55 | |
| 56 # now, what are we looking at? | |
| 57 self.bmpblock = bmpblock | |
| 58 self.UpdateControls() | |
| 59 self.do_update = True | |
| 60 self.screenlist.SetFocus() | |
| 61 | |
| 62 def OnAbout(self, event): | |
| 63 """Display basic information about this application.""" | |
| 64 msg = ("Yes, all this does right now is display the screens from the config" | |
| 65 " file. You still have to edit, save, and reload in order to see any" | |
| 66 " changes. Learning python and wxpython is my 20% project (actually" | |
| 67 " it's more like 5%). Feel free to improve things.\n\t-- bill") | |
| 68 wx.MessageBox(msg, "About", wx.OK | wx.ICON_INFORMATION, self) | |
| 69 | |
| 70 def OnQuit(self, event): | |
| 71 """Close all application windows and quit.""" | |
| 72 wx.GetApp().ExitMainLoop() | |
| 73 | |
| 74 def OnReload(self, event): | |
| 75 """Tell the model object to refresh the view that the user sees. | |
| 76 FIXME: The model itself should know to do this without being told. | |
| 77 """ | |
| 78 self.bmpblock.Reload() | |
| 79 self.do_update = True; | |
| 80 self.UpdateControls() | |
| 81 | |
| 82 def OnSelected(self, event): | |
| 83 """I may have picked one of the pulldowns.""" | |
|
Randall Spangler
2011/03/01 17:37:18
I -> User
| |
| 84 if event.IsSelection(): | |
| 85 self.bmpblock.current_screen = event.GetString() | |
| 86 self.do_update = True | |
| 87 event.Skip() | |
| 88 | |
| 89 def UpdateControls(self): | |
| 90 """Reload all the buttons with the current model information.""" | |
| 91 screens = self.bmpblock.yaml["screens"] | |
| 92 self.screenlist.Clear() | |
| 93 self.screenlist.AppendItems(sorted(screens.keys())) | |
| 94 current = self.bmpblock.current_screen | |
| 95 self.screenlist.SetStringSelection(current) | |
| 96 self.SetStatusText(self.bmpblock.filename) | |
| 97 | |
| 98 def OnIdle(self, event=None): | |
| 99 """What to do, what to do...""" | |
| 100 if self.do_update: | |
| 101 # FIXME: The model should know when to do this itself, right? | |
| 102 self.bmpblock.Redisplay() | |
| 103 self.do_update = False | |
| OLD | NEW |