spacepaste

  1.  
  2. class StyledTextApp(wx.App):
  3. def OnInit(self):
  4. self.frame = StcFrame(None, title="Custom Lexer")
  5. self.frame.Show()
  6. return True
  7. class StcFrame(wx.Frame):
  8. """Main application window"""
  9. def __init__(self, parent, *args, **kwargs):
  10. super(StcFrame, self).__init__(parent,
  11. *args,
  12. **kwargs)
  13. self.panel = TestPanel(self)
  14. class TestPanel(wx.Panel):
  15. def __init__(self, parent):
  16. wx.Panel.__init__(self, parent, -1)
  17. self.Autosizer = wx.FlexGridSizer(rows=1, cols=2, hgap = -190, vgap = -1)
  18. self.Autosizer.SetFlexibleDirection(wx.VERTICAL)
  19. self.Autosizer.AddGrowableCol(1, 1) # 2 col
  20. self.SetSizer(self.Autosizer)
  21. self.Fit()
  22. class STC(st.StyledTextCtrl):
  23. def __init__(self, *args, **kwargs):
  24. super(STC, self).__init__(*args, **kwargs)
  25. self.InitUI()
  26. def InitUI(self):
  27. self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
  28. def OnRightDown(self, e):
  29. self.PopupMenu(MyPopupMenu(self), e.GetPosition())
  30. class MyPopupMenu(wx.Menu):
  31. def __init__(self, parent):
  32. super(MyPopupMenu, self).__init__()
  33. self.parent = parent
  34. mmi = wx.MenuItem(self, wx.NewId(), 'Remove')
  35. self.AppendItem(mmi)
  36. self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)
  37. def OnMinimize(self, e):
  38. StcFrame.panel.Autosizer.Remove(self) <------------------------------------------------------ this part is what I concern!
  39. def OnClose(self, e):
  40. if __name__ == '__main__':
  41. app = StyledTextApp(False)
  42. app.MainLoop()
  43.