Save column width on attachment window
Make Attachment inherit WinForm to be fully no-modal and put save_width_height code in his own method. review222002
This commit is contained in:
1 parent
0bb4822a7f
commit
d64036a5ef
3 files changed
+43
-30
No files matched your search
@@ -5,20 +5,27 @@ from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.gui.window.win_form import WinForm
|
||||
|
||||
|
||||
class Attachment(object):
|
||||
class Attachment(WinForm):
|
||||
"Attachment window"
|
||||
|
||||
def __init__(self, model_name, record_id):
|
||||
def __init__(self, model_name, record_id, callback=None):
|
||||
self.resource = '%s,%s' % (model_name, record_id)
|
||||
|
||||
def run(self):
|
||||
self.attachment_callback = callback
|
||||
screen = Screen('ir.attachment', domain=[
|
||||
('resource', '=', self.resource),
|
||||
], mode=['tree', 'form'], context={
|
||||
'resource': self.resource,
|
||||
}, exclude_field='resource')
|
||||
screen.search_filter()
|
||||
def callback(result):
|
||||
if result:
|
||||
screen.group.save()
|
||||
WinForm(screen, callback, view_type='tree')
|
||||
super(Attachment, self).__init__(screen, self.callback,
|
||||
view_type='tree')
|
||||
|
||||
def destroy(self):
|
||||
self.prev_view.save_width_height()
|
||||
super(Attachment, self).destroy()
|
||||
|
||||
def callback(self, result):
|
||||
if result:
|
||||
self.screen.group.save()
|
||||
if self.attachment_callback:
|
||||
self.attachment_callback()
|
||||
@@ -240,7 +240,9 @@ class Form(SignalEvent, TabContent):
|
||||
def sig_attach(self, widget=None):
|
||||
obj_id = self.id_get()
|
||||
if obj_id >= 0 and obj_id is not False:
|
||||
Attachment(self.model, obj_id).run()
|
||||
def callback():
|
||||
self.update_attachment_count(reload=True)
|
||||
Attachment(self.model, obj_id, callback)
|
||||
else:
|
||||
self.message_info(_('No record selected!'))
|
||||
self.update_attachment_count(reload=True)
|
||||
|
||||
@@ -634,28 +634,32 @@ class ViewList(ParserView):
|
||||
def __getitem__(self, name):
|
||||
return None
|
||||
|
||||
def destroy(self):
|
||||
if CONFIG['client.save_width_height']:
|
||||
fields = {}
|
||||
last_col = None
|
||||
for col in self.widget_tree.get_columns():
|
||||
if col.get_visible():
|
||||
last_col = col
|
||||
if not hasattr(col, 'name') or not hasattr(col, 'width'):
|
||||
continue
|
||||
if col.get_width() != col.width and col.get_visible():
|
||||
fields[col.name] = col.get_width()
|
||||
#Don't set width for last visible columns
|
||||
#as it depends of the screen size
|
||||
if last_col and last_col.name in fields:
|
||||
del fields[last_col.name]
|
||||
def save_width_height(self):
|
||||
if not CONFIG['client.save_width_height']:
|
||||
return
|
||||
fields = {}
|
||||
last_col = None
|
||||
for col in self.widget_tree.get_columns():
|
||||
if col.get_visible():
|
||||
last_col = col
|
||||
if not hasattr(col, 'name') or not hasattr(col, 'width'):
|
||||
continue
|
||||
if col.get_width() != col.width and col.get_visible():
|
||||
fields[col.name] = col.get_width()
|
||||
#Don't set width for last visible columns
|
||||
#as it depends of the screen size
|
||||
if last_col and last_col.name in fields:
|
||||
del fields[last_col.name]
|
||||
|
||||
if fields and any(fields.itervalues()):
|
||||
try:
|
||||
rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
|
||||
self.screen.model_name, fields, rpc.CONTEXT)
|
||||
except TrytonServerError:
|
||||
pass
|
||||
if fields and any(fields.itervalues()):
|
||||
try:
|
||||
rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
|
||||
self.screen.model_name, fields, rpc.CONTEXT)
|
||||
except TrytonServerError:
|
||||
pass
|
||||
|
||||
def destroy(self):
|
||||
self.save_width_height()
|
||||
self.widget_tree.destroy()
|
||||
self.screen = None
|
||||
self.widget_tree = None
|
||||
|
||||
Reference in new issue
Block a user