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

Class Gtk2Example

examples/gtk2.py:75–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75class Gtk2Example:
76 def __init__(self):
77 self.browser = None
78 self.menubar_height = 0
79 self.exiting = False
80
81 self.main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
82 self.main_window.connect('focus-in-event', self.on_focus_in)
83 self.main_window.connect('configure-event', self.on_configure)
84 self.main_window.connect('destroy', self.on_exit)
85 self.main_window.set_size_request(width=800, height=600)
86 self.main_window.set_title('GTK 2 example (PyGTK)')
87 icon = os.path.join(os.path.dirname(__file__), "resources", "gtk.png")
88 if os.path.exists(icon):
89 self.main_window.set_icon_from_file(icon)
90 self.main_window.realize()
91
92 self.vbox = gtk.VBox(False, 0)
93 self.vbox.connect('size-allocate', self.on_vbox_size_allocate)
94 self.menubar = self.create_menu()
95 self.menubar.connect('size-allocate', self.on_menubar_size_allocate)
96 self.vbox.pack_start(self.menubar, False, False, 0)
97 self.main_window.add(self.vbox)
98
99 # On Linux must show window first before embedding browser
100 # (Issue #347).
101 self.vbox.show()
102 self.main_window.show()
103 self.embed_browser()
104
105 self.vbox.get_window().focus()
106 self.main_window.get_window().focus()
107 if g_message_loop == MESSAGE_LOOP_TIMER:
108 gobject.timeout_add(10, self.on_timer)
109
110 def embed_browser(self):
111 windowInfo = cef.WindowInfo()
112 size = self.main_window.get_size()
113 rect = [0, 0, size[0], size[1]]
114 windowInfo.SetAsChild(self.get_window_handle(), rect)
115 self.browser = cef.CreateBrowserSync(windowInfo, settings={},
116 url="https://www.google.com/")
117 self.browser.SetClientHandler(LoadHandler())
118
119 def get_window_handle(self):
120 if WINDOWS:
121 return self.main_window.window.handle
122 elif LINUX:
123 return self.main_window.window.xid
124 elif MAC:
125 return self.main_window.window.nsview
126
127 def create_menu(self):
128 item1 = gtk.MenuItem('MenuBar')
129 item1.show()
130 item1_0 = gtk.Menu()
131 item1_1 = gtk.MenuItem('Just a menu')
132 item1_0.append(item1_1)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected