You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.7 KiB
85 lines
2.7 KiB
#!/usr/bin/python
|
|
#-*- coding: utf-8 -*-
|
|
|
|
import sys, os, pwd
|
|
from PySide import QtGui
|
|
|
|
from calculate.consolegui.application.ConnectionTabs import ToolTabWidget, \
|
|
DBusWidget, parse, SelectedMethodWgt
|
|
from calculate.consolegui.application.more import getRunProc, owner, _print
|
|
import __builtin__
|
|
import dbus
|
|
import dbus.mainloop.glib
|
|
reload(sys)
|
|
sys.setdefaultencoding("utf-8")
|
|
|
|
def main():
|
|
__builtin__.__dict__['_print'] = _print
|
|
host, port, args = None, None, None
|
|
if len(sys.argv) > 1:
|
|
args = parse()
|
|
if args.method:
|
|
app = QtGui.QApplication(sys.argv)
|
|
app.setQuitOnLastWindowClosed(True)
|
|
ex = SelectedMethodWgt(app, args)
|
|
sys.exit(app.exec_())
|
|
if args.host:
|
|
host = args.host
|
|
if args.port:
|
|
port = args.port
|
|
|
|
# Enable glib main loop support
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
# Get the session bus
|
|
try:
|
|
bus = dbus.SessionBus()
|
|
except dbus.exceptions.DBusException, e:
|
|
bus = None
|
|
if not os.getuid():
|
|
_print (_('User should be not root'))
|
|
else:
|
|
print e
|
|
sys.exit(1)
|
|
|
|
iface = None
|
|
try:
|
|
# Get the remote object
|
|
remote_object = bus.get_object("org.calculate.consolegui",
|
|
"/org/calculate/consolegui")
|
|
# Get the remote interface for the remote object
|
|
iface = dbus.Interface(remote_object, "org.calculate.consolegui")
|
|
except dbus.DBusException:
|
|
pass
|
|
|
|
app = QtGui.QApplication(sys.argv)
|
|
|
|
second = False
|
|
for run_commands in filter(lambda x:'cl-console-gui' in x[0],getRunProc()):
|
|
if 'python' in run_commands[0]:
|
|
if not '--method' in run_commands[0] and pwd.getpwuid(os.getuid())\
|
|
.pw_name == owner(run_commands[1]):
|
|
if second:
|
|
print 'Client already running'
|
|
if iface:
|
|
# Call some methods of the remote interface
|
|
iface.show()
|
|
sys.exit(0)
|
|
else:
|
|
second = True
|
|
|
|
# Do not complete the program then last window is closed
|
|
app.setQuitOnLastWindowClosed(False)
|
|
|
|
ex = ToolTabWidget(app, args = args, host = host, port = port)
|
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
session_bus = dbus.SessionBus()
|
|
# Export the service
|
|
name = dbus.service.BusName("org.calculate.consolegui", session_bus)
|
|
# Export the object
|
|
widget = DBusWidget(session_bus, '/org/calculate/consolegui', ex)
|
|
sys.exit(app.exec_())
|
|
|
|
if __name__=='__main__':
|
|
main() |