def testWindowSetter(self): event = gtk.gdk.Event(gtk.gdk.BUTTON_PRESS) win1 = gtk.Window() win1.realize() event.window = win1.window self.assertEqual(event.window, win1.window) win2 = gtk.Window() win2.realize() event.window = win2.window self.assertEqual(event.window, win2.window)
def testProperty(self): win = gtk.Window() wtype = win.get_property('type') self.assertEquals(wtype, gtk.WINDOW_TOPLEVEL) self.assertTrue(isinstance(wtype, gtk.WindowType)) self.assertTrue('WINDOW_TOPLEVEL' in repr(wtype))
def testProperty(self): win = gtk.Window() wtype = win.get_property('type') assert wtype == gtk.WINDOW_TOPLEVEL assert isinstance(wtype, gtk.WindowType) assert 'WINDOW_TOPLEVEL' in repr(wtype)
def testGParam(self): win = gtk.Window() enums = filter(lambda x: GType.is_a(x.value_type, GEnum), gobject.list_properties(win)) self.assertTrue(enums) enum = enums[0] self.assertTrue(hasattr(enum, 'enum_class')) self.assertTrue(issubclass(enum.enum_class, GEnum))
def testWindowGetState(self): win = gtk.Window() win.realize() state = win.window.get_state() self.assertEquals(state, gtk.gdk.WINDOW_STATE_WITHDRAWN) self.assertTrue(isinstance(state, gtk.gdk.WindowState)) self.assertTrue('WINDOW_STATE_WITHDRAWN' in repr(state))
def testWindowGetState(self): win = gtk.Window() win.realize() state = win.window.get_state() assert state == gdk.WINDOW_STATE_WITHDRAWN assert isinstance(state, gdk.WindowState) assert 'WINDOW_STATE_WITHDRAWN' in repr(state)
def testWindow(self): self.failUnless(hasattr(gtk, 'Window')) self.failUnless(issubclass(gtk.Window, gobject.GObject)) self.failUnless(issubclass(gtk.Window, gtk.Object)) self.failUnless(issubclass(gtk.Window, gtk.Widget)) self.failUnless(issubclass(gtk.Window, gtk.Container)) self.failUnless(issubclass(gtk.Window, gtk.Bin)) w = gtk.Window() self.failUnless(isinstance(w, gtk.Window))
def testGParam(self): win = gtk.Window() enums = filter( lambda x: gobject.type_is_a(x.value_type, gobject.GEnum), gobject.list_properties(win)) assert enums enum = enums[0] assert hasattr(enum, 'enum_class') assert issubclass(enum.enum_class, gobject.GEnum)
def build_gui(self): # Create the toplevel window window = gtk.Window() vbox = gtk.VBox() window.add(vbox) # Create a UIManager instance uimanager = gtk.UIManager() self.uimanager = uimanager # Create the base ActionGroup actiongroup = gtk.ActionGroup('UIMergeExampleBase') actiongroup.add_actions([('File', None, '_File'), ('Sound', None, '_Sound'), ('RadioBand', None, '_Radio Band')]) uimanager.insert_action_group(actiongroup, 0) # Create an ActionGroup actiongroup0 = gtk.ActionGroup('UIMergeExample0') # Create a ToggleAction, etc. actiongroup0.add_toggle_actions([('Mute', None, '_Mute', '<Control>m', 'Mute the volume', self.cb)]) # Create actions actiongroup0.add_actions([('Quit', gtk.STOCK_QUIT, '_Quit me!', None, 'Quit the Program', self.cb)]) # Create some RadioActions actiongroup0.add_radio_actions([ ('AM', None, '_AM', '<Control>a', 'AM Radio', 0), ('FM', None, '_FM', '<Control>f', 'FM Radio', 1), ('SSB', None, '_SSB', '<Control>b', 'SSB Radio', 2), ], 0, self.cb) # Add the actiongroup to the uimanager uimanager.insert_action_group(actiongroup0, 1) self.ag0 = actiongroup0 del actiongroup0 # Add a UI description self.merge_id0 = uimanager.add_ui_from_string(self.ui0) # Create a MenuBar menubar = uimanager.get_widget('/MenuBar') vbox.pack_start(menubar, False) # Create a Toolbar toolbar = uimanager.get_widget('/Toolbar') vbox.pack_start(toolbar, False) gobject.timeout_add(50, self.timeout_cb) gtk.main() return
def testListAccelClosures(self): group = gtk.AccelGroup() window = gtk.Window() window.add_accel_group(group) button = gtk.Button() window.add(button) button.add_accelerator("clicked", group, gtk.keysyms.x, gtk.gdk.CONTROL_MASK, 0) for closure in button.list_accel_closures(): group1 = gtk.accel_group_from_accel_closure(closure) self.assert_(group1 is group) window.destroy()
def setUp(self): win = gtk.Window() win.realize() self.window = win.window self.bg_pixmap = win.style.bg_pixmap
def show_composite_main_window(): window = gtk.Window(gtk.WindowType.TOPLEVEL) #window = gtk.Window() window.set_title("Something") window.connect("destroy", gtk.main_quit) window.set_default_size(1200, 800) headerbar = gtk.HeaderBar() headerbar.set_show_close_button(True) window.set_titlebar(headerbar) scrolled_window = gtk.ScrolledWindow() show_web_inspector = False webview = WebKit2.WebView() #webview.get_settings().set_allow_file_access_from_file_urls(True) webview.get_settings().set_enable_developer_extras(True) #if (show_web_inspector): # webview.get_settings().set_enable_developer_extras(True) #webview.open("https://www.gnome.org/") app_functions_file = os.path.join(ROOT_DIR, "frontend", "app.functions.js") with open(app_functions_file) as f: contents = f.read() webview.get_user_content_manager().add_script( WebKit2.UserScript.new(contents, 0, 1, None, None)) app_functions_file = os.path.join(ROOT_DIR, "frontend", "timings_summary.functions.js") with open(app_functions_file) as f: contents = f.read() webview.get_user_content_manager().add_script( WebKit2.UserScript.new(contents, 0, 1, None, None)) app_functions_file = os.path.join(ROOT_DIR, "frontend", "composite_main_window", "composite_main_window.my.js") with open(app_functions_file) as f: contents = f.read() webview.get_user_content_manager().add_script( WebKit2.UserScript.new(contents, 0, 1, None, None)) app_functions_file = os.path.join(ROOT_DIR, "frontend", "composite_main_window", "composite_main_window.functions.js") with open(app_functions_file) as f: contents = f.read() webview.get_user_content_manager().add_script( WebKit2.UserScript.new(contents, 0, 1, None, None)) app_styles_file = os.path.join(ROOT_DIR, "frontend", "composite_main_window", "composite_main_window.styles.css") with open(app_styles_file) as f: contents = f.read() webview.get_user_content_manager().add_style_sheet( WebKit2.UserStyleSheet.new(contents, 0, 0, None, None)) page_communicator = PageCommunicator(webview) app_state = WindowAppState(page_communicator) def load_changed_handler(a_webview, load_event): if load_event == WebKit2.LoadEvent.FINISHED: app_state.page_loaded() webview.connect("load_changed", load_changed_handler) webview.get_user_content_manager().connect( "script-message-received::foobar", lambda userContentManager, value: page_communicator.handleScriptMessage(value)) webview.get_user_content_manager().register_script_message_handler( "foobar") webview.get_user_content_manager().connect( "script-message-received::timings_summary_msgs", lambda userContentManager, value: page_communicator. handleScriptMessage(value)) webview.get_user_content_manager().register_script_message_handler( "timings_summary_msgs") def webview_key_press_handler(a_webview, eve): keyval = eve.keyval keyval_name = Gdk.keyval_name(keyval) print("webview_key_press_handler. keyval: " + keyval_name) if keyval_name == "Escape": if not window.emit("delete-event", Gdk.Event( Gdk.EventType.DELETE)): window.destroy() return True if keyval_name == "f": if app_state.is_fullscreen: window.unfullscreen() else: window.fullscreen() app_state.is_fullscreen = not app_state.is_fullscreen return True #if keyval_name == "n": # Gdk.notify_startup_complete() # return True if keyval_name == "w": msg = {"type": "key_pressed", "keyval": keyval_name} page_communicator.send_json(json.dumps(msg)) return True if (keyval_name == "J" or keyval_name == "j") and ( eve.state & Gdk.ModifierType.SHIFT_MASK != 0) and (eve.state & Gdk.ModifierType.CONTROL_MASK != 0): webview.get_inspector().show() webview.connect("key_press_event", webview_key_press_handler) def webview_button_press_handler(a_webview, eve): if eve.type == Gdk.EventType.DOUBLE_BUTTON_PRESS: if app_state.is_fullscreen: window.unfullscreen() else: window.fullscreen() app_state.is_fullscreen = not app_state.is_fullscreen return True webview.connect("button_press_event", webview_button_press_handler) config_file = os.path.join(ROOT_DIR, "indic.config.txt") with open(config_file) as f: contents = f.read().rstrip() #print("config contents: {}".format(contents)) config = json2config(contents) app_state.config = config page_communicator.config_loaded(config) processes_info = parse_processes_file(config.processes_filepath) timings_contents = read_timings(config) composed_info = { "processes": processes_info, "timings": timings_contents } #await page_communicator.load_finished_event.wait() app_state.after_page_loaded( lambda: page_communicator.send_json(json.dumps(composed_info))) wallpapers_dir = os.path.join(ROOT_DIR, "wallpapers") wallpapers = os.listdir(wallpapers_dir) print("wallpapers: {}".format(wallpapers)) wallpapers_msg = {"type": "wallpapers", "wallpapers": wallpapers} app_state.after_page_loaded( lambda: page_communicator.send_json(json.dumps(wallpapers_msg))) app_html_file = os.path.join(ROOT_DIR, "frontend", "composite_main_window", "composite_main_window.html") with open(app_html_file) as f: from urllib.parse import urljoin from urllib.request import pathname2url base_uri = urljoin('file:', pathname2url(ROOT_DIR)) + "/" webview.load_html(f.read(), base_uri) #if (show_web_inspector): # webview.get_inspector().show() scrolled_window.add(webview) window.add(scrolled_window) #window.set_keep_above(True) window.show_all() #app_state.after_page_loaded(lambda : window.set_keep_above(False)) gtk.main()
def show_timings_history_latest(): window = gtk.Window() window.set_title("Something") window.connect("destroy", gtk.main_quit) window.set_default_size(800, 900) window.set_position(gtk.WindowPosition.CENTER) headerbar = gtk.HeaderBar() headerbar.set_show_close_button(True) window.set_titlebar(headerbar) scrolled_window = gtk.ScrolledWindow() show_web_inspector = False webview = WebKit2.WebView() if (show_web_inspector): webview.get_settings().set_enable_developer_extras(True) app_functions_file = os.path.join(ROOT_DIR, "frontend", "timings_history", "latest.functions.js") with open(app_functions_file) as f: contents = f.read() webview.get_user_content_manager().add_script( WebKit2.UserScript.new(contents, 0, 1, None, None)) app_styles_file = os.path.join(ROOT_DIR, "frontend", "timings_history", "latest.styles.css") with open(app_styles_file) as f: contents = f.read() webview.get_user_content_manager().add_style_sheet( WebKit2.UserStyleSheet.new(contents, 0, 0, None, None)) page_communicator = PageCommunicator(webview) app_state = WindowAppState(page_communicator) def load_changed_handler(a_webview, load_event): if load_event == WebKit2.LoadEvent.FINISHED: app_state.page_loaded() webview.connect("load_changed", load_changed_handler) webview.get_user_content_manager().connect( "script-message-received::timings_history_latest_msgs", lambda userContentManager, value: page_communicator. handleScriptMessage(value)) webview.get_user_content_manager().register_script_message_handler( "timings_history_latest_msgs") def webview_key_press_handler(a_webview, eve): keyval = eve.keyval keyval_name = Gdk.keyval_name(keyval) print("webview_key_press_handler. keyval: " + keyval_name) if keyval_name == "Escape": if not window.emit("delete-event", Gdk.Event( Gdk.EventType.DELETE)): window.destroy() return True if keyval_name == "Left": page_communicator.send_json( "{\"msg_type\": \"keypress_event\", \"keyval\": \"Left\"}") return True elif keyval_name == "Right": page_communicator.send_json( "{\"msg_type\": \"keypress_event\", \"keyval\": \"Right\"}") return True elif keyval_name == "f": if app_state.is_fullscreen: window.unfullscreen() else: window.fullscreen() app_state.is_fullscreen = not app_state.is_fullscreen return True webview.connect("key_press_event", webview_key_press_handler) def webview_button_press_handler(a_webview, eve): if eve.type == Gdk.EventType.DOUBLE_BUTTON_PRESS: if app_state.is_fullscreen: window.unfullscreen() else: window.fullscreen() app_state.is_fullscreen = not app_state.is_fullscreen return True webview.connect("button_press_event", webview_button_press_handler) config_file = os.path.join(ROOT_DIR, "indic.config.txt") with open(config_file) as f: contents = f.read().rstrip() print("config contents: {}".format(contents)) config = json2config(contents) app_state.config = config page_communicator.config_loaded(config) timings_contents = read_timings(config) app_state.after_page_loaded( lambda: page_communicator.send_json(json.dumps(timings_contents))) app_html_file = os.path.join(ROOT_DIR, "frontend", "timings_history", "latest.html") with open(app_html_file) as f: base_uri = "file:///" webview.load_html(f.read(), base_uri) if (show_web_inspector): webview.get_inspector().show() scrolled_window.add(webview) window.add(scrolled_window) window.show_all() gtk.main()