Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created October 16, 2017 13:34
Show Gist options
  • Save driscollis/121c3766188ebfca7e6edbfaa9b8d10c to your computer and use it in GitHub Desktop.
Save driscollis/121c3766188ebfca7e6edbfaa9b8d10c to your computer and use it in GitHub Desktop.
Ribbon bar, menu and grid
import wx
import wx.grid as gridlib
import wx.lib.agw.ribbon as RB
class MyRibbonBar(wx.Panel):
def __init__(self, *ls, **kw):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
wx.Panel.__init__(self, *ls, **kw)
ribbon = RB.RibbonBar(self)
page = RB.RibbonPage(ribbon, wx.ID_ANY, "Page")
panel = RB.RibbonPanel(page, wx.ID_ANY, "Create Project")
bbar = RB.RibbonButtonBar(panel)
bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_OTHER, wx.Size(48, 48))
bbar.AddSimpleButton(wx.ID_ANY, "New", bmp, '')
bbar.AddSimpleButton(wx.ID_ANY, "New2", bmp, '') # uncomment for the good result
ribbon.Realize()
s = wx.BoxSizer(wx.VERTICAL)
s.Add(ribbon, 0, wx.EXPAND)
self.SetSizer(s)
class Panel(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self,parent)
ribbon = MyRibbonBar(self)
btn = wx.Button(self,label="push",pos=(100,400))
self.Bind(wx.EVT_BUTTON, self.kliknuti, btn)
btn1 = wx.Button(self,label="push me",pos=(200,400))
self.Bind(wx.EVT_BUTTON, self.kliknuti1, btn1)
global grid
grid = gridlib.Grid(self)
grid.CreateGrid(10,20)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(ribbon)
sizer.Add(grid, 0, wx.EXPAND)
self.SetSizer(sizer)
def kliknuti(self,event):
grid.SetCellValue(0, 0, 'wxGrid is good')
def kliknuti1(self,event):
grid.SetCellValue(1, 0, '10')
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Exceptions", size=(600,600))
panel = Panel(self)
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
"Exit the application")
menuBar.Append(fileMenu, "&File")
self.Bind(wx.EVT_MENU, self.on_exit, exitMenuItem)
self.SetMenuBar(menuBar)
self.Show()
def on_exit(self, event):
print('exiting')
if __name__ == "__main__":
app = wx.App()
frame = Frame()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment