Python with GTK+3 で application_id の使い道。
どうやら Windows API の SendMessage みたいになことができるようだ。
LibUnique/Example – GNOME Live!
libunique を Python で使う方法は解らない…
色々探してみてこんなのを見つける。
Migrating from libunique to GApplication or GtkApplication
なんか GtkApplication や GtkWindow から直接送受信できそうだ。
でもコレって継承した GtkWindow の自作関数なんかも利用できるのかな。
試してみる、GList から Window を得るには添字でイケるようだ。
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from gi.repository import Gtk, Gio
class Win(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("sendmessage")
self.set_border_width(24)
self.label = Gtk.Label("Hello World")
self.add(self.label)
self.show_all()
def append_text(self, text):
s = self.label.get_text()
self.label.set_text("{0}\n{1}".format(s, text))
class App(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(
self,
application_id="apps.test.helloworld",
flags=Gio.ApplicationFlags.FLAGS_NONE)
self.connect("activate", self.on_activate)
def on_activate(self, data=None):
l = self.get_windows()
if l:
l[0].append_text("Hello World")
return
w = Win()
w.set_application(self)
if __name__ == "__main__":
app = App()
app.run(None)
起動中 Window の関数がそのまんま呼び出せる。
多重起動防止処理がこんなに簡単になっていたとは知らなかった。
