<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function

"""GUI creator."""

#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------

import phy
from ...utils._misc import _show_shortcuts
from ...utils.dock import DockWindow, _create_web_view
from ...utils import EventEmitter, debug
from ...plot.view_models import BaseViewModel


#------------------------------------------------------------------------------
# Manual clustering window
#------------------------------------------------------------------------------

class KlustaViewa(EventEmitter):
    """Manual clustering GUI.

    This object represents a main window with:

    * multiple views
    * a wizard panel
    * high-level clustering methods
    * global keyboard shortcuts

    """

    def __init__(self, session, config=None):
        super(KlustaViewa, self).__init__()
        self.session = session
        self.start()
        self._dock = DockWindow(title=self.title)
        # Load the saved view count.
        vc = self.session.settings.get('gui_view_count', None)
        # Default GUI config.
        config = config or self.session.settings['gui_config']
        # Remove non-existing views.
        if vc and config:
            config = [(name, _) for (name, _) in config
                      if name in vc]
        # Create the views.
        self._load_config(config)
        self._load_geometry_state()
        self._create_gui_actions()
        self._set_default_view_connections()

    def _load_config(self, config=None):
        """Load a GUI configuration dictionary."""
        for name, kwargs in config:
            debug("Adding {} view in GUI.".format(name))
            # GUI-specific keyword arguments position, size, maximized
            position = kwargs.pop('position', None)
            if name == 'wizard':
                item = self._create_wizard_panel()
            else:
                clusters = self._cluster_ids
                item = self.session.view_creator.add(name,
                                                     cluster_ids=clusters,
                                                     **kwargs)
            self.add_view(item, title=name.title(), position=position)

    def _load_geometry_state(self):
        # Load geometry state
        gs = self.session.settings.get('gui_state', None)
        if gs:
            self._dock.restore_geometry_state(gs)

    def show(self):
        """Show the GUI"""
        self._dock.show()

    def start(self):
        """Start the wizard."""
        self.session.wizard.start()
        self._cluster_ids = self.session.wizard.selection

    @property
    def main_window(self):
        """Dock main window."""
        return self._dock

    @property
    def title(self):
        """Title of the main window."""
        name = self.__class__.__name__
        filename = self.session.model.kwik_path
        clustering = self.session.model.clustering
        channel_group = self.session.model.channel_group
        template = ("{name} {version} - {filename} (shank {channel_group}, "
                    "{clustering} clustering)")
        return template.format(name=name,
                               version=phy.__version__,
                               filename=filename,
                               channel_group=channel_group,
                               clustering=clustering,<commit_msg>Fix GUI title.<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function

"""GUI creator."""

#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------

import phy
from ...utils._misc import _show_shortcuts
from ...utils.dock import DockWindow, _create_web_view
from ...utils import EventEmitter, debug
from ...plot.view_models import BaseViewModel


#------------------------------------------------------------------------------
# Manual clustering window
#------------------------------------------------------------------------------

class KlustaViewa(EventEmitter):
    """Manual clustering GUI.

    This object represents a main window with:

    * multiple views
    * a wizard panel
    * high-level clustering methods
    * global keyboard shortcuts

    """

    def __init__(self, session, config=None):
        super(KlustaViewa, self).__init__()
        self.session = session
        self.start()
        self._dock = DockWindow(title=self.title)
        # Load the saved view count.
        vc = self.session.settings.get('gui_view_count', None)
        # Default GUI config.
        config = config or self.session.settings['gui_config']
        # Remove non-existing views.
        if vc and config:
            config = [(name, _) for (name, _) in config
                      if name in vc]
        # Create the views.
        self._load_config(config)
        self._load_geometry_state()
        self._create_gui_actions()
        self._set_default_view_connections()

    def _load_config(self, config=None):
        """Load a GUI configuration dictionary."""
        for name, kwargs in config:
            debug("Adding {} view in GUI.".format(name))
            # GUI-specific keyword arguments position, size, maximized
            position = kwargs.pop('position', None)
            if name == 'wizard':
                item = self._create_wizard_panel()
            else:
                clusters = self._cluster_ids
                item = self.session.view_creator.add(name,
                                                     cluster_ids=clusters,
                                                     **kwargs)
            self.add_view(item, title=name.title(), position=position)

    def _load_geometry_state(self):
        # Load geometry state
        gs = self.session.settings.get('gui_state', None)
        if gs:
            self._dock.restore_geometry_state(gs)

    def show(self):
        """Show the GUI"""
        self._dock.show()

    def start(self):
        """Start the wizard."""
        self.session.wizard.start()
        self._cluster_ids = self.session.wizard.selection

    @property
    def main_window(self):
        """Dock main window."""
        return self._dock

    @property
    def title(self):
        """Title of the main window."""
        name = self.__class__.__name__
        filename = self.session.model.kwik_path
        clustering = self.session.model.clustering
        channel_group = self.session.model.channel_group
        template = ("{filename} (shank {channel_group}, "
                    "{clustering} clustering) "
                    "- {name} {version}")
        return template.format(name=name,
                               version=phy.__version__,
                               filename=filename,
                               channel_group=channel_group,
                               clustering=clustering,
{'fraction_non_alphanumeric': 0.17953448765256882, 'fraction_numerical': 0.0002838489923360772, 'mean_word_length': 1.4665733286664333, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089005', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1657, 'n_words': 421}