Make preference windows no-modal
Modal dialog keep the event loop for themselves on windows so any children popups are insensitive. issue2809 review546003
This commit is contained in:
1 parent
e3b3a0f02b
commit
a48fd7e0a3
3 files changed
+35
-35
No files matched your search
+4
-4
@@ -833,8 +833,8 @@ class Main(object):
|
||||
def sig_user_preferences(self, widget):
|
||||
if not self.close_pages():
|
||||
return False
|
||||
win = Preference(rpc._USER)
|
||||
if win.run():
|
||||
|
||||
def callback():
|
||||
rpc.context_reload()
|
||||
try:
|
||||
prefs = RPCExecute('model', 'res.user', 'get_preferences',
|
||||
@@ -856,8 +856,8 @@ class Main(object):
|
||||
self.sig_win_menu()
|
||||
CONFIG['client.lang'] = prefs['language']
|
||||
CONFIG.save()
|
||||
self.sig_win_menu()
|
||||
return True
|
||||
self.sig_win_menu()
|
||||
Preference(rpc._USER, callback)
|
||||
|
||||
def sig_win_close(self, widget):
|
||||
self._sig_remove_book(widget,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
import gtk
|
||||
|
||||
from tryton.gui.main import Main
|
||||
import tryton.common as common
|
||||
|
||||
|
||||
@@ -19,6 +18,7 @@ class NoModal(object):
|
||||
focus = focus.get_parent()
|
||||
|
||||
def register(self):
|
||||
from tryton.gui.main import Main
|
||||
main = Main.get_main()
|
||||
self.page = main.get_page()
|
||||
if not self.page:
|
||||
|
||||
@@ -8,17 +8,19 @@ from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.config import TRYTON_ICON
|
||||
import tryton.common as common
|
||||
from tryton.common import RPCExecute, RPCException
|
||||
from tryton.gui.window.nomodal import NoModal
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
|
||||
class Preference(object):
|
||||
class Preference(NoModal):
|
||||
"Preference window"
|
||||
|
||||
def __init__(self, user):
|
||||
self.parent = common.get_toplevel_window()
|
||||
def __init__(self, user, callback):
|
||||
NoModal.__init__(self)
|
||||
self.callback = callback
|
||||
self.win = gtk.Dialog(_('Preferences'), self.parent,
|
||||
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
|
||||
gtk.DIALOG_DESTROY_WITH_PARENT)
|
||||
self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||
self.win.set_has_separator(False)
|
||||
self.win.set_icon(TRYTON_ICON)
|
||||
@@ -33,6 +35,7 @@ class Preference(object):
|
||||
gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
|
||||
|
||||
self.win.set_default_response(gtk.RESPONSE_OK)
|
||||
self.win.connect('response', self.response)
|
||||
|
||||
try:
|
||||
view = RPCExecute('model', 'res.user',
|
||||
@@ -68,33 +71,30 @@ class Preference(object):
|
||||
width, height = self.parent.get_size()
|
||||
self.win.set_default_size(int(width * 0.9), int(height * 0.9))
|
||||
|
||||
self.register()
|
||||
self.win.show()
|
||||
|
||||
def run(self):
|
||||
"Run the window"
|
||||
if not self.win:
|
||||
return False
|
||||
res = False
|
||||
while True:
|
||||
if self.win.run() == gtk.RESPONSE_OK:
|
||||
if self.screen.current_record.validate():
|
||||
vals = copy.copy(self.screen.get(get_modifiedonly=True))
|
||||
if 'password' in vals:
|
||||
password = common.ask(_('Current Password:'),
|
||||
visibility=False)
|
||||
if not password:
|
||||
break
|
||||
else:
|
||||
password = False
|
||||
try:
|
||||
RPCExecute('model', 'res.user', 'set_preferences',
|
||||
vals, password)
|
||||
except RPCException:
|
||||
continue
|
||||
res = True
|
||||
break
|
||||
else:
|
||||
break
|
||||
def response(self, win, response_id):
|
||||
if response_id == gtk.RESPONSE_OK:
|
||||
if self.screen.current_record.validate():
|
||||
vals = copy.copy(self.screen.get(get_modifiedonly=True))
|
||||
if 'password' in vals:
|
||||
password = common.ask(_('Current Password:'),
|
||||
visibility=False)
|
||||
if not password:
|
||||
return
|
||||
else:
|
||||
password = False
|
||||
try:
|
||||
RPCExecute('model', 'res.user', 'set_preferences',
|
||||
vals, password)
|
||||
except RPCException:
|
||||
return
|
||||
self.parent.present()
|
||||
self.destroy()
|
||||
self.callback()
|
||||
|
||||
def destroy(self):
|
||||
self.screen.destroy()
|
||||
self.win.destroy()
|
||||
return res
|
||||
NoModal.destroy(self)
|
||||
Reference in new issue
Block a user