forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcefwxpanel_sample2.py
More file actions
70 lines (56 loc) · 2.2 KB
/
Copy pathcefwxpanel_sample2.py
File metadata and controls
70 lines (56 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Slightly more advanced sample illustrating the usage of CEFWindow class
# __author__ = "Greg Kacy <grkacy@gmail.com>"
import wx
import wx.lib.agw.flatnotebook as fnb
from cefwxpanel import initCEF, shutdownCEF, CEFWindow, GetApplicationPath
ROOT_NAME = "My Locations"
URLS = ["http://google.com",
"http://maps.google.com",
"http://youtube.com",
"http://yahoo.com",
"http://wikipedia.com",
"http://cyaninc.com",
]
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title='wxPython example', size=(600,400))
self.initComponents()
self.layoutComponents()
self.initEventHandlers()
def initComponents(self):
self.tree = wx.TreeCtrl(self, id=-1, size=(200, -1))
self.root = self.tree.AddRoot(ROOT_NAME)
for url in URLS:
self.tree.AppendItem(self.root, url)
self.tree.Expand(self.root)
self.tabs = fnb.FlatNotebook(self, wx.ID_ANY, agwStyle=fnb.FNB_NODRAG|fnb.FNB_X_ON_TAB)
def layoutComponents(self):
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.tree, 0, wx.EXPAND)
sizer.Add(self.tabs, 1, wx.EXPAND)
self.SetSizer(sizer)
def initEventHandlers(self):
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.OnPageClosing)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnSelChanged(self, event):
self.item = event.GetItem()
url = self.tree.GetItemText(self.item)
if url and url != ROOT_NAME:
cefPanel = CEFWindow(self.tabs, url=str(url))
self.tabs.AddPage(cefPanel, url)
self.tabs.SetSelection(self.tabs.GetPageCount()-1)
event.Skip()
def OnPageClosing(self, event):
print "One could place some extra closing stuff here"
event.Skip()
def OnClose(self, event):
self.Destroy()
if __name__ == '__main__':
initCEF()
print('wx.version=%s' % wx.version())
app = wx.PySimpleApp()
MainFrame().Show()
app.MainLoop()
del app # Let wx.App destructor do the cleanup before calling cefpython.Shutdown().
shutdownCEF()