예제 #1
0
    def prompt_for_name(self, folder, extension, action):
        while True:
            response = self.dialog.run()
            if response != gtk.RESPONSE_OK:
                break

            raw_name = self.name_entry.get_text()
            raw_name = reunicode.canonicalize_filename(raw_name)

            error_message = None
            try:
                raw_name = self.validate_name(raw_name)
            except ValueError, e:
                error_message = e.message

            if not error_message:
                if not (raw_name.lower().endswith("." + extension)):
                    raw_name += "." + extension

            if not error_message:
                fullname = os.path.join(folder, raw_name)
                if os.path.exists(fullname):
                    error_message = "'%s' already exists" % raw_name

            if error_message:
                dialog = gtk.MessageDialog(parent=self.dialog, buttons=gtk.BUTTONS_OK,
                                           type=gtk.MESSAGE_ERROR)
                dialog.set_markup("<big><b>Please choose a different name</b></big>")
                dialog.format_secondary_text(error_message)
                dialog.run()
                dialog.destroy()
                continue

            action(fullname)
            break
예제 #2
0
def run(parent=None):
    builder = CreateNotebookBuilder()
    builder.dialog.set_transient_for(parent)
    result_window = None

    while True:
        response = builder.dialog.run()
        if response == 0:  # gtk-builder-convert puts check/radio buttons in action-widgets
            continue
        if response != gtk.RESPONSE_OK:
            break

        raw_name = builder.name_entry.get_text()
        raw_name = reunicode.canonicalize_filename(raw_name)

        error_message = None
        error_detail = None
        try:
            name = reunicode.validate_name(raw_name)
        except ValueError, e:
            error_message = "<big><b>Please choose a different name</b></big>"
            error_detail = e.message

        if error_message is None:
            if builder.other_folder_radio_button.get_active():
                parent_folder = builder.other_folder_chooser.get_filename()
            else:
                parent_folder = global_settings.notebooks_dir

            fullname = os.path.join(parent_folder, name)
            if os.path.exists(fullname):
                error_message = "<big><b>Please choose a different name</b></big>"
                error_detail = "'%s' already exists" % name

        if error_message is None:
            try:
                builder.dialog.hide()
                description = builder.description_text_view.get_buffer(
                ).props.text.strip()
                result_window = application.create_notebook(
                    fullname, description=description)
            except OSError, e:
                builder.dialog.show()
                error_message = "<big><b>Error creating notebook</b></big>"
                error_detail = e.message
예제 #3
0
def run(parent=None):
    builder = CreateNotebookBuilder()
    builder.dialog.set_transient_for(parent)
    result_window = None

    while True:
        response = builder.dialog.run()
        if response == 0: # gtk-builder-convert puts check/radio buttons in action-widgets
            continue
        if response != gtk.RESPONSE_OK:
            break

        raw_name = builder.name_entry.get_text()
        raw_name = reunicode.canonicalize_filename(raw_name)

        error_message = None
        error_detail = None
        try:
            name = reunicode.validate_name(raw_name)
        except ValueError, e:
            error_message = "<big><b>Please choose a different name</b></big>"
            error_detail = e.message

        if error_message is None:
            if builder.other_folder_radio_button.get_active():
                parent_folder = builder.other_folder_chooser.get_filename()
            else:
                parent_folder = global_settings.notebooks_dir

            fullname = os.path.join(parent_folder, name)
            if os.path.exists(fullname):
                error_message = "<big><b>Please choose a different name</b></big>"
                error_detail = "'%s' already exists" % name

        if error_message is None:
            try:
                builder.dialog.hide()
                description = builder.description_text_view.get_buffer().props.text.strip()
                result_window = application.create_notebook(fullname, description=description)
            except OSError, e:
                builder.dialog.show()
                error_message = "<big><b>Error creating notebook</b></big>"
                error_detail = e.message
예제 #4
0
    def prompt_for_name(self, folder, extension, action):
        while True:
            response = self.dialog.run()
            if response != gtk.RESPONSE_OK:
                break

            raw_name = self.name_entry.get_text()
            raw_name = reunicode.canonicalize_filename(raw_name)

            error_message = None
            try:
                raw_name = self.validate_name(raw_name)
            except ValueError, e:
                error_message = e.message

            if not error_message:
                if not (raw_name.lower().endswith("." + extension)):
                    raw_name += "." + extension

            if not error_message:
                fullname = os.path.join(folder, raw_name)
                if os.path.exists(fullname):
                    error_message = "'%s' already exists" % raw_name

            if error_message:
                dialog = gtk.MessageDialog(parent=self.dialog,
                                           buttons=gtk.BUTTONS_OK,
                                           type=gtk.MESSAGE_ERROR)
                dialog.set_markup(
                    "<big><b>Please choose a different name</b></big>")
                dialog.format_secondary_text(error_message)
                dialog.run()
                dialog.destroy()
                continue

            action(fullname)
            break
