python SITCON 2018中使用的PyGObject示例。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python SITCON 2018中使用的PyGObject示例。相关的知识,希望对你有一定的参考价值。

import sys
import threading
import time

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GLib

class BackgroundThread(threading.Thread):
    def __init__(self, app):
        super().__init__(target=self.counter)
        self.daemon = True

    def counter(self):
        cnt = 0
        while True:
            if app.window:
                GLib.idle_add(app.window.set_title, (str(cnt)))
            cnt += 1
            time.sleep(0.1)


class Application(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.window = None

    def do_startup(self, *args):
        Gtk.Application.do_startup(self)
        self.connect('activate', self.my_activate)

    def my_activate(self, *args):
        window = Gtk.ApplicationWindow(application=self)
        window.set_title('Window')
        window.set_default_size(200, 200)
        window.present()

        self.window = window


if __name__ == '__main__':
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app = Application(application_id='org.gtk.example-py-thread',
                      flags=Gio.ApplicationFlags.FLAGS_NONE)

    thr = BackgroundThread(app)
    thr.start()
    app.run(sys.argv)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.2 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkApplicationWindow" id="app_window">
    <property name="can_focus">False</property>
    <property name="default_width">440</property>
    <property name="default_height">250</property>
    <child>
      <object class="GtkButton">
        <property name="label" translatable="yes">Just a button owo</property>
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <signal name="clicked" handler="onButtonClick" swapped="no"/>
      </object>
    </child>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio

class Application(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.builder = None

    def do_startup(self, *args):
        Gtk.Application.do_startup(self)

        builder = Gtk.Builder()
        builder.add_from_file('01a-ui.glade')
        builder.connect_signals(self)
        self.builder = builder

    def do_activate(self, *args):
        window = self.builder.get_object('app_window')
        self.add_window(window)
        window.show()

    def onButtonClick(self, *args):
        print('owo')


if __name__ == '__main__':
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app = Application(application_id='org.gtk.example-py-glade',
                      flags=Gio.ApplicationFlags.FLAGS_NONE)
    app.run(sys.argv)
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio

class Application(Gtk.Application):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.window = None

    def do_startup(self, *args):
        Gtk.Application.do_startup(self)
        self.connect('activate', self.my_activate)

    def my_activate(self, *args):
        window = Gtk.ApplicationWindow(application=self)
        window.set_title('Window')
        window.set_default_size(200, 200)
        window.present()


if __name__ == '__main__':
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    app = Application(application_id='org.gtk.example-py',
                      flags=Gio.ApplicationFlags.FLAGS_NONE)
    app.run(sys.argv)

以上是关于python SITCON 2018中使用的PyGObject示例。的主要内容,如果未能解决你的问题,请参考以下文章

图机器学习 | PyG 安装配置记录

图机器学习 | PyG 安装配置记录

有关kaggle中更新cuda与pytorch的版本,并安装pyg

PyTorch+PyG实现图神经网络经典模型目录

PyG基于Node2Vec实现节点分类及其可视化

pyg安装——ERROR: Failed building wheel for torch-sparse