Merge branch 'master' of git://git.assembla.com/fpdb-gimick

This commit is contained in:
Worros 2010-06-25 16:22:38 +08:00
commit 06e5e5ec26
2 changed files with 39 additions and 17 deletions

View File

@ -30,10 +30,11 @@ import Configuration
class GuiPrefs: class GuiPrefs:
def __init__(self, config, mainwin, dia): def __init__(self, config, mainwin, dia, parentwin):
self.config = config self.config = config
self.main_window = mainwin self.main_window = mainwin
self.dialog = dia self.dialog = dia
self.parent_window = parentwin #need to pass reference of parent, to set transient
self.tree_box = gtk.ScrolledWindow() self.tree_box = gtk.ScrolledWindow()
self.tree_box.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.tree_box.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@ -120,7 +121,7 @@ class GuiPrefs:
name = tmodel.get_value( iter, 1 ) name = tmodel.get_value( iter, 1 )
val = tmodel.get_value( iter, 2 ) val = tmodel.get_value( iter, 2 )
dia_edit = gtk.Dialog(name, dia_edit = gtk.Dialog(name,
self.main_window, self.parent_window,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
@ -162,7 +163,8 @@ if __name__=="__main__":
(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
dia.set_default_size(700, 500) dia.set_default_size(700, 500)
prefs = GuiPrefs(config, win, dia.vbox) pw=dia #pass parent window
prefs = GuiPrefs(config, win, dia.vbox,pw)
response = dia.run() response = dia.run()
if response == gtk.RESPONSE_ACCEPT: if response == gtk.RESPONSE_ACCEPT:
# save updated config # save updated config

View File

@ -276,7 +276,7 @@ class fpdb:
gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT)) gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT))
dia.set_default_size(700, 500) dia.set_default_size(700, 500)
prefs = GuiPrefs.GuiPrefs(self.config, self.window, dia.vbox) prefs = GuiPrefs.GuiPrefs(self.config, self.window, dia.vbox, dia)
response = dia.run() response = dia.run()
if response == gtk.RESPONSE_ACCEPT: if response == gtk.RESPONSE_ACCEPT:
# save updated config # save updated config
@ -284,11 +284,13 @@ class fpdb:
if len(self.nb_tab_names) == 1: if len(self.nb_tab_names) == 1:
# only main tab open, reload profile # only main tab open, reload profile
self.load_profile() self.load_profile()
dia.destroy()
else: else:
dia.destroy() # destroy prefs before raising warning, otherwise parent is dia rather than self.window
self.warning_box("Updated preferences have not been loaded because " self.warning_box("Updated preferences have not been loaded because "
+ "windows are open. Re-start fpdb to load them.") + "windows are open. Re-start fpdb to load them.")
else:
dia.destroy() dia.destroy()
def dia_maintain_dbs(self, widget, data=None): def dia_maintain_dbs(self, widget, data=None):
self.warning_box("Unimplemented: Maintain Databases") self.warning_box("Unimplemented: Maintain Databases")
@ -394,11 +396,13 @@ class fpdb:
if self.obtain_global_lock(): # returns true if successful if self.obtain_global_lock(): # returns true if successful
#lock_released = False #lock_released = False
dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, dia_confirm = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_WARNING,
buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables") buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables")
diastring = "Please confirm that you want to (re-)create the tables. If there already are tables in the database " \ diastring = "Please confirm that you want to (re-)create the tables. If there already are tables in the database " \
+self.db.database+" on "+self.db.host+" they will be deleted." +self.db.database+" on "+self.db.host+" they will be deleted."
dia_confirm.format_secondary_text(diastring)#todo: make above string with bold for db, host and deleted dia_confirm.format_secondary_text(diastring)#todo: make above string with bold for db, host and deleted
# disable windowclose, do not want the the underlying processing interrupted mid-process
dia_confirm.set_deletable(False)
response = dia_confirm.run() response = dia_confirm.run()
dia_confirm.destroy() dia_confirm.destroy()
@ -414,7 +418,7 @@ class fpdb:
# for other dbs use same connection as holds global lock # for other dbs use same connection as holds global lock
# self.fdb_lock.fdb.recreate_tables() # self.fdb_lock.fdb.recreate_tables()
# TODO: figure out why this seems to be necessary # TODO: figure out why this seems to be necessary
dia_restart = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, dia_restart = gtk.MessageDialog(parent=self.window, flags=0, type=gtk.MESSAGE_WARNING,
buttons=(gtk.BUTTONS_OK), message_format="Restart fpdb") buttons=(gtk.BUTTONS_OK), message_format="Restart fpdb")
diastring = "You should now restart fpdb." diastring = "You should now restart fpdb."
dia_restart.format_secondary_text(diastring) dia_restart.format_secondary_text(diastring)
@ -428,9 +432,11 @@ class fpdb:
def dia_recreate_hudcache(self, widget, data=None): def dia_recreate_hudcache(self, widget, data=None):
if self.obtain_global_lock(): if self.obtain_global_lock():
self.dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache") self.dia_confirm = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache")
diastring = "Please confirm that you want to re-create the HUD cache." diastring = "Please confirm that you want to re-create the HUD cache."
self.dia_confirm.format_secondary_text(diastring) self.dia_confirm.format_secondary_text(diastring)
# disable windowclose, do not want the the underlying processing interrupted mid-process
self.dia_confirm.set_deletable(False)
hb1 = gtk.HBox(True, 1) hb1 = gtk.HBox(True, 1)
self.h_start_date = gtk.Entry(max=12) self.h_start_date = gtk.Entry(max=12)
@ -478,16 +484,19 @@ class fpdb:
def dia_rebuild_indexes(self, widget, data=None): def dia_rebuild_indexes(self, widget, data=None):
if self.obtain_global_lock(): if self.obtain_global_lock():
self.dia_confirm = gtk.MessageDialog(parent=None self.dia_confirm = gtk.MessageDialog(parent=self.window
,flags=0 ,flags=gtk.DIALOG_DESTROY_WITH_PARENT
,type=gtk.MESSAGE_WARNING ,type=gtk.MESSAGE_WARNING
,buttons=(gtk.BUTTONS_YES_NO) ,buttons=(gtk.BUTTONS_YES_NO)
,message_format="Confirm rebuilding database indexes") ,message_format="Confirm rebuilding database indexes")
diastring = "Please confirm that you want to rebuild the database indexes." diastring = "Please confirm that you want to rebuild the database indexes."
self.dia_confirm.format_secondary_text(diastring) self.dia_confirm.format_secondary_text(diastring)
# disable windowclose, do not want the the underlying processing interrupted mid-process
self.dia_confirm.set_deletable(False)
response = self.dia_confirm.run() response = self.dia_confirm.run()
if response == gtk.RESPONSE_YES: if response == gtk.RESPONSE_YES:
#FIXME these progress messages do not seem to work
lbl = gtk.Label(" Rebuilding Indexes ... ") lbl = gtk.Label(" Rebuilding Indexes ... ")
self.dia_confirm.vbox.add(lbl) self.dia_confirm.vbox.add(lbl)
lbl.show() lbl.show()
@ -559,8 +568,13 @@ class fpdb:
pass pass
def __calendar_dialog(self, widget, entry): def __calendar_dialog(self, widget, entry):
self.dia_confirm.set_modal(False) # do not alter the modality of the parent
# self.dia_confirm.set_modal(False)
d = gtk.Window(gtk.WINDOW_TOPLEVEL) d = gtk.Window(gtk.WINDOW_TOPLEVEL)
d.set_transient_for(self.dia_confirm)
d.set_destroy_with_parent(True)
d.set_modal(True)
d.set_title('Pick a date') d.set_title('Pick a date')
vb = gtk.VBox() vb = gtk.VBox()
@ -973,9 +987,15 @@ This program is licensed under the AGPL3, see agpl-3.0.txt in the fpdb installat
menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT) menuItem = gtk.ImageMenuItem(gtk.STOCK_ABOUT)
menuItem.connect('activate', self.dia_about) menuItem.connect('activate', self.dia_about)
self.statusMenu.append(menuItem) self.statusMenu.append(menuItem)
menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
menuItem.connect('activate', self.quit) # do not allow quit - if any transient (popup) windows are open (rebuild cache, rebuild index etc)
self.statusMenu.append(menuItem) # quit from the tray causes a very very unclean shutdown, lockup of python process and failure to release global lock.
# fpdb window must be re-opened and the windows closed to quit
# menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
# menuItem.connect('activate', self.quit)
# self.statusMenu.append(menuItem)
self.statusIcon.connect('popup-menu', self.statusicon_menu, self.statusMenu) self.statusIcon.connect('popup-menu', self.statusicon_menu, self.statusMenu)
self.statusIcon.set_visible(True) self.statusIcon.set_visible(True)
@ -1022,7 +1042,7 @@ This program is licensed under the AGPL3, see agpl-3.0.txt in the fpdb installat
self.window.present() self.window.present()
def info_box(self, str1, str2): def info_box(self, str1, str2):
diapath = gtk.MessageDialog( parent=None, flags=0, type=gtk.MESSAGE_INFO diapath = gtk.MessageDialog( parent=self.window, flags=0, type=gtk.MESSAGE_INFO
, buttons=(gtk.BUTTONS_OK), message_format=str1 ) , buttons=(gtk.BUTTONS_OK), message_format=str1 )
diapath.format_secondary_text(str2) diapath.format_secondary_text(str2)
response = diapath.run() response = diapath.run()
@ -1030,7 +1050,7 @@ This program is licensed under the AGPL3, see agpl-3.0.txt in the fpdb installat
return response return response
def warning_box(self, str, diatitle="FPDB WARNING"): def warning_box(self, str, diatitle="FPDB WARNING"):
diaWarning = gtk.Dialog(title=diatitle, parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) diaWarning = gtk.Dialog(title=diatitle, parent=self.window, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK))
label = gtk.Label(str) label = gtk.Label(str)
diaWarning.vbox.add(label) diaWarning.vbox.add(label)