MCPcopy Create free account
hub / github.com/cztomczak/cefpython / MainFrame

Class MainFrame

src/cefpython3.wx/examples/sample3.py:12–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import platform
11
12class MainFrame(wx.Frame):
13 def __init__(self):
14 wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
15 title='cefwx example3', size=(800,600))
16 self._InitComponents()
17 self._LayoutComponents()
18 self._InitEventHandlers()
19
20 def _InitComponents(self):
21 self.tabs = fnb.FlatNotebook(self, wx.ID_ANY,
22 agwStyle=fnb.FNB_NODRAG|fnb.FNB_X_ON_TAB)
23 # You also have to set the wx.WANTS_CHARS style for
24 # all parent panels/controls, if it's deeply embedded.
25 self.tabs.SetWindowStyleFlag(wx.WANTS_CHARS)
26
27 ctrl1 = chrome.ChromeCtrl(self.tabs, useTimer=True,
28 url="wikipedia.org")
29 ctrl1.GetNavigationBar().GetUrlCtrl().SetEditable(False)
30 ctrl1.GetNavigationBar().GetBackButton().SetBitmapLabel(
31 wx.Bitmap(os.path.join(os.path.dirname(os.path.abspath(__file__)),
32 "back.png"), wx.BITMAP_TYPE_PNG))
33 ctrl1.GetNavigationBar().GetForwardButton().SetBitmapLabel(
34 wx.Bitmap(os.path.join(os.path.dirname(os.path.abspath(__file__)),
35 "forward.png"), wx.BITMAP_TYPE_PNG))
36 ctrl1.GetNavigationBar().GetReloadButton().SetBitmapLabel(
37 wx.Bitmap(os.path.join(os.path.dirname(os.path.abspath(__file__)),
38 "reload_page.png"), wx.BITMAP_TYPE_PNG))
39
40 self.tabs.AddPage(ctrl1, "Wikipedia")
41
42 ctrl2 = chrome.ChromeCtrl(self.tabs, useTimer=True, url="google.com",
43 hasNavBar=False)
44 self.tabs.AddPage(ctrl2, "Google")
45
46 ctrl3 = chrome.ChromeCtrl(self.tabs, useTimer=True, url="greenpeace.org")
47 ctrl3.SetNavigationBar(CustomNavigationBar(ctrl3))
48 self.tabs.AddPage(ctrl3, "Greenpeace")
49
50 def _LayoutComponents(self):
51 sizer = wx.BoxSizer(wx.HORIZONTAL)
52 sizer.Add(self.tabs, 1, wx.EXPAND)
53 self.SetSizer(sizer)
54
55 def _InitEventHandlers(self):
56 self.Bind(wx.EVT_CLOSE, self.OnClose)
57
58 def OnClose(self, event):
59 # Remember to destroy all CEF browser references before calling
60 # Destroy(), so that browser closes cleanly. In this specific
61 # example there are no references kept, but keep this in mind
62 # for the future.
63 self.Destroy()
64 # On Mac the code after app.MainLoop() never executes, so
65 # need to call CEF shutdown here.
66 if platform.system() == "Darwin":
67 chrome.Shutdown()
68 wx.GetApp().Exit()
69

Callers 1

OnInitMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected