Example #1
0
    def on_export_notebook(self, window, notebook):
        """Callback from gui for exporting a notebook"""

        if notebook is None:
            return

        dialog = FileChooserDialog("Export Notebook",
                                   window,
                                   action=gtk.FILE_CHOOSER_ACTION_SAVE,
                                   buttons=("Cancel", gtk.RESPONSE_CANCEL,
                                            "Export", gtk.RESPONSE_OK),
                                   app=self.app,
                                   persistent_path="archive_notebook_path")

        basename = time.strftime(
            os.path.basename(notebook.get_path()) + "-%Y-%m-%d")

        path = self.app.get_default_path("archive_notebook_path")
        if path and os.path.exists(path):
            filename = notebooklib.get_unique_filename(path, basename, "", ".")
        else:
            filename = basename
        dialog.set_current_name(os.path.basename(filename))

        response = dialog.run()

        if response == gtk.RESPONSE_OK and dialog.get_filename():
            filename = unicode_gtk(dialog.get_filename())
            dialog.destroy()
            self.export_notebook(notebook, filename, window=window)
        else:
            dialog.destroy()
Example #2
0
    def on_export_notebook(self, window, notebook):
        """Callback from gui for exporting a notebook"""
        
        if notebook is None:
            return

        dialog = FileChooserDialog("Export Notebook", window, 
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Export", gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="archive_notebook_path")


        basename = time.strftime(os.path.basename(notebook.get_path()) +
                                 "-%Y-%m-%d")

        path = self.app.get_default_path("archive_notebook_path")
        if path and os.path.exists(path):
            filename = notebooklib.get_unique_filename(
                path, basename, "", ".")
        else:
            filename = basename
        dialog.set_current_name(os.path.basename(filename))
        
        response = dialog.run()

        if response == gtk.RESPONSE_OK and dialog.get_filename():
            filename = unicode_gtk(dialog.get_filename())
            dialog.destroy()
            self.export_notebook(notebook, filename, window=window)
        else:
            dialog.destroy()
Example #3
0
    def on_archive_notebook(self, window, notebook):
        """Callback from gui for archiving a notebook"""

        if notebook is None:
            return

        dialog = FileChooserDialog(
            "Backup Notebook", window, 
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Backup", gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="archive_notebook_path")

        path = self.app.get_default_path("archive_notebook_path")
        if os.path.exists(path):
            filename = notebooklib.get_unique_filename(
                path,
                os.path.basename(notebook.get_path()) +
                time.strftime("-%Y-%m-%d"), ".tar.gz", ".")
        else: 
            filename = os.path.basename(notebook.get_path()) + \
                time.strftime("-%Y-%m-%d") + u".tar.gz"
        
        dialog.set_current_name(os.path.basename(filename))


        file_filter = gtk.FileFilter()
        file_filter.add_pattern("*.tar.gz")
        file_filter.set_name("Archives (*.tar.gz)")
        dialog.add_filter(file_filter)

        file_filter = gtk.FileFilter()
        file_filter.add_pattern("*")
        file_filter.set_name("All files (*.*)")
        dialog.add_filter(file_filter)

        response = dialog.run()

        if response == gtk.RESPONSE_OK and dialog.get_filename():
            filename = unicode_gtk(dialog.get_filename())
            dialog.destroy()

            if u"." not in filename:
                filename += u".tar.gz"

            window.set_status("Archiving...")
            return self.archive_notebook(notebook, filename, window)
            

        elif response == gtk.RESPONSE_CANCEL:
            dialog.destroy()
            return False