<commit_before>import datetime
import os

import pkg_resources
from gi.repository import GtkSource, Gdk, Gtk, GObject, GdkPixbuf, Notify

from ..core.toolwindow import ToolWindow, question_message, error_message, info_message
from ...core.commands.script import Script, Command

# ToDo: closing the script window results in GtkWarnings (not a GTK_WIDGET etc.). Something to do with buffer marks.

language_def_path = pkg_resources.resource_filename(
    'cct', 'resource/language-specs')
langman = GtkSource.LanguageManager.get_default()
langman.set_search_path(langman.get_search_path() + [language_def_path])


class ScriptMeasurement(ToolWindow):
    def _init_gui(self, *args):
        view=self._builder.get_object('sourceview')
        self._sourcebuffer=GtkSource.Buffer()
        view.set_buffer(self._sourcebuffer)
        self._sourcebuffer.set_language(langman.get_language('cct'))
        ssman = GtkSource.StyleSchemeManager.get_default()
        self._sourcebuffer.set_style_scheme(
            ssman.get_scheme(ssman.get_scheme_ids()[0]))
        self._sourcebuffer.set_highlight_syntax(True)
        self._sourcebuffer.set_highlight_matching_brackets(True)
        self._sourcebuffer.set_modified(False)
        self._sourcebuffer.connect('modified-changed', self.on_modified_changed)
        self._window.set_title('Unnamed script')
        ma = GtkSource.MarkAttributes()
        ma.set_icon_name('media-playback-start')
        ma.set_background(Gdk.RGBA(0, 1, 0, 1))
        view.set_mark_attributes('Executing', ma, 0)

    def confirm_save(self):
        if self._sourcebuffer.get_modified():
            if question_message(self._window,'Script has been modified. Do you want to save it first?'):
                self.on_toolbutton_save(self._builder.get_object('save_toolbutton'))
                self._sourcebuffer.set_modified(False)
                return True
        self._sourcebuffer.set_modified(False)
        return False


    def on_modified_changed(self, sourcebuffer):
        self._builder.get_object('save_toolbutton').set_sensitive(sourcebuffer.get_modified())
        self._builder.get_object('saveas_toolbutton').set_sensitive(sourcebuffer.get_modified())
        title=self._window.get_title()
        if title.endswith('*'):
            title=title[:-1].strip()
        if sourcebuffer.get_modified():
            self._window.set_title(title+' *')
        else:
            self._window.set_title(title)

    def on_toolbutton_new(self, toolbutton):<commit_msg>Script GUI: Save As button not made insensitive<commit_after>import datetime
import os

import pkg_resources
from gi.repository import GtkSource, Gdk, Gtk, GObject, GdkPixbuf, Notify

from ..core.toolwindow import ToolWindow, question_message, error_message, info_message
from ...core.commands.script import Script, Command

# ToDo: closing the script window results in GtkWarnings (not a GTK_WIDGET etc.). Something to do with buffer marks.

language_def_path = pkg_resources.resource_filename(
    'cct', 'resource/language-specs')
langman = GtkSource.LanguageManager.get_default()
langman.set_search_path(langman.get_search_path() + [language_def_path])


class ScriptMeasurement(ToolWindow):
    def _init_gui(self, *args):
        view=self._builder.get_object('sourceview')
        self._sourcebuffer=GtkSource.Buffer()
        view.set_buffer(self._sourcebuffer)
        self._sourcebuffer.set_language(langman.get_language('cct'))
        ssman = GtkSource.StyleSchemeManager.get_default()
        self._sourcebuffer.set_style_scheme(
            ssman.get_scheme(ssman.get_scheme_ids()[0]))
        self._sourcebuffer.set_highlight_syntax(True)
        self._sourcebuffer.set_highlight_matching_brackets(True)
        self._sourcebuffer.set_modified(False)
        self._sourcebuffer.connect('modified-changed', self.on_modified_changed)
        self._window.set_title('Unnamed script')
        ma = GtkSource.MarkAttributes()
        ma.set_icon_name('media-playback-start')
        ma.set_background(Gdk.RGBA(0, 1, 0, 1))
        view.set_mark_attributes('Executing', ma, 0)

    def confirm_save(self):
        if self._sourcebuffer.get_modified():
            if question_message(self._window,'Script has been modified. Do you want to save it first?'):
                self.on_toolbutton_save(self._builder.get_object('save_toolbutton'))
                self._sourcebuffer.set_modified(False)
                return True
        self._sourcebuffer.set_modified(False)
        return False


    def on_modified_changed(self, sourcebuffer):
        self._builder.get_object('save_toolbutton').set_sensitive(sourcebuffer.get_modified())
        title=self._window.get_title()
        if title.endswith('*'):
            title=title[:-1].strip()
        if sourcebuffer.get_modified():
            self._window.set_title(title+' *')
        else:
            self._window.set_title(title)

    def on_toolbutton_new(self, toolbutton):
{'fraction_non_alphanumeric': 0.10280751363360938, 'fraction_numerical': 0.002827711573419511, 'mean_word_length': 3.5979572887650884, 'pattern_counts': {'":': 0, '<': 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': '96968', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1439, 'n_words': 251}