Fix #1785 (Calibre exits when closing preference window on OS X)

This commit is contained in:
Kovid Goyal 2009-02-06 17:31:40 -08:00
parent edae7237d9
commit 4ecec00044

View File

@ -115,16 +115,11 @@ class Main(MainWindow, Ui_MainWindow):
self.connect(self.donate_action, SIGNAL('triggered(bool)'), self.donate)
self.connect(self.restore_action, SIGNAL('triggered(bool)'), lambda c : self.show())
self.connect(self.action_show_book_details, SIGNAL('triggered(bool)'), self.show_book_info)
def restart_app(c):
self.quit(None, restart=True)
self.connect(self.action_restart, SIGNAL('triggered(bool)'), restart_app)
def sta(r):
if r == QSystemTrayIcon.Trigger:
self.hide() if self.isVisible() else self.show()
self.connect(self.system_tray_icon, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), sta)
def tcme(self, *args):
pass
self.tool_bar.contextMenuEvent = tcme
self.connect(self.action_restart, SIGNAL('triggered(bool)'),
lambda c : self.quit(None, restart=True))
self.connect(self.system_tray_icon, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'),
self.system_tray_icon_activated)
self.tool_bar.contextMenuEvent = self.no_op
####################### Location View ########################
QObject.connect(self.location_view, SIGNAL('location_selected(PyQt_PyObject)'),
self.location_selected)
@ -165,15 +160,11 @@ class Main(MainWindow, Ui_MainWindow):
sm.addSeparator()
sm.addAction(_('Send to storage card by default'))
sm.actions()[-1].setCheckable(True)
def default_sync(checked):
config.set('send_to_storage_card_by_default', bool(checked))
QObject.disconnect(self.action_sync, SIGNAL("triggered(bool)"), self.sync_to_main_memory)
QObject.disconnect(self.action_sync, SIGNAL("triggered(bool)"), self.sync_to_card)
QObject.connect(self.action_sync, SIGNAL("triggered(bool)"), self.sync_to_card if checked else self.sync_to_main_memory)
QObject.connect(sm.actions()[-1], SIGNAL('toggled(bool)'), default_sync)
QObject.connect(sm.actions()[-1], SIGNAL('toggled(bool)'),
self.do_default_sync)
sm.actions()[-1].setChecked(config.get('send_to_storage_card_by_default'))
default_sync(sm.actions()[-1].isChecked())
self.do_default_sync(sm.actions()[-1].isChecked())
self.sync_menu = sm # Needed
md = QMenu()
md.addAction(_('Edit metadata individually'))
@ -371,6 +362,31 @@ class Main(MainWindow, Ui_MainWindow):
self.connect(self.action_news, SIGNAL('triggered(bool)'), self.scheduler.show_dialog)
self.location_view.setCurrentIndex(self.location_view.model().index(0))
def no_op(self, *args):
pass
def system_tray_icon_activated(self, r):
if r == QSystemTrayIcon.Trigger:
if self.isVisible():
for window in QApplication.topLevelWidgets():
if isinstance(window, (MainWindow, QDialog)):
window.hide()
else:
for window in QApplication.topLevelWidgets():
if isinstance(window, (MainWindow, QDialog)):
if window not in (self.device_error_dialog, self.jobs_dialog):
window.show()
def do_default_sync(self, checked):
config.set('send_to_storage_card_by_default', bool(checked))
QObject.disconnect(self.action_sync, SIGNAL("triggered(bool)"),
self.sync_to_main_memory)
QObject.disconnect(self.action_sync, SIGNAL("triggered(bool)"),
self.sync_to_card)
QObject.connect(self.action_sync, SIGNAL("triggered(bool)"),
self.sync_to_card if checked else self.sync_to_main_memory)
def change_output_format(self, x):
of = unicode(x).strip()
if of != prefs['output_format']: