Example #1
0
    def sig_select(self, widget=None):
        try:
            # Add the filename from the field with the filename attribute in the view
            filters = []
            if not self.filters:
                filter_file = gtk.FileFilter()
                filter_file.set_name(_('All Files'))
                filter_file.add_pattern('*')
                filters.append(filter_file)
            else:
                for pat in self.filters:
                    filter_file = gtk.FileFilter()
                    filter_file.set_name(str(pat))
                    filter_file.add_pattern(pat)
                    filters.append(filter_file)

            filename = common.file_selection(_('Select a file...'),
                                             parent=self._window,
                                             filters=filters)
            if filename:
                self.model_field.set_client(
                    self._view.model,
                    base64.encodestring(file(filename, 'rb').read()))
                if self.has_filename:
                    self._view.model.set(
                        {self.has_filename: os.path.basename(filename)},
                        modified=True)
                self._view.display(self._view.model)
        except Exception, ex:
            common.message(_('Error reading the file: %s') % str(ex))
Example #2
0
def print_data(data):
    if 'result' not in data:
        common.message(
            _('Error! No Data found. Make sure you have enough data to print!')
        )
        return
    if data.get('code', 'normal') == 'zlib':
        import zlib
        content = zlib.decompress(base64.decodestring(data['result']))
    else:
        content = base64.decodestring(data['result'])

    if data['format'] in printer.openers.keys():
        import tempfile
        if data['format'] == 'html' and os.name == 'nt':
            data['format'] = 'doc'
        (fileno, fp_name) = tempfile.mkstemp('.' + data['format'], 'openerp_')
        fp = file(fp_name, 'wb+')
        fp.write(content)
        fp.close()
        os.close(fileno)
        printer.print_file(fp_name, data['format'])
    else:
        fname = common.file_selection(_('Save As...'),
                                      filename='report.' + data['format'],
                                      action=gtk.FILE_CHOOSER_ACTION_SAVE)
        if fname:
            try:
                fp = file(fname, 'wb+')
                fp.write(content)
                fp.close()
            except:
                common.message(_('Error writing the file!'))
Example #3
0
 def go(self):
     button = self.win.run()
     if button==gtk.RESPONSE_OK:
         fields = []
         fields2 = []
         iter = self.model2.get_iter_root()
         while iter:
             fields.append(self.model2.get_value(iter, 1).replace('/.id','.id'))
             fields2.append(self.model2.get_value(iter, 0))
             iter = self.model2.iter_next(iter)
         action = self.wid_action.get_active_text()
         self.parent.present()
         self.win.destroy()
         import_comp = self.wid_import_compatible.get_active()
         result = datas_read(self.ids, self.model, fields, self.fields_data, context=self.context)
         if result.get('warning',False):
             common.message_box(_('Exportation Error !'), unicode(result.get('warning',False)))
             return False
         result = result.get('datas',[])
         if import_comp:
             fields2 = fields
         if action == _('Open in Excel'):
             open_excel(fields2, result)
         else:
             fname = common.file_selection(_('Save As...'),
                     parent=self.parent, action=gtk.FILE_CHOOSER_ACTION_SAVE)
             if fname:
                 export_csv(fname, fields2, result, self.wid_write_field_names.get_active())
         return True
     else:
         self.parent.present()
         self.win.destroy()
         return False
Example #4
0
def print_data(data):
    if 'result' not in data:
        common.message(_('Error! No Data found. Make sure you have enough data to print!'))
        return 
    if data.get('code','normal')=='zlib':
        import zlib
        content = zlib.decompress(base64.decodestring(data['result']))
    else:
        content = base64.decodestring(data['result'])

    if data['format'] in printer.openers.keys():
        import tempfile
        if data['format']=='html' and os.name=='nt':
            data['format']='doc'
        (fileno, fp_name) = tempfile.mkstemp('.'+data['format'], 'openerp_')
        fp = file(fp_name, 'wb+')
        fp.write(content)
        fp.close()
        os.close(fileno)
        printer.print_file(fp_name, data['format'])
    else:
        fname = common.file_selection(_('Save As...'), filename='report.' + data['format'],
                action=gtk.FILE_CHOOSER_ACTION_SAVE)
        if fname:
            try:
                fp = file(fname,'wb+')
                fp.write(content)
                fp.close()
            except:
                common.message(_('Error writing the file!'))
Example #5
0
 def sig_save_as(self, widget):
     if not self._value:
         common.warning('There is no image!',_('Warning'))
     else:
         filename = common.file_selection(_('Save As...'), parent=self._window,
                 action=gtk.FILE_CHOOSER_ACTION_SAVE)
         if filename:
             file(filename, 'wb').write(decodestring(self._value))
Example #6
0
	def sig_add(self, widget=None):
		try:
			filename = common.file_selection(_('Select the file to picture(jpg,jpeg,gif,png)'))			
			#self.wid_text.set_text(filename)
			self.value=base64.encodestring(file(filename).read())
			self.preview()
		except:
			common.message(_('Error reading the file'))		
Example #7
0
	def sig_save_as(self, widget=None):
		try:
			filename = common.file_selection(_('Save attachment as...'))
			fp = file(filename,'wb+')
			fp.write(base64.decodestring(self.value))
			fp.close()
		except:
			common.message(_('Error writing the file!'))
