コード例 #1
0
    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
コード例 #2
0
ファイル: indic.py プロジェクト: shiraeeshi/shiraeeshi-timing
def main():
    indicator = appindicator.Indicator.new("customtray", "clock-icon", appindicator.IndicatorCategory.APPLICATION_STATUS)
    indicEnv = IndicEnv(indicator);
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
    #menu = await create_menu(indicEnv)
    menu = create_menu(indicEnv)
    indicator.set_menu(menu)
    gtk.main()
コード例 #3
0
    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
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
ファイル: test_glade.py プロジェクト: NikolenkoAV2020/Selena
 def testAutoconnectLeak(self):
     self.SimpleTest(self)
     gtk.main()
     self.assertEqual(self.windowref(), None)