def _update_attachment(self): filters = get_filters_for_attachment() with selectfile(_("Select attachment"), filters=filters) as sf: rv = sf.run() filename = sf.get_filename() if rv != gtk.RESPONSE_OK or not filename: return data = open(filename, 'rb').read() mimetype = gio.content_type_guess(filename, data, False) if self.attachment is None: self.attachment = Attachment(store=self.store) self.attachment.name = unicode(os.path.basename(filename)) self.attachment.mimetype = unicode(mimetype) self.attachment.blob = data self._update_widget()
def _setup_attachment_chooser(self): self.attachment_chooser.connect('file-set', self._on_attachment_chooser__file_set) # If payment already had an attachment attached, changes the # FileChooser label to that file's name. if self._attachment and self._attachment.blob: name = self._attachment.get_description() # We can't use self.attachment_chooser.set_filename() because the # attachment is not a real file in the filesystem, but a field in # the database. label = (self.attachment_chooser.get_children()[0].get_children() [0].get_children()[1]) # We need to use glib.idle_add() so the label.set_label() will be # run once gtk main loop is done drawing the button (so it won't # overwrite to label back to '(None)'). glib.idle_add(label.set_label, name) for ffilter in get_filters_for_attachment(): self.attachment_chooser.add_filter(ffilter)
def _setup_attachment_chooser(self): self.attachment_chooser.connect('file-set', self._on_attachment_chooser__file_set) # If payment already had an attachment attached, changes the # FileChooser label to that file's name. if self._attachment and self._attachment.blob: name = self._attachment.get_description() # We can't use self.attachment_chooser.set_filename() because the # attachment is not a real file in the filesystem, but a field in # the database. label = (self.attachment_chooser. get_children()[0].get_children()[0].get_children()[1]) # We need to use glib.idle_add() so the label.set_label() will be # run once gtk main loop is done drawing the button (so it won't # overwrite to label back to '(None)'). glib.idle_add(label.set_label, name) for ffilter in get_filters_for_attachment(): self.attachment_chooser.add_filter(ffilter)