Force shutdown, fix cx_Freeze startup
This commit is contained in:
parent
9fb8e67164
commit
aaf80f4e2d
77
FAHControl
77
FAHControl
@ -36,47 +36,46 @@ def set_proc_name(name):
|
|||||||
libc.prctl(15, byref(buff), 0, 0, 0)
|
libc.prctl(15, byref(buff), 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if sys.platform.startswith('linux'): set_proc_name('FAHControl')
|
||||||
if sys.platform.startswith('linux'): set_proc_name('FAHControl')
|
|
||||||
|
|
||||||
# If present, remove the Launch Services -psn_xxx_xxx argument
|
# If present, remove the Launch Services -psn_xxx_xxx argument
|
||||||
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
|
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
|
||||||
del sys.argv[1]
|
del sys.argv[1]
|
||||||
|
|
||||||
parser = OptionParser(usage = 'Usage: %prog [options]')
|
parser = OptionParser(usage = 'Usage: %prog [options]')
|
||||||
|
|
||||||
parser.add_option('--exit', help = 'Tell the running application to exit',
|
parser.add_option('--exit', help = 'Tell the running application to exit',
|
||||||
action = 'store_true', dest = 'exit')
|
action = 'store_true', dest = 'exit')
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
# Tell app to exit
|
|
||||||
if options.exit:
|
|
||||||
try:
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
sock.connect(single_app_addr)
|
|
||||||
sock.send('EXIT')
|
|
||||||
if sock.recv(1024).strip() == 'OK': print 'Ok'
|
|
||||||
except Exception, e: pass
|
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
# Add executable path to PATH
|
|
||||||
if getattr(sys, 'frozen', False): path = os.path.dirname(sys.executable)
|
|
||||||
else: path = os.path.dirname(__file__)
|
|
||||||
path = os.path.realpath(path)
|
|
||||||
os.environ['PATH'] = path + os.pathsep + os.environ['PATH']
|
|
||||||
|
|
||||||
# Load Glade
|
|
||||||
dir = os.path.dirname(inspect.getfile(inspect.currentframe()))
|
|
||||||
if not dir: dir = '.'
|
|
||||||
glade = dir + '/fah/FAHControl.glade'
|
|
||||||
|
|
||||||
if os.path.exists(glade): app = FAHControl(glade)
|
|
||||||
else:
|
|
||||||
from fah.FAHControl_glade import glade_data
|
|
||||||
app = FAHControl(glade_data)
|
|
||||||
|
|
||||||
|
# Tell app to exit
|
||||||
|
if options.exit:
|
||||||
try:
|
try:
|
||||||
app.run()
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
except Exception, e:
|
sock.connect(single_app_addr)
|
||||||
print e
|
sock.send('EXIT')
|
||||||
|
if sock.recv(1024).strip() == 'OK': print 'Ok'
|
||||||
|
except Exception, e: pass
|
||||||
|
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Add executable path to PATH
|
||||||
|
if getattr(sys, 'frozen', False): path = os.path.dirname(sys.executable)
|
||||||
|
else: path = os.path.dirname(__file__)
|
||||||
|
path = os.path.realpath(path)
|
||||||
|
os.environ['PATH'] = path + os.pathsep + os.environ['PATH']
|
||||||
|
|
||||||
|
# Load Glade
|
||||||
|
dir = os.path.dirname(inspect.getfile(inspect.currentframe()))
|
||||||
|
if not dir: dir = '.'
|
||||||
|
glade = dir + '/fah/FAHControl.glade'
|
||||||
|
|
||||||
|
if os.path.exists(glade): app = FAHControl(glade)
|
||||||
|
else:
|
||||||
|
from fah.FAHControl_glade import glade_data
|
||||||
|
app = FAHControl(glade_data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
app.run()
|
||||||
|
except Exception, e:
|
||||||
|
print e
|
||||||
|
@ -534,10 +534,10 @@ class FAHControl(SingleAppServer):
|
|||||||
self.window_accel_group = ag
|
self.window_accel_group = ag
|
||||||
key, mod = gtk.accelerator_parse("<meta>w")
|
key, mod = gtk.accelerator_parse("<meta>w")
|
||||||
ag.connect_group(key, mod, gtk.ACCEL_VISIBLE,
|
ag.connect_group(key, mod, gtk.ACCEL_VISIBLE,
|
||||||
osx_accel_window_close)
|
osx_accel_window_close)
|
||||||
key, mod = gtk.accelerator_parse("<meta>m")
|
key, mod = gtk.accelerator_parse("<meta>m")
|
||||||
ag.connect_group(key, mod, gtk.ACCEL_VISIBLE,
|
ag.connect_group(key, mod, gtk.ACCEL_VISIBLE,
|
||||||
osx_accel_window_minimize)
|
osx_accel_window_minimize)
|
||||||
self.window.add_accel_group(ag)
|
self.window.add_accel_group(ag)
|
||||||
except Exception, e: print e
|
except Exception, e: print e
|
||||||
|
|
||||||
@ -710,7 +710,7 @@ class FAHControl(SingleAppServer):
|
|||||||
self.db.flush_queued()
|
self.db.flush_queued()
|
||||||
except Exception, e: print e
|
except Exception, e: print e
|
||||||
|
|
||||||
self.shutdown() # Shutdown SingleAppServer
|
sys.exit(0) # Force shutdown
|
||||||
|
|
||||||
|
|
||||||
def set_status(self, text):
|
def set_status(self, text):
|
||||||
|
@ -58,9 +58,9 @@ class SingleAppServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
|
|||||||
self, single_app_addr, SingleAppRequestHandler)
|
self, single_app_addr, SingleAppRequestHandler)
|
||||||
|
|
||||||
thread = threading.Thread(target = self.serve_forever)
|
thread = threading.Thread(target = self.serve_forever)
|
||||||
# Exit the server thread when the main thread terminates
|
# Exit the server thread when the main thread terminates
|
||||||
thread.setDaemon(True)
|
thread.setDaemon(True)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
def check_for_instance(self):
|
def check_for_instance(self):
|
||||||
|
1
setup.py
1
setup.py
@ -67,6 +67,7 @@ if sys.platform == 'darwin':
|
|||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
from cx_Freeze import setup, Executable
|
from cx_Freeze import setup, Executable
|
||||||
|
|
||||||
|
# Change base to 'Console' for debugging
|
||||||
e = Executable(app, base = 'Win32GUI', icon = 'images/FAHControl.ico')
|
e = Executable(app, base = 'Win32GUI', icon = 'images/FAHControl.ico')
|
||||||
options = {
|
options = {
|
||||||
'build_exe': {
|
'build_exe': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user