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 |
| 36 # create UI components |
| 37 panel = wx.Panel(self) |
| 38 button_reload = wx.Button(panel, label="Reload File") |
| 39 self.screenlist = wx.ListBox(panel, wx.ID_ANY) |
| 40 |
| 41 # connect events |
| 42 self.Bind(wx.EVT_BUTTON, self.OnReload, button_reload) |
| 43 self.Bind(wx.EVT_LISTBOX, self.OnSelected, self.screenlist) |
| 44 self.Bind(wx.EVT_IDLE, self.OnIdle) |
| 45 |
| 46 # place the componenents |
| 47 sizer = wx.BoxSizer(wx.VERTICAL) |
| 48 sizer.Add(button_reload) |
| 49 sizer.Add(wx.StaticText(panel, wx.ID_ANY, "Screens")) |
| 50 sizer.Add(self.screenlist, 1, wx.EXPAND) |
| 51 |
| 52 panel.SetSizer(sizer) |
| 53 panel.Fit() |
| 54 |
| 55 # now, what are we looking at? |
| 56 self.bmpblock = bmpblock |
| 57 self.UpdateControls() |
| 58 self.do_update = True |
| 59 self.screenlist.SetFocus() |
| 60 |
| 61 def OnAbout(self, event): |
| 62 """Display basic information about this application.""" |
| 63 msg = ("Yes, all this does right now is display the screens from the config" |
| 64 " file. You still have to edit, save, and reload in order to see any" |
| 65 " changes. Learning python and wxpython is my 20% project (actually" |
| 66 " it's more like 5%). Feel free to improve things.\n\t-- bill") |
| 67 wx.MessageBox(msg, "About", wx.OK | wx.ICON_INFORMATION, self) |
| 68 |
| 69 def OnQuit(self, event): |
| 70 """Close all application windows and quit.""" |
| 71 wx.GetApp().ExitMainLoop() |
| 72 |
| 73 def OnReload(self, event): |
| 74 """Tell the model object to refresh the view that the user sees. |
| 75 FIXME: The model itself should know to do this without being told. |
| 76 """ |
| 77 self.bmpblock.Reload() |
| 78 self.do_update = True; |
| 79 self.UpdateControls() |
| 80 |
| 81 def OnSelected(self, event): |
| 82 """User may have picked one of the pulldowns.""" |
| 83 if event.IsSelection(): |
| 84 self.bmpblock.current_screen = event.GetString() |
| 85 self.do_update = True |
| 86 event.Skip() |
| 87 |
| 88 def UpdateControls(self): |
| 89 """Reload all the buttons with the current model information.""" |
| 90 screens = self.bmpblock.yaml["screens"] |
| 91 self.screenlist.Clear() |
| 92 self.screenlist.AppendItems(sorted(screens.keys())) |
| 93 current = self.bmpblock.current_screen |
| 94 self.screenlist.SetStringSelection(current) |
| 95 self.SetStatusText(self.bmpblock.filename) |
| 96 |
| 97 def OnIdle(self, event=None): |
| 98 """What to do, what to do...""" |
| 99 if self.do_update: |
| 100 # FIXME: The model should know when to do this itself, right? |
| 101 self.bmpblock.Redisplay() |
| 102 self.do_update = False |
OLD | NEW |