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.
117 lines
3.8 KiB
117 lines
3.8 KiB
12 years ago
|
#!/usr/bin/env python2
|
||
13 years ago
|
#-*- coding: utf-8 -*-
|
||
13 years ago
|
|
||
12 years ago
|
import sys, os, pwd
|
||
12 years ago
|
from PySide import QtGui
|
||
12 years ago
|
|
||
12 years ago
|
from calculate.consolegui.application.more import getRunProc, owner, _print
|
||
|
import __builtin__
|
||
12 years ago
|
import dbus
|
||
|
import dbus.mainloop.glib
|
||
12 years ago
|
reload(sys)
|
||
|
sys.setdefaultencoding("utf-8")
|
||
12 years ago
|
from calculate.lib.cl_lang import setLocalTranslate
|
||
|
setLocalTranslate('console_gui',sys.modules[__name__])
|
||
12 years ago
|
|
||
12 years ago
|
import signal
|
||
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||
12 years ago
|
|
||
12 years ago
|
#KeyboardInterrupt
|
||
|
#def sigint_handler(*args):
|
||
|
# """Handler for the SIGINT signal."""
|
||
|
# sys.stderr.write('\r')
|
||
|
# from PySide.QtGui import QMessageBox
|
||
|
# if QMessageBox.question(None, '', "Are you sure you want to quit?",
|
||
|
# QMessageBox.Yes | QMessageBox.No,
|
||
|
# QMessageBox.No) == QMessageBox.Yes:
|
||
|
# QtGui.QApplication.quit()
|
||
|
#signal.signal(signal.SIGINT, sigint_handler)
|
||
12 years ago
|
|
||
12 years ago
|
def main():
|
||
10 years ago
|
from calculate.consolegui.application.ConnectionTabs import (ToolTabWidget,
|
||
|
parse, SelectedMethodWgt)
|
||
|
from calculate.consolegui.application.dbus_service import (DBUS_MAINAPP,
|
||
|
DBUS_NAME, DBUS_METHOD_APP, DBusWidget, dbus_updater_hide_tray)
|
||
12 years ago
|
__builtin__.__dict__['_print'] = _print
|
||
|
host, port, args = None, None, None
|
||
|
if len(sys.argv) > 1:
|
||
12 years ago
|
parser = parse()
|
||
|
args = parser.parse_args()
|
||
|
if args.help:
|
||
|
parser.print_help()
|
||
|
sys.exit(0)
|
||
12 years ago
|
if args.method:
|
||
|
app = QtGui.QApplication(sys.argv)
|
||
12 years ago
|
app.setQuitOnLastWindowClosed(True)
|
||
12 years ago
|
ex = SelectedMethodWgt(app, args)
|
||
10 years ago
|
if args.method == 'update':
|
||
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||
|
session_bus = dbus.SessionBus()
|
||
|
# Export the service
|
||
|
name = dbus.service.BusName(DBUS_NAME, session_bus)
|
||
|
# Export the object
|
||
|
widget = DBusWidget(session_bus, DBUS_METHOD_APP % args.method,
|
||
|
ex)
|
||
12 years ago
|
sys.exit(app.exec_())
|
||
|
if args.host:
|
||
|
host = args.host
|
||
|
if args.port:
|
||
|
port = args.port
|
||
12 years ago
|
|
||
|
# Enable glib main loop support
|
||
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||
|
# Get the session bus
|
||
12 years ago
|
try:
|
||
|
bus = dbus.SessionBus()
|
||
|
except dbus.exceptions.DBusException, e:
|
||
|
bus = None
|
||
|
if not os.getuid():
|
||
12 years ago
|
_print (_('The user must not be root'))
|
||
12 years ago
|
else:
|
||
|
print e
|
||
|
sys.exit(1)
|
||
12 years ago
|
|
||
|
iface = None
|
||
|
try:
|
||
|
# Get the remote object
|
||
10 years ago
|
remote_object = bus.get_object(DBUS_NAME, DBUS_MAINAPP)
|
||
12 years ago
|
# Get the remote interface for the remote object
|
||
10 years ago
|
iface = dbus.Interface(remote_object, DBUS_NAME)
|
||
12 years ago
|
except dbus.DBusException:
|
||
|
pass
|
||
|
|
||
12 years ago
|
app = QtGui.QApplication(sys.argv)
|
||
12 years ago
|
|
||
12 years ago
|
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'
|
||
12 years ago
|
if iface:
|
||
|
# Call some methods of the remote interface
|
||
|
iface.show()
|
||
12 years ago
|
sys.exit(0)
|
||
|
else:
|
||
|
second = True
|
||
12 years ago
|
|
||
12 years ago
|
# Do not complete the program then last window is closed
|
||
10 years ago
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||
|
|
||
|
session_bus = dbus.SessionBus()
|
||
|
dbus_updater_hide_tray(session_bus)
|
||
|
|
||
12 years ago
|
app.setQuitOnLastWindowClosed(False)
|
||
12 years ago
|
|
||
12 years ago
|
ex = ToolTabWidget(app, args = args, host = host, port = port)
|
||
12 years ago
|
|
||
|
# Export the service
|
||
10 years ago
|
name = dbus.service.BusName(DBUS_NAME, session_bus)
|
||
12 years ago
|
# Export the object
|
||
10 years ago
|
widget = DBusWidget(session_bus, DBUS_MAINAPP, ex)
|
||
12 years ago
|
sys.exit(app.exec_())
|
||
|
|
||
|
if __name__=='__main__':
|
||
12 years ago
|
main()
|