我在这里看到过类似的问题,但没有得到答案。也许是因为我不熟悉这一切,只是不了解。我希望我的应用程序主要用作指标。如果用户再次启动它,它将检查它是否已经在运行,如果已运行,则将所有输入数据提供给该进程并退出。
我正在尝试使用Quickly创建此文件。因此,如果您可以给我一些python示例或链接到类似的东西,那将是很好的。
我发现我确实需要DBus来实现我所需要的。所以这是我实际需要做的:
# using quickly...
#
# __init__.py
# # # # # # # # # # # # #
import dbus
import sys
from gi.repository import Gtk
# import whatever else you need...
from my_app import MyAppDBusService
# import whatever else from your app...
def main():
bus = dbus.SessionBus()
# Check if my app is running and providing DBus service
if bus.name_has_owner('com.example.myApp'):
#if it is running pass the commandline variables to it and exit
#get my service from DBus
myService = bus.get_object('com.example.myApp', '/com/example/myApp')
#get offered method from DBus
myMethod = myService.get_dbus_method('my_method', 'com.example.myApp')
#call the method and pass comandline varialbes
myMethod(sys.argv)
#exit
sys.exit(0)
else:
#if not running
#run my DBus service by creating MyAppDBusService instance
MyAppDBusService.MyAppDBusService()
#do whatever with sys.argv...
#...
Gtk.main()
# MyAppDBusService.py
# # # # # # # # # # # # # #
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
#import whatever else you need...
# use the dbus mainloop
DBusGMainLoop(set_as_default = True)
class MyAppDBusService(dbus.service.Object):
def __init__(self):
# create dbus service in the SessionBus()
dbus_name = dbus.service.BusName('com.example.myApp', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, dbus_name, '/com/example/myApp')
# offer a method to call using my dbus service
@dbus.service.method('com.example.myApp')
def my_method(self, argv):
#do whatever with argv...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句