Пример #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()
Пример #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()
Пример #3
0
    def on_import_folder_tree(self, window, notebook):
        """Callback from gui for importing a folder tree"""

        # Ask the window for the currently selected nodes
        nodes = window.get_selected_nodes()
        print nodes
        if len(nodes) == 0:
            return
        node = nodes[0]


        dialog = FileChooserDialog(
            "Attach Folder", window, 
            action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Attach Folder", gtk.RESPONSE_OK))        
        response = dialog.run()

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

            self.import_folder_tree(node, filename, window=window)
        else:
            dialog.destroy()
Пример #4
0
    def on_import_txt(self, window, notebook):
        """Callback from gui for importing a plain text file"""
        
        # Ask the window for the currently selected nodes
        nodes = window.get_selected_nodes()
        if len(nodes) == 0:
            return
        node = nodes[0]
        if isinstance(node, list):
            node = node[0] # remove for keepnote 0.6.4


        dialog = FileChooserDialog(
            "Import Plain Text", window, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Import", gtk.RESPONSE_OK))
        dialog.set_select_multiple(True)
        response = dialog.run()

        if response == gtk.RESPONSE_OK and dialog.get_filenames():
            filenames = map(unicode_gtk, dialog.get_filenames())
            dialog.destroy()

            self.import_plain_text(node, filenames, window=window)
        else:
            dialog.destroy()
Пример #5
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
    def backup(self, notebook_filename):

        dialog = FileChooserDialog(
            _("Choose Backup Notebook Name"),
            self.main_window,
            action=gtk.FILE_CHOOSER_ACTION_SAVE,  #CREATE_FOLDER,
            buttons=(_("Cancel"), gtk.RESPONSE_CANCEL, _("Backup"),
                     gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="new_notebook_path")

        response = dialog.run()

        new_filename = dialog.get_filename()
        dialog.destroy()

        if response == gtk.RESPONSE_OK and new_filename:
            new_filename = unicode_gtk(new_filename)

            def func(task):
                try:
                    shutil.copytree(notebook_filename, new_filename)
                except Exception as e:
                    print(e, file=sys.stderr)
                    print("'%s' '%s'" % (notebook_filename, new_filename),
                          file=sys.stderr)
                    raise

            task = tasklib.Task(func)
            dialog2 = dialog_wait.WaitDialog(self.dialog)
            dialog2.show(_("Backing Up Notebook"),
                         _("Backing up old notebook..."),
                         task,
                         cancel=False)

            # handle errors
            if task.aborted():
                ty, err, tb = task.exc_info()
                if err:
                    self.main_window.error(_("Error occurred during backup."),
                                           err, tb)
                else:
                    self.main_window.error(_("Backup canceled."))
                return False

        return True
Пример #7
0
    def backup(self, notebook_filename):
        
        dialog = FileChooserDialog(
            _("Choose Backup Notebook Name"),
            self.main_window, 
            action=gtk.FILE_CHOOSER_ACTION_SAVE, #CREATE_FOLDER,
            buttons=(_("Cancel"), gtk.RESPONSE_CANCEL,
                     _("Backup"), gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="new_notebook_path")
        
        response = dialog.run()
        
        new_filename = dialog.get_filename()
        dialog.destroy()

        
        if response == gtk.RESPONSE_OK and new_filename:
            new_filename = unicode_gtk(new_filename)
            
            def func(task):
                try:
                    shutil.copytree(notebook_filename, new_filename)
                except Exception, e:
                    print >>sys.stderr, e
                    print >>sys.stderr, "'%s' '%s'" % (notebook_filename,
                                                       new_filename)
                    raise
            task = tasklib.Task(func)
            dialog2 = dialog_wait.WaitDialog(self.dialog)
            dialog2.show(_("Backing Up Notebook"),
                         _("Backing up old notebook..."),
                         task, cancel=False)

            # handle errors
            if task.aborted():
                ty, err, tb = task.exc_info()
                if err:
                    self.main_window.error(_("Error occurred during backup."), 
                                           err, tb)
                else:
                    self.main_window.error(_("Backup canceled."))
                return False
Пример #8
0
    def on_make_catalog(self, window, notebook, widget="focus"):
        """Callback from gui for making a catalog tree"""
        
        if notebook is None:
            return

        dialog = FileChooserDialog(
            "Make Catalog", window, 
            action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Make Catalog", gtk.RESPONSE_OK))        
        response = dialog.run()

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

            self.make_catalog(notebook, filename, 
                                    window=window, widget=widget)
        else:
            dialog.destroy()
Пример #9
0
    def on_make_catalog(self, window, notebook, widget="focus"):
        """Callback from gui for making a catalog tree"""
        
        if notebook is None:
            return

        dialog = FileChooserDialog(
            "Make Catalog", window, 
            action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Make Catalog", gtk.RESPONSE_OK))        
        response = dialog.run()

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

            self.make_catalog(notebook, filename, 
                                    window=window, widget=widget)
        else:
            dialog.destroy()
Пример #10
0
    def on_import_folder_tree(self, window, notebook):
        """Callback from gui for importing a folder tree"""

        # Ask the window for the currently selected nodes
        nodes = window.get_selected_nodes()
        if len(nodes) == 0:
            return
        node = nodes[0]

        dialog = FileChooserDialog(
            "Attach Folder",
            window,
            action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            buttons=("Cancel", gtk.RESPONSE_CANCEL, "Attach Folder",
                     gtk.RESPONSE_OK))
        response = dialog.run()

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

            self.import_folder_tree(node, filename, window=window)
        else:
            dialog.destroy()
Пример #11
0
    def on_import_nmap(self, window, notebook):
        """Callback from gui for importing a plain text file"""

        # Ask the window for the currently selected nodes
        nodes = window.get_selected_nodes()
        if len(nodes) == 0:
            return
        node = nodes[0]

        dialog = FileChooserDialog("Import Nmap XML",
                                   window,
                                   action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                   buttons=("Cancel", gtk.RESPONSE_CANCEL,
                                            "Import", gtk.RESPONSE_OK))
        dialog.set_select_multiple(True)
        response = dialog.run()

        if response == gtk.RESPONSE_OK and dialog.get_filenames():
            filenames = map(unicode_gtk, dialog.get_filenames())
            dialog.destroy()

            self.import_nmap_xml(node, filenames, window=window)
        else:
            dialog.destroy()
Пример #12
0
    def on_restore_notebook(self, window):
        """Callback from gui for restoring a notebook from an archive"""

        dialog = FileChooserDialog(
            "Chose Archive To Restore", window, 
            action=gtk.FILE_CHOOSER_ACTION_OPEN,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "Restore", gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="archive_notebook_path")

        file_filter = gtk.FileFilter()
        file_filter.add_pattern("*.tar.gz")
        file_filter.set_name("Archive (*.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():
            archive_filename = unicode_gtk(dialog.get_filename())
            dialog.destroy()

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


        # choose new notebook name
        dialog = FileChooserDialog(
            "Choose New Notebook Name", window, 
            action=gtk.FILE_CHOOSER_ACTION_SAVE,
            buttons=("Cancel", gtk.RESPONSE_CANCEL,
                     "New", gtk.RESPONSE_OK),
            app=self.app,
            persistent_path="new_notebook_path")

        file_filter = gtk.FileFilter()
        file_filter.add_pattern("*.nbk")
        file_filter.set_name("Notebook (*.nbk)")
        dialog.add_filter(file_filter)

        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():
            notebook_filename = unicode_gtk(dialog.get_filename())
            dialog.destroy()

            window.set_status("Restoring...")
            self.restore_notebook(archive_filename,
                                  notebook_filename, window)

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