예제 #5
0
    def __load_files(self, folder, old_files, new_files, old_monitors, new_monitors):
        if folder:
            full_folder = os.path.join(self.folder, folder)
        else:
            full_folder = self.folder

        if full_folder in old_monitors:
            new_monitors[full_folder] = old_monitors[full_folder]
            del old_monitors[full_folder]
        else:
            try:
                new_monitors[full_folder] = gio.File(full_folder).monitor_directory()
                new_monitors[full_folder].connect("changed", self._on_monitor_changed)
            except gio.Error:
                pass # probably not supported on the operating system

        files_added = False

        for f in os.listdir(full_folder):
            f = reunicode.canonicalize_filename(f)

            if folder is None and f == "index.rnb":
                continue

            # We handle filenames starting with . as hidden on all platforms,
            # valuing notebook portability over exact correspondance with
            # local convention.
            if f.startswith('.'):
                continue

            if folder:
                relative = os.path.join(folder, f)
            else:
                relative = f

            full_path = os.path.join(full_folder, f)

            if os.path.isdir(full_path):
                files_added = self.__load_files(relative, old_files, new_files, old_monitors, new_monitors) or files_added
            elif relative in old_files:
                new_files[relative] = old_files[relative]
                del old_files[relative]
            elif f.endswith('~'):
                pass
            else:
                lower = f.lower()
                if lower.endswith('.rws'):
                    file = WorksheetFile(relative)
                    absolute = os.path.join(full_folder, f)
                    for worksheet in self.worksheets:
                        if worksheet.filename and os.path.abspath(worksheet.filename) == absolute:
                            file.worksheet = worksheet
                            break
                elif lower.endswith('.py'):
                    file = LibraryFile(relative)
                elif lower.endswith('.pyc') or lower.endswith('.pyo'):
                    continue
                else:
                    file = MiscFile(relative)
                new_files[relative] = file
                files_added = True

        return files_added
예제 #6
0
    def __load_files(self, folder, old_files, new_files, old_monitors,
                     new_monitors):
        if folder:
            full_folder = os.path.join(self.folder, folder)
        else:
            full_folder = self.folder

        if full_folder in old_monitors:
            new_monitors[full_folder] = old_monitors[full_folder]
            del old_monitors[full_folder]
        else:
            try:
                new_monitors[full_folder] = gio.File(
                    full_folder).monitor_directory()
                new_monitors[full_folder].connect("changed",
                                                  self._on_monitor_changed)
            except gio.Error:
                pass  # probably not supported on the operating system

        files_added = False

        for f in os.listdir(full_folder):
            f = reunicode.canonicalize_filename(f)

            if folder is None and f == "index.rnb":
                continue

            # We handle filenames starting with . as hidden on all platforms,
            # valuing notebook portability over exact correspondance with
            # local convention.
            if f.startswith('.'):
                continue

            if folder:
                relative = os.path.join(folder, f)
            else:
                relative = f

            full_path = os.path.join(full_folder, f)

            if os.path.isdir(full_path):
                files_added = self.__load_files(relative, old_files, new_files,
                                                old_monitors,
                                                new_monitors) or files_added
            elif relative in old_files:
                new_files[relative] = old_files[relative]
                del old_files[relative]
            elif f.endswith('~'):
                pass
            else:
                lower = f.lower()
                if lower.endswith('.rws'):
                    file = WorksheetFile(relative)
                    absolute = os.path.join(full_folder, f)
                    for worksheet in self.worksheets:
                        if worksheet.filename and os.path.abspath(
                                worksheet.filename) == absolute:
                            file.worksheet = worksheet
                            break
                elif lower.endswith('.py'):
                    file = LibraryFile(relative)
                elif lower.endswith('.pyc') or lower.endswith('.pyo'):
                    continue
                else:
                    file = MiscFile(relative)
                new_files[relative] = file
                files_added = True

        return files_added