diff --git a/share/tryton/tryton.glade b/share/tryton/tryton.glade index 5b794b0278..ef9c101437 100644 --- a/share/tryton/tryton.glade +++ b/share/tryton/tryton.glade @@ -1339,7 +1339,7 @@ True Add an attachment to this resource - Attachment + Attachment(0) True gtk-paste diff --git a/tryton/gui/main.py b/tryton/gui/main.py index bae7595b2d..216d542eaa 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -793,19 +793,26 @@ class Main(object): self.pages.append(page) self.notebook.append_page(page.widget, gtk.Label(page.name)) self.notebook.set_current_page(-1) + page.signal_connect(self, 'attachment-count', self._attachment_count) def sb_set(self, view=None): if not view: view = self._wid_get() for i in self.buttons: if self.buttons[i]: - self.buttons[i].set_sensitive(bool(view and (i in view.handlers))) + self.buttons[i].set_sensitive( + bool(view and (i in view.handlers))) + + def _attachment_count(self, widget, signal_data): + label = _('Attachment(%d)') % signal_data + self.buttons['but_attach'].set_label(label) def _win_del(self): page = int(self.notebook.get_current_page()) if page != -1: self.notebook.disconnect(self.sig_id) page_widget = self.pages.pop(page) + page_widget.signal_unconnect(self) self.notebook.remove_page(page) self.sig_id = self.notebook.connect_after('switch-page', self._sig_page_changt) diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index 70d62d2f99..2ddc1ecbca 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -15,16 +15,18 @@ from tryton.gui.window.preference import Preference from tryton.gui.window.win_export import WinExport from tryton.gui.window.win_import import WinImport from tryton.gui.window.attachment import Attachment +from tryton.signal_event import SignalEvent _ = gettext.gettext -class Form(object): +class Form(SignalEvent): "Form" def __init__(self, model, res_id=False, domain=None, view_type=None, view_ids=None, window=None, context=None, name=False, limit=80, auto_refresh=False): + super(Form, self).__init__() if not view_type: view_type = ['tree', 'form'] if domain is None: @@ -52,6 +54,8 @@ class Form(object): window=self.window, limit=limit, readonly=bool(auto_refresh), form=self) self.screen.signal_connect(self, 'record-message', self._record_message) + self.screen.signal_connect(self, 'attachment-count', + self._attachment_count) self.screen.widget.show() if not name: @@ -338,6 +342,9 @@ class Form(object): cid = statusbar.get_context_id('message') statusbar.push(cid, msg) + def _attachment_count(self, screen, signal_data): + self.signal('attachment-count', signal_data) + def modified_save(self, reload=True): if self.screen.is_modified(): value = common.sur_3b( diff --git a/tryton/gui/window/tree.py b/tryton/gui/window/tree.py index 833d4ebe53..dcb980ca83 100644 --- a/tryton/gui/window/tree.py +++ b/tryton/gui/window/tree.py @@ -10,14 +10,16 @@ from tryton.gui.window.win_export import WinExport from tryton.config import GLADE from window import Window from tryton.action import Action +from tryton.signal_event import SignalEvent _ = gettext.gettext -class Tree(object): +class Tree(SignalEvent): "Tree page" def __init__(self, model, res_id=False, view_id=False, domain=None, context=None, window=None, name=False): + super(Tree, self).__init__() if domain is None: domain = {} if context is None: diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index aa0c9ee3b0..e4299f0e9e 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -36,6 +36,7 @@ class ModelRecord(SignalEvent): self.modified = False self.modified_fields = {} self.read_time = time.time() + self.attachment_count = -1 for key, val in self.mgroup.mfields.items(): self.value[key] = val.create(self) if (new and val.attrs['type']=='one2many') \ @@ -239,3 +240,12 @@ class ModelRecord(SignalEvent): for index, fname, value in values: data[fname] = value self.set_default(data) + + def get_attachment_count(self): + if self.attachment_count < 0: + ir_attachment = RPCProxy('ir.attachment') + self.attachment_count = ir_attachment.search_count([ + ('res_model', '=', self.resource), + ('res_id', '=', self.id), + ]) + return self.attachment_count diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index d257901087..e875c38975 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -166,6 +166,10 @@ class Screen(SignalEvent): len(self.models.models or []) + offset, self.search_count, value and value.id)) + attachment_count = 0 + if value: + attachment_count = value.get_attachment_count() + self.signal('attachment-count', attachment_count) return True current_model = property(_get_current_model, _set_current_model)