Пример #1
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.wid_action.get_active()
            self.destroy()
            result = self.datas_read(self.ids, self.model, fields,
                    context=self.context)

            if action == 0:
                fileno, fname = tempfile.mkstemp('.csv', 'tryton_')
                self.export_csv(fname, fields2, result,
                        self.wid_write_field_names.get_active(), popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(_('Save As...'),
                        action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, result,
                            self.wid_write_field_names.get_active())
            return True
        else:
            self.destroy()
            return False
Пример #2
0
    def response(self, dialog, response):
        if response == Gtk.ResponseType.OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_first()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.saveas.get_active()
            try:
                data = RPCExecute('model',
                                  self.model,
                                  'export_data',
                                  self.ids,
                                  fields,
                                  context=self.context)
            except RPCException:
                data = []

            if action == 0:
                fileno, fname = tempfile.mkstemp(
                    '.csv',
                    common.slugify(self.name) + '_')
                self.export_csv(fname, fields2, data, popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(
                    _('Save As...'), action=Gtk.FileChooserAction.SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        self.destroy()
Пример #3
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.wid_action.get_active()
            self.destroy()
            result = self.datas_read(self.ids,
                                     self.model,
                                     fields,
                                     context=self.context)

            if action == 0:
                fileno, fname = tempfile.mkstemp('.csv', 'tryton_')
                self.export_csv(fname,
                                fields2,
                                result,
                                self.wid_write_field_names.get_active(),
                                popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(
                    _('Save As...'), action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, result,
                                    self.wid_write_field_names.get_active())
            return True
        else:
            self.destroy()
            return False
Пример #4
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.saveas.get_active()
            self.destroy()
            try:
                data = RPCExecute('model',
                                  self.model,
                                  'export_data',
                                  self.ids,
                                  fields,
                                  context=self.context)
            except RPCException:
                data = []

            if action == 0:
                fileno, fname = tempfile.mkstemp('.csv', 'tryton_')
                self.export_csv(fname, fields2, data, popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(
                    _('Save As...'), action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        else:
            self.destroy()
Пример #5
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.saveas.get_active()
            try:
                data = RPCExecute("model", self.model, "export_data", self.ids, fields, context=self.context)
            except RPCException:
                data = []

            if action == 0:
                fileno, fname = tempfile.mkstemp(".csv", "tryton_")
                self.export_csv(fname, fields2, data, popup=False)
                os.close(fileno)
                common.file_open(fname, "csv")
            else:
                fname = common.file_selection(_("Save As..."), action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        self.destroy()
Пример #6
0
 def sig_new(self, widget=None):
     filename = file_selection(_('Open...'))
     if filename and self.field:
         self.field.set_client(self.record, open(filename, 'rb').read())
         if self.filename_field:
             self.filename_field.set_client(self.record,
                     os.path.basename(filename))
Пример #7
0
    def save(self, widget):
        parent = get_toplevel_window()
        dia = gtk.Dialog(_('Image Size'), parent,
                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                         (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK,
                          gtk.RESPONSE_OK))
        dia.set_icon(GNUHEALTH_ICON)
        dia.set_default_response(gtk.RESPONSE_OK)

        hbox = gtk.HBox(spacing=3)
        dia.vbox.pack_start(hbox, False, True)

        hbox.pack_start(gtk.Label(_('Width:')), False, True)
        spinwidth = gtk.SpinButton()
        spinwidth.configure(gtk.Adjustment(400.0, 0.0, sys.maxint, 1.0, 10.0),
                            climb_rate=1,
                            digits=0)
        spinwidth.set_numeric(True)
        spinwidth.set_activates_default(True)
        hbox.pack_start(spinwidth, True, True)

        hbox.pack_start(gtk.Label(_('Height:')), False, True)
        spinheight = gtk.SpinButton()
        spinheight.configure(gtk.Adjustment(200.0, 0.0, sys.maxint, 1.0, 10.0),
                             climb_rate=1,
                             digits=0)
        spinheight.set_numeric(True)
        spinheight.set_activates_default(True)
        hbox.pack_start(spinheight, True, True)
        dia.show_all()

        filter = gtk.FileFilter()
        filter.set_name(_('PNG image (*.png)'))
        filter.add_mime_type('image/png')
        filter.add_pattern('*.png')

        while True:
            response = dia.run()
            width = spinwidth.get_value_as_int()
            height = spinheight.get_value_as_int()
            if response == gtk.RESPONSE_OK:
                filename = file_selection(_('Save As'),
                                          action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                          preview=False,
                                          filters=[filter])
                if width and height and filename:
                    if not filename.endswith('.png'):
                        filename = filename + '.png'
                    try:
                        self.widgets['root'].export_png(
                            filename, width, height)
                        break
                    except MemoryError:
                        message(_('Image size too large.'), dia,
                                gtk.MESSAGE_ERROR)
            else:
                break
        parent.present()
        dia.destroy()
Пример #8
0
 def select(self, widget=None):
     if not self.field:
         return
     filename = file_selection(_('Select'),
                               preview=self.preview,
                               filters=self.filters)
     if filename:
         self._set_uri('file:///' + filename)
Пример #9
0
 def new_binary(self, renderer, path):
     filename = file_selection(_('Open...'))
     record, field = self._get_record_field(path)
     if filename:
         field.set_client(record, open(filename, 'rb').read())
         if self.filename:
             filename_field = record.group.fields[self.filename]
             filename_field.set_client(record, os.path.basename(filename))
Пример #10
0
 def _select():
     filename = file_selection(_('Open...'))
     if filename:
         with open(filename, 'rb') as fp:
             field.set_client(record, fp.read())
         if filename_field:
             filename_field.set_client(record,
                                       os.path.basename(filename))
Пример #11
0
 def new_binary(self, renderer, path):
     filename = file_selection(_('Open...'))
     record, field = self._get_record_field(path)
     if filename:
         field.set_client(record, open(filename, 'rb').read())
         if self.filename:
             filename_field = record.group.fields[self.filename]
             filename_field.set_client(record, os.path.basename(filename))
Пример #12
0
    def response(self, dialog, response):
        if response == Gtk.ResponseType.OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_first()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)

            if self.selected_records.get_active():
                ids = [r.id for r in self.screen.selected_records]
                paths = self.screen.selected_paths
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data',
                        ids, fields,
                        context=self.context)
                except RPCException:
                    data = []
            elif self.screen_is_tree:
                ids = [r.id for r in self.screen.listed_records]
                paths = self.screen.listed_paths
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data',
                        ids, fields,
                        context=self.context)
                except RPCException:
                    data = []
            else:
                paths = None
                domain = self.screen.search_domain(
                    self.screen.screen_container.get_text())
                if self.ignore_search_limit.get_active():
                    offset, limit = 0, None
                else:
                    offset, limit = self.screen.offset, self.screen.limit
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data_domain',
                        domain, fields, offset, limit, self.screen.order,
                        context=self.context)
                except RPCException:
                    data = []

            if self.saveas.get_active():
                fname = common.file_selection(_('Save As...'),
                        action=Gtk.FileChooserAction.SAVE)
                if fname:
                    self.export_csv(fname, fields2, data, paths)
            else:
                fileno, fname = tempfile.mkstemp(
                    '.csv', common.slugify(self.name) + '_')
                self.export_csv(fname, fields2, data, paths, popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
        self.destroy()
Пример #13
0
 def save_as(self, widget=None):
     filename = ''
     if self.filename_field:
         filename = self.filename_field.get(self.record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=Gtk.FileChooserAction.SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(self.get_data())
Пример #14
0
 def sig_save_as(self, widget):
     filename = ''
     if self.filename_field:
         filename = self.filename_field.get(self.record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=gtk.FILE_CHOOSER_ACTION_SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(self.field.get_data(self.record))
Пример #15
0
 def sig_save_as(self, widget=None):
     filename = ''
     if self.filename_field:
         filename = self.filename_field.get(self.record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=gtk.FILE_CHOOSER_ACTION_SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(self.field.get_data(self.record))
Пример #16
0
 def save_binary(self, renderer, path):
     filename = ''
     record, field = self._get_record_field(path)
     if self.filename:
         filename_field = record.group.fields.get(self.filename)
         filename = filename_field.get(record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=gtk.FILE_CHOOSER_ACTION_SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(field.get_data(record))
Пример #17
0
 def clicked(self, renderer, path):
     filename = ''
     record, field = self._get_record_field_from_path(path)
     if self.attrs.get('filename'):
         filename_field = record.group.fields.get(self.attrs['filename'])
         filename = filename_field.get(record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=Gtk.FileChooserAction.SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(self.binary.get_data(record, field))
Пример #18
0
 def save_binary(self, renderer, path):
     filename = ''
     record, field = self._get_record_field(path)
     if self.filename:
         filename_field = record.group.fields.get(self.filename)
         filename = filename_field.get(record)
     filename = file_selection(_('Save As...'), filename=filename,
         action=gtk.FILE_CHOOSER_ACTION_SAVE)
     if filename:
         with open(filename, 'wb') as fp:
             fp.write(field.get_data(record))
Пример #19
0
    def select(self, widget=None):
        if not self.field:
            return
        filters = self.filters

        filename = file_selection(_('Select'), preview=self.preview,
            filters=filters)
        if filename:
            self.field.set_client(self.record, open(filename, 'rb').read())
            if self.filename_field:
                self.filename_field.set_client(self.record,
                    os.path.basename(filename))
Пример #20
0
 def sig_new(self, widget=None):
     filename = ''
     if self.last_open_file:
         last_id, last_filename = self.last_open_file
         if last_id == self.record.id:
             filename = last_filename
     filename = file_selection(_('Open...'), filename=filename)
     if filename and self.field:
         self.field.set_client(self.record, open(filename, 'rb').read())
         if self.filename_field:
             self.filename_field.set_client(self.record,
                                            os.path.basename(filename))
Пример #21
0
 def new_binary(self, renderer, path):
     record, field = self._get_record_field(path)
     filename = ''
     if self.last_open_file:
         last_id, last_filename = self.last_open_file
         if last_id == record.id:
             filename = last_filename
     filename = file_selection(_('Open...'), filename=filename)
     if filename:
         field.set_client(record, open(filename, 'rb').read())
         if self.filename:
             filename_field = record.group.fields[self.filename]
             filename_field.set_client(record, os.path.basename(filename))
Пример #22
0
 def new_binary(self, renderer, path):
     record, field = self._get_record_field(path)
     filename = ''
     if self.last_open_file:
         last_id, last_filename = self.last_open_file
         if last_id == record.id:
             filename = last_filename
     filename = file_selection(_('Open...'), filename=filename)
     if filename:
         field.set_client(record, open(filename, 'rb').read())
         if self.filename:
             filename_field = record.group.fields[self.filename]
             filename_field.set_client(record, os.path.basename(filename))
Пример #23
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 = file_selection(_('Open...'), preview=True,
            filters=[filter_image, filter_all])
        if filename:
            self.field.set_client(self.record, open(filename, 'rb').read())
            if self.filename_field:
                self.filename_field.set_client(self.record,
                        os.path.basename(filename))
            self.update_img()
Пример #24
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 = file_selection(_('Open...'),
                                  preview=True,
                                  filters=[filter_image, filter_all])
        if filename:
            self.field.set_client(self.record, open(filename, 'rb').read())
            if self.filename_field:
                self.filename_field.set_client(self.record,
                                               os.path.basename(filename))
            self.update_img()
Пример #25
0
 def add_file(widget):
     filenames = common.file_selection(_("Select"), multi=True)
     if filenames:
         attachment = window(widget)
         for filename in filenames:
             attachment.add_file(filename)
Пример #26
0
    def save(self, widget):
        parent = get_toplevel_window()
        dia = Gtk.Dialog(
            title=_('Image Size'), transient_for=parent, modal=True,
            destroy_with_parent=True)
        Main().add_window(dia)
        cancel_button = dia.add_button(
            set_underline(_("Cancel")), Gtk.ResponseType.CANCEL)
        cancel_button.set_image(IconFactory.get_image(
                'tryton-cancel', Gtk.IconSize.BUTTON))
        cancel_button.set_always_show_image(True)
        ok_button = dia.add_button(
            set_underline(_("OK")), Gtk.ResponseType.OK)
        ok_button.set_image(IconFactory.get_image(
                'tryton-ok', Gtk.IconSize.BUTTON))
        ok_button.set_always_show_image(True)
        dia.set_icon(TRYTON_ICON)
        dia.set_default_response(Gtk.ResponseType.OK)

        hbox = Gtk.HBox(spacing=3)
        dia.vbox.pack_start(hbox, expand=False, fill=True, padding=0)

        hbox.pack_start(
            Gtk.Label(label=_('Width:')), expand=False, fill=True, padding=0)
        spinwidth = Gtk.SpinButton()
        spinwidth.configure(Gtk.Adjustment(
                value=400.0, lower=0.0, upper=sys.maxsize,
                step_increment=1.0, page_increment=10.0),
            climb_rate=1, digits=0)
        spinwidth.set_numeric(True)
        spinwidth.set_activates_default(True)
        hbox.pack_start(spinwidth, expand=True, fill=True, padding=0)

        hbox.pack_start(
            Gtk.Label(label=_('Height:')), expand=False, fill=True, padding=0)
        spinheight = Gtk.SpinButton()
        spinheight.configure(Gtk.Adjustment(
                value=200.0, lower=0.0, upper=sys.maxsize,
                step_increment=1.0, page_increment=10.0),
            climb_rate=1, digits=0)
        spinheight.set_numeric(True)
        spinheight.set_activates_default(True)
        hbox.pack_start(spinheight, expand=True, fill=True, padding=0)
        dia.show_all()

        filter = Gtk.FileFilter()
        filter.set_name(_('PNG image (*.png)'))
        filter.add_mime_type('image/png')
        filter.add_pattern('*.png')

        while True:
            response = dia.run()
            width = spinwidth.get_value_as_int()
            height = spinheight.get_value_as_int()
            if response == Gtk.ResponseType.OK:
                filename = file_selection(
                    _('Save As'),
                    action=Gtk.FileChooserAction.SAVE,
                    preview=False,
                    filters=[filter])
                if width and height and filename:
                    if not filename.endswith('.png'):
                        filename = filename + '.png'
                    try:
                        self.widgets['root'].export_png(
                            filename, width, height)
                        break
                    except MemoryError:
                        message(
                            _('Image size too large.'), dia,
                            Gtk.MessageType.ERROR)
            else:
                break
        parent.present()
        dia.destroy()