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.
calculate-utils-3-console-gui/scripts/cl-console-gui

106 lines
3.4 KiB

#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys, os, pwd
from PySide import QtGui
from calculate.consolegui.application.more import getRunProc, owner, _print
import __builtin__
import dbus
import dbus.mainloop.glib
reload(sys)
sys.setdefaultencoding("utf-8")
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('console_gui',sys.modules[__name__])
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
#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)
def main():
from calculate.consolegui.application.ConnectionTabs import ToolTabWidget,\
DBusWidget, parse, SelectedMethodWgt
__builtin__.__dict__['_print'] = _print
host, port, args = None, None, None
if len(sys.argv) > 1:
parser = parse()
args = parser.parse_args()
if args.help:
parser.print_help()
sys.exit(0)
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 (_('The user must not be 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()