Esempio n. 1
0
    def _edit_image(self):
        filters = get_filters_for_images()
        with selectfile(_("Select Image"), filters=filters) as sf:
            rv = sf.run()
            filename = sf.get_filename()
            if rv != Gtk.ResponseType.OK or not filename:
                return

        if not self.image_model:
            self.image_model = Image(store=self.store, sellable=self._sellable)

        pb = GdkPixbuf.Pixbuf.new_from_file(filename)
        self.image_model.image = _pixbuf_converter.as_string(pb)
        self.image_model.filename = str(os.path.basename(filename))

        if self._sellable:
            for image in self._sellable.images:
                if image.is_main:
                    break
            else:
                # If there's no main image, set this one to be
                self.image_model.is_main = True

        self._setup_thumbnail()
        self.emit('image-changed', self.image_model)

        self._update_widgets()
Esempio n. 2
0
    def _edit_image(self):
        filters = get_filters_for_images()
        with selectfile(_("Select Image"), filters=filters) as sf:
            rv = sf.run()
            filename = sf.get_filename()
            if rv != Gtk.ResponseType.OK or not filename:
                return

        if not self.image_model:
            self.image_model = Image(store=self.store,
                                     sellable=self._sellable)

        pb = GdkPixbuf.Pixbuf.new_from_file(filename)
        self.image_model.image = _pixbuf_converter.as_string(pb)
        self.image_model.filename = str(os.path.basename(filename))

        if self._sellable:
            for image in self._sellable.images:
                if image.is_main:
                    break
            else:
                # If there's no main image, set this one to be
                self.image_model.is_main = True

        self._setup_thumbnail()
        self.emit('image-changed', self.image_model)

        self._update_widgets()
Esempio n. 3
0
    def testSelectfile(self):
        filters = gtk.FileFilter()
        filters.add_pattern('*.pdf')
        filters = [filters]

        with selectfile(filters=filters) as sf:
            self.assertTrue(isinstance(sf, gtk.FileChooserDialog))
            self.assertEqual(sf.list_filters(), filters)
Esempio n. 4
0
    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.ResponseType.OK or not filename:
                return

        data = open(filename, 'rb').read()
        mimetype = Gio.content_type_guess(filename, data)[0]
        if self.attachment is None:
            self.attachment = Attachment(store=self.store)
        self.attachment.name = str(os.path.basename(filename))
        self.attachment.mimetype = str(mimetype)
        self.attachment.blob = data
        self._update_widget()
Esempio n. 5
0
    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()
Esempio n. 6
0
    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()
Esempio n. 7
0
    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.ResponseType.OK or not filename:
                return

        data = open(filename, 'rb').read()
        mimetype = Gio.content_type_guess(filename, data)[0]
        if self.attachment is None:
            self.attachment = Attachment(store=self.store)
        self.attachment.name = str(os.path.basename(filename))
        self.attachment.mimetype = str(mimetype)
        self.attachment.blob = data
        self._update_widget()
Esempio n. 8
0
    def _import(self):
        ffilters = []

        all_filter = gtk.FileFilter()
        all_filter.set_name(_('All supported formats'))
        all_filter.add_pattern('*.ofx')
        all_filter.add_mime_type('application/xml')
        all_filter.add_mime_type('application/x-gzip')
        ffilters.append(all_filter)

        ofx_filter = gtk.FileFilter()
        ofx_filter.set_name(_('Open Financial Exchange (OFX)'))
        ofx_filter.add_pattern('*.ofx')
        ffilters.append(ofx_filter)

        gnucash_filter = gtk.FileFilter()
        gnucash_filter.set_name(_('GNUCash xml format'))
        gnucash_filter.add_mime_type('application/xml')
        gnucash_filter.add_mime_type('application/x-gzip')
        ffilters.append(gnucash_filter)

        with selectfile("Import", parent=self.get_toplevel(),
                        filters=ffilters) as file_chooser:
            file_chooser.run()

            filename = file_chooser.get_filename()
            if not filename:
                return

            ffilter = file_chooser.get_filter()
            if ffilter == gnucash_filter:
                format = 'gnucash.xml'
            elif ffilter == ofx_filter:
                format = 'account.ofx'
            else:
                # Guess
                if filename.endswith('.ofx'):
                    format = 'account.ofx'
                else:
                    format = 'gnucash.xml'
        run_dialog(ImporterDialog, self, format, filename)

        # Refresh everthing after an import
        self.accounts.refresh_accounts(self.store)
        for page in self._pages.values():
            page.refresh()
Esempio n. 9
0
    def _edit_image(self):
        filters = get_filters_for_images()
        with selectfile(_("Select Image"), filters=filters) as sf:
            rv = sf.run()
            filename = sf.get_filename()
            if rv != gtk.RESPONSE_OK or not filename:
                return

        w, h = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        self._thumbnail = gtk.gdk.pixbuf_new_from_file_at_size(filename, w, h)
        self._image = gtk.gdk.pixbuf_new_from_file(filename)

        if not self._image_model:
            self._image_model = Image(store=self.store)
        self._image_model.thumbnail = (
            _pixbuf_converter.as_string(self._thumbnail))
        self._image_model.image = _pixbuf_converter.as_string(self._image)
        self.emit('image-changed', self._image_model)

        self._update_widgets()
Esempio n. 10
0
    def _edit_image(self):
        filters = get_filters_for_images()
        with selectfile(_("Select Image"), filters=filters) as sf:
            rv = sf.run()
            filename = sf.get_filename()
            if rv != gtk.RESPONSE_OK or not filename:
                return

        w, h = (Image.THUMBNAIL_SIZE_WIDTH, Image.THUMBNAIL_SIZE_HEIGHT)
        self._thumbnail = gtk.gdk.pixbuf_new_from_file_at_size(filename, w, h)
        self._image = gtk.gdk.pixbuf_new_from_file(filename)

        if not self._image_model:
            self._image_model = Image(store=self.store)
        self._image_model.thumbnail = (_pixbuf_converter.as_string(
            self._thumbnail))
        self._image_model.image = _pixbuf_converter.as_string(self._image)
        self.emit('image-changed', self._image_model)

        self._update_widgets()