~parthpanchl/gtg/workspace2

« back to all changes in this revision

Viewing changes to GTG/plugins/export/export.py

  • Committer: Parin Porecha
  • Date: 2014-01-31 06:59:35 UTC
  • mfrom: (1240.2.94 port-to-gtk3-py3)
  • Revision ID: parinporecha@gmail.com-20140131065935-ub6evnrwpmmm25hz
Merged the gtk3 and python3 port with GTG trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import subprocess
25
25
 
26
26
from xdg.BaseDirectory import xdg_config_home
27
 
import gobject
28
 
import gtk
 
27
from gi.repository import GObject, Gtk, GdkPixbuf
29
28
 
30
29
from GTG import _
31
30
from GTG.plugins.export.task_str import get_task_wrappers
132
131
        try:
133
132
            self.template.generate(tasks, self.plugin_api,
134
133
                                   self.on_export_finished)
135
 
        except Exception, err:
 
134
        except Exception as err:
136
135
            self.show_error_dialog(
137
136
                _("GTG could not generate the document: %s") % err)
138
137
            raise
179
178
        self.menu_entry = False
180
179
        self.toolbar_entry = False
181
180
 
182
 
        self.menu_item = gtk.MenuItem(_("Export the tasks currently listed"))
 
181
        self.menu_item = Gtk.MenuItem(_("Export the tasks currently listed"))
183
182
        self.menu_item.connect('activate', self.show_dialog)
184
183
        self.menu_item.show()
185
184
 
186
 
        self.tb_button = gtk.ToolButton(gtk.STOCK_PRINT)
 
185
        self.tb_button = Gtk.ToolButton(Gtk.STOCK_PRINT)
187
186
        self.tb_button.connect('clicked', self.show_dialog)
188
187
        self.tb_button.show()
189
188
 
190
 
        builder = gtk.Builder()
 
189
        builder = Gtk.Builder()
191
190
        cur_dir = os.path.dirname(os.path.abspath(__file__))
192
191
        builder_file = os.path.join(cur_dir, "export.ui")
193
192
        builder.add_from_file(builder_file)
194
193
 
195
194
        self.combo = builder.get_object("export_combo_templ")
196
 
        templates_list = gtk.ListStore(gobject.TYPE_STRING,
197
 
                                       gobject.TYPE_STRING,
198
 
                                       gobject.TYPE_STRING, gobject.TYPE_STRING
199
 
                                       )
 
195
        templates_list = Gtk.ListStore(
 
196
            GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING,
 
197
            GObject.TYPE_STRING)
200
198
        self.combo.set_model(templates_list)
201
 
        cell = gtk.CellRendererText()
 
199
        cell = Gtk.CellRendererText()
202
200
        self.combo.pack_start(cell, True)
203
201
        self.combo.add_attribute(cell, 'text', 1)
204
202
 
293
291
        description, image = model[active][2], model[active][3]
294
292
 
295
293
        if image:
296
 
            pixbuf = gtk.gdk.pixbuf_new_from_file(image)
 
294
            pixbuf = GdkPixbuf.Pixbuf.new_from_file(image)
297
295
            width, height = self.export_image.get_size_request()
298
296
            pixbuf = pixbuf.scale_simple(width, height,
299
 
                                         gtk.gdk.INTERP_BILINEAR)
 
297
                                         GdkPixbuf.InterpType.BILINEAR)
300
298
            self.export_image.set_from_pixbuf(pixbuf)
301
299
        else:
302
300
            self.export_image.clear()
308
306
 
309
307
    def show_error_dialog(self, message):
310
308
        """ Display an error """
311
 
        dialog = gtk.MessageDialog(
 
309
        dialog = Gtk.MessageDialog(
312
310
            parent=self.export_dialog,
313
 
            flags=gtk.DIALOG_DESTROY_WITH_PARENT,
314
 
            type=gtk.MESSAGE_ERROR,
315
 
            buttons=gtk.BUTTONS_OK,
 
311
            flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
 
312
            type=Gtk.MessageType.ERROR,
 
313
            buttons=Gtk.ButtonsType.OK,
316
314
            message_format=message)
317
315
        dialog.run()
318
316
        dialog.destroy()
319
317
 
320
318
    def choose_file(self):
321
319
        """ Let user choose a file to save and return its path """
322
 
        chooser = gtk.FileChooserDialog(
 
320
        chooser = Gtk.FileChooserDialog(
323
321
            title=_("Choose where to save your list"),
324
322
            parent=self.export_dialog,
325
 
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
326
 
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
327
 
                     gtk.STOCK_SAVE, gtk.RESPONSE_OK))
 
323
            action=Gtk.FileChooserAction.SAVE,
 
324
            buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
 
325
                     Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
328
326
        chooser.set_do_overwrite_confirmation(True)
329
 
        chooser.set_default_response(gtk.RESPONSE_OK)
 
327
        chooser.set_default_response(Gtk.ResponseType.OK)
330
328
        chooser.set_current_folder(get_desktop_dir())
331
329
        response = chooser.run()
332
330
        filename = chooser.get_filename()
333
331
        chooser.destroy()
334
 
        if response == gtk.RESPONSE_OK:
 
332
        if response == Gtk.ResponseType.OK:
335
333
            return filename
336
334
        else:
337
335
            return None