Add attachment count

This commit is contained in:
Cédric Krier
2008-01-18 23:52:25 +01:00
parent 17ba126a41
commit 0953a2c107
6 changed files with 34 additions and 4 deletions
+1 -1
View File
@@ -1339,7 +1339,7 @@
<widget class="GtkToolButton" id="but_attach">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Add an attachment to this resource</property>
<property name="label" translatable="yes">Attachment</property>
<property name="label" translatable="yes">Attachment(0)</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-paste</property>
<signal name="clicked" handler="on_but_attach_clicked"/>
+8 -1
View File
@@ -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)
+8 -1
View File
@@ -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(
+3 -1
View File
@@ -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:
@@ -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
@@ -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)