| OLD | NEW |
| 1 #!/usr/bin/python -tt | 1 #!/usr/bin/python -tt |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Edit buttons for bmpblock object""" | 6 """Edit buttons for bmpblock object""" |
| 7 | 7 |
| 8 import wx | 8 import wx |
| 9 | 9 |
| 10 class Frame(wx.Frame): | 10 class Frame(wx.Frame): |
| 11 | 11 |
| 12 def __init__(self, bmpblock=None, title=None): | 12 def __init__(self, bmpblock=None, title=None): |
| 13 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(200,400)) | 13 wx.Frame.__init__(self, None, wx.ID_ANY, title, size=(200,400)) |
| 14 menuFile = wx.Menu() | 14 menuFile = wx.Menu() |
| 15 m_about = menuFile.Append(wx.ID_ANY, "About...\tCtrl+A") | 15 m_about = menuFile.Append(wx.ID_ANY, "About...\tCtrl+A") |
| 16 menuFile.AppendSeparator() | 16 menuFile.AppendSeparator() |
| 17 m_reload = menuFile.Append(wx.ID_ANY, "Reload\tCtrl+R") | 17 m_reload = menuFile.Append(wx.ID_ANY, "Reload\tCtrl+R") |
| 18 m_snapshot = menuFile.Append(wx.ID_ANY, "Save snapshot") |
| 18 m_quit = menuFile.Append(wx.ID_ANY, "Quit\tCtrl+Q") | 19 m_quit = menuFile.Append(wx.ID_ANY, "Quit\tCtrl+Q") |
| 19 menuBar = wx.MenuBar() | 20 menuBar = wx.MenuBar() |
| 20 menuBar.Append(menuFile, "&File") | 21 menuBar.Append(menuFile, "&File") |
| 21 self.SetMenuBar(menuBar) | 22 self.SetMenuBar(menuBar) |
| 22 self.CreateStatusBar() | 23 self.CreateStatusBar() |
| 23 self.Bind(wx.EVT_MENU, self.OnAbout, m_about) | 24 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.OnReload, m_reload) |
| 26 self.Bind(wx.EVT_MENU, self.OnSaveit, m_snapshot) |
| 25 self.Bind(wx.EVT_MENU, self.OnQuit, m_quit) | 27 self.Bind(wx.EVT_MENU, self.OnQuit, m_quit) |
| 26 self.Bind(wx.EVT_CLOSE, self.OnQuit) | 28 self.Bind(wx.EVT_CLOSE, self.OnQuit) |
| 27 | 29 |
| 28 acctbl = wx.AcceleratorTable([ | 30 acctbl = wx.AcceleratorTable([ |
| 29 (wx.ACCEL_CTRL, ord('A'), m_about.GetId()), | 31 (wx.ACCEL_CTRL, ord('A'), m_about.GetId()), |
| 30 (wx.ACCEL_CTRL, ord('R'), m_reload.GetId()), | 32 (wx.ACCEL_CTRL, ord('R'), m_reload.GetId()), |
| 31 (wx.ACCEL_CTRL, ord('Q'), m_quit.GetId()) | 33 (wx.ACCEL_CTRL, ord('Q'), m_quit.GetId()) |
| 32 ]) | 34 ]) |
| 33 | 35 |
| 34 self.SetAcceleratorTable(acctbl) | 36 self.SetAcceleratorTable(acctbl) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 wx.GetApp().ExitMainLoop() | 73 wx.GetApp().ExitMainLoop() |
| 72 | 74 |
| 73 def OnReload(self, event): | 75 def OnReload(self, event): |
| 74 """Tell the model object to refresh the view that the user sees. | 76 """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. | 77 FIXME: The model itself should know to do this without being told. |
| 76 """ | 78 """ |
| 77 self.bmpblock.Reload() | 79 self.bmpblock.Reload() |
| 78 self.do_update = True; | 80 self.do_update = True; |
| 79 self.UpdateControls() | 81 self.UpdateControls() |
| 80 | 82 |
| 83 def OnSaveit(self, event): |
| 84 """Tell the model object to save the view that the user sees.""" |
| 85 self.bmpblock.Saveit() |
| 86 |
| 81 def OnSelected(self, event): | 87 def OnSelected(self, event): |
| 82 """User may have picked one of the pulldowns.""" | 88 """User may have picked one of the pulldowns.""" |
| 83 if event.IsSelection(): | 89 if event.IsSelection(): |
| 84 self.bmpblock.current_screen = event.GetString() | 90 self.bmpblock.current_screen = event.GetString() |
| 85 self.do_update = True | 91 self.do_update = True |
| 86 event.Skip() | 92 event.Skip() |
| 87 | 93 |
| 88 def UpdateControls(self): | 94 def UpdateControls(self): |
| 89 """Reload all the buttons with the current model information.""" | 95 """Reload all the buttons with the current model information.""" |
| 90 screens = self.bmpblock.yaml["screens"] | 96 screens = self.bmpblock.yaml["screens"] |
| 91 self.screenlist.Clear() | 97 self.screenlist.Clear() |
| 92 self.screenlist.AppendItems(sorted(screens.keys())) | 98 self.screenlist.AppendItems(sorted(screens.keys())) |
| 93 current = self.bmpblock.current_screen | 99 current = self.bmpblock.current_screen |
| 94 self.screenlist.SetStringSelection(current) | 100 self.screenlist.SetStringSelection(current) |
| 95 self.SetStatusText(self.bmpblock.filename) | 101 self.SetStatusText(self.bmpblock.filename) |
| 96 | 102 |
| 97 def OnIdle(self, event=None): | 103 def OnIdle(self, event=None): |
| 98 """What to do, what to do...""" | 104 """What to do, what to do...""" |
| 99 if self.do_update: | 105 if self.do_update: |
| 100 # FIXME: The model should know when to do this itself, right? | 106 # FIXME: The model should know when to do this itself, right? |
| 101 self.bmpblock.Redisplay() | 107 self.bmpblock.Redisplay() |
| 102 self.do_update = False | 108 self.do_update = False |
| OLD | NEW |