<commit_before># The global application object; it from global_settings because it handles tracking
# the user interface objects of the current session, rather than global options and
# preferences.

import gtk
import re
import os
import sys

# SEE BOTTOM OF FILE FOR MOST LOCAL IMPORTS
#
# Done that way to allow 'from Application import application'
# We'll have to rethink this if we ever statically compile reinteract

from application_state import ApplicationState

_VALID_CHAR = re.compile("[A-Za-z0-9._ -]")

class Application():
    def __init__(self):
        self.__unsaved_indices = []
        self.windows = set()

        config_folder = self.get_config_folder()
        if not os.path.exists(config_folder):
            os.makedirs(config_folder)

        state_location = os.path.join(config_folder, 'reinteract.state')
        self.state = ApplicationState(state_location)

    def get_notebook_infos(self):
        infos = []

        notebooks_folder = self.get_notebooks_folder()
        for f in os.listdir(notebooks_folder):
            fullpath = os.path.join(notebooks_folder, f)
            if not os.path.isdir(fullpath):
                continue

            infos.append(NotebookInfo(fullpath))

        # Wedge the examples notebook into the Open Notebook dialog so people
        # can find it. Longer-term, a possibility:
        #
        # - keep track of the history of recently opened notebooks
        # - include them when listing known notebooks
        # - on first startup, prime that with the examples notebook
        #
        infos.append(NotebookInfo(global_settings.examples_dir))

        return infos

    def get_config_folder(self):
        if sys.platform == 'win32':
            return os.path.join(os.getenv('APPDATA'), 'Reinteract')
        else:
            return os.path.expanduser("~/.reinteract")

    def get_notebooks_folder(self):
        # In a shocking example of cross-platform convergence, ~/Documents
        # is the documents directory on OS X, Windows, and Linux
        return os.path.expanduser("~/Documents/Reinteract")

    def validate_name(self, name):
        # Remove surrounding whitespace
        name = name.strip()
        if name == "":
            raise ValueError("Name cannot be empty")
<commit_msg>Add recently used notebooks to the Open Notebook dialog, and conditionally prime the list with the example notebook.<commit_after># The global application object; it from global_settings because it handles tracking
# the user interface objects of the current session, rather than global options and
# preferences.

import gtk
import re
import os
import sys

# SEE BOTTOM OF FILE FOR MOST LOCAL IMPORTS
#
# Done that way to allow 'from Application import application'
# We'll have to rethink this if we ever statically compile reinteract

from application_state import ApplicationState

_VALID_CHAR = re.compile("[A-Za-z0-9._ -]")

class Application():
    def __init__(self):
        self.__unsaved_indices = []
        self.windows = set()

        config_folder = self.get_config_folder()
        if not os.path.exists(config_folder):
            os.makedirs(config_folder)

        state_location = os.path.join(config_folder, 'reinteract.state')
        self.state = ApplicationState(state_location)

    def get_notebook_infos(self):
        paths = []

        recent = self.state.get_recent_notebooks()
        notebooks_folder = self.get_notebooks_folder()
        recent_paths = [os.path.abspath(r.path) for r in recent]
        folder_paths = [os.path.join(notebooks_folder, f) for f in os.listdir(notebooks_folder)]
        paths = recent_paths + folder_paths

        example_state = self.state.get_notebook_state(global_settings.examples_dir)
        if example_state.get_last_opened() == -1:
            paths.append(global_settings.examples_dir)
        paths = [p for p in paths if os.path.isdir(p)]
        paths = list(set(paths))

        return [NotebookInfo(p) for p in paths]

    def get_config_folder(self):
        if sys.platform == 'win32':
            return os.path.join(os.getenv('APPDATA'), 'Reinteract')
        else:
            return os.path.expanduser("~/.reinteract")

    def get_notebooks_folder(self):
        # In a shocking example of cross-platform convergence, ~/Documents
        # is the documents directory on OS X, Windows, and Linux
        return os.path.expanduser("~/Documents/Reinteract")

    def validate_name(self, name):
        # Remove surrounding whitespace
        name = name.strip()
        if name == "":
            raise ValueError("Name cannot be empty")

{'fraction_non_alphanumeric': 0.08597481545809814, 'fraction_numerical': 0.0019539730785931393, 'mean_word_length': 2.858458961474037, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686645', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1283, 'n_words': 393}