Example #8
0
    def sig_add(self, widget):
        filter_all = gtk.FileFilter()
        filter_all.set_name(_('All files'))
        filter_all.add_pattern("*")

        filter_image = gtk.FileFilter()
        filter_image.set_name(_('Images'))
        for mime in ("image/png", "image/jpeg", "image/gif"):
            filter_image.add_mime_type(mime)
        for pat in ("*.png", "*.jpg", "*.gif", "*.tif", "*.xpm"):
            filter_image.add_pattern(pat)

        filename = common.file_selection(_('Open...'), parent=self._window, preview=True,
                filters=[filter_image, filter_all])
        if filename:
            self._value = encodestring(file(filename, 'rb').read())
            self.update_img()
Example #9
0
    def sig_save_as(self, widget=None):
        try:
            data = self._view.model.value.get(self.data_field_name)
            if not data:
                data = self._view.model.get(self.data_field_name)[self.data_field_name]
                if not data:
                    raise Exception(_("Unable to read the file data"))

            # Add the filename from the field with the filename attribute in the view
            filename = common.file_selection(
                _("Save As..."), parent=self._window, action=gtk.FILE_CHOOSER_ACTION_SAVE, filename=self._get_filename()
            )
            if filename:
                fp = file(filename, "wb+")
                fp.write(base64.decodestring(data))
                fp.close()
        except Exception, ex:
            common.message(_("Error writing the file: %s") % str(ex))
Example #10
0
 def go(self):
     button = self.win.run()
     if button == gtk.RESPONSE_OK:
         fields = []
         fields2 = []
         iter = self.model2.get_iter_root()
         while iter:
             fields.append(
                 self.model2.get_value(iter, 1).replace('/.id', '.id'))
             fields2.append(self.model2.get_value(iter, 0))
             iter = self.model2.iter_next(iter)
         action = self.wid_action.get_active()
         self.parent.present()
         self.win.destroy()
         import_comp = self.wid_import_compatible.get_active()
         result = datas_read(self.ids,
                             self.model,
                             fields,
                             self.fields_data,
                             context=self.context)
         if result.get('warning', False):
             common.message_box(_('Exportation Error !'),
                                unicode(result.get('warning', False)))
             return False
         result = result.get('datas', [])
         if import_comp:
             fields2 = fields
         if len(self.wid_action.get_model()
                ) > 1 and self.wid_action.get_active() == 0:
             open_excel(fields2, result)
         else:
             fname = common.file_selection(
                 _('Save As...'),
                 parent=self.parent,
                 action=gtk.FILE_CHOOSER_ACTION_SAVE)
             if fname:
                 export_csv(fname, fields2, result,
                            self.wid_write_field_names.get_active())
         return True
     else:
         self.parent.present()
         self.win.destroy()
         return False
Example #11
0
    def sig_add(self, widget):
        filter_all = gtk.FileFilter()
        filter_all.set_name(_('All files'))
        filter_all.add_pattern("*")

        filter_image = gtk.FileFilter()
        filter_image.set_name(_('Images'))
        for mime in ("image/png", "image/jpeg", "image/gif"):
            filter_image.add_mime_type(mime)
        for pat in ("*.png", "*.jpg", "*.gif", "*.tif", "*.xpm"):
            filter_image.add_pattern(pat)

        filename = common.file_selection(_('Open...'), parent=self._window, preview=True,
                filters=[filter_image, filter_all])
        if filename:
            self._value = encodestring(file(filename, 'rb').read())
            self.update_img()
            self.set_value(self._view.model, self._view.model.mgroup.mfields[self.attrs['name']])
            if self.has_filename and self.has_filename in self._view.model.mgroup.mfields:
                self._view.model.set({self.has_filename: os.path.basename(filename)}, modified=True)
Example #12
0
    def sig_save_as(self, widget=None):
        try:
            data = self._view.model.value.get(self.data_field_name)
            if not data:
                data = self._view.model.get(self.data_field_name)[self.data_field_name]
                if not data:
                    raise Exception(_("Unable to read the file data"))

            # Add the filename from the field with the filename attribute in the view
            filename = common.file_selection(
                _('Save As...'),
                parent=self._window,
                action=gtk.FILE_CHOOSER_ACTION_SAVE,
                filename=self._get_filename()
            )
            if filename:
                fp = file(filename,'wb+')
                fp.write(base64.decodestring(data))
                fp.close()
        except Exception, ex:
            common.message(_('Error writing the file: %s') % str(ex))
Example #13
0
    def sig_select(self, widget=None):
        try:
            # Add the filename from the field with the filename attribute in the view
            filters = []
            if not self.filters:
                filter_file = gtk.FileFilter()
                filter_file.set_name(_('All Files'))
                filter_file.add_pattern('*')
                filters.append(filter_file)
            else:
                for pat in self.filters:
                    filter_file = gtk.FileFilter()
                    filter_file.set_name(str(pat))
                    filter_file.add_pattern(pat)
                    filters.append(filter_file)

            filename = common.file_selection(_('Select a file...'), parent=self._window,filters=filters)
            if filename:
                self.model_field.set_client(self._view.model, base64.encodestring(file(filename, 'rb').read()))
                if self.has_filename and self.has_filename in self._view.model.mgroup.mfields:
                    self._view.model.set({self.has_filename: os.path.basename(filename)}, modified=True)
                self._view.display(self._view.model)
        except Exception, ex:
            common.message(_('Error reading the file: %s') % str(ex))
Example #14
0
 def sig_new(self, widget=None):
     filename = common.file_selection(_("Open..."), parent=self._window)
     if filename:
         self.model_field.set_client(self._view.model, filename)
Example #15
0
 def sig_new(self, widget=None):
     filename = common.file_selection(_('Open...'), parent=self._window)
     if filename:
         self.model_field.set_client(self._view.model, filename)