<commit_before>#  Copyright 2008-2015 Nokia Solutions and Networks
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

import wx

from robotide import robotapi, context
from robotide.controller.settingcontrollers import (
    DocumentationController, VariableController, TagsController)
from robotide.usages.UsageRunner import ResourceFileUsages
from robotide.publish import (
    RideItemSettingsChanged, RideInitFileRemoved, RideFileNameChanged)
from robotide.widgets import (
    ButtonWithHandler, Label, HeaderLabel, HorizontalSizer, HtmlWindow)
from .settingeditors import (
    DocumentationEditor, SettingEditor, TagsEditor,
    ImportSettingListEditor, VariablesListEditor, MetadataListEditor)


class WelcomePage(HtmlWindow):
    undo = cut = copy = paste = delete = comment = uncomment = save \
        = show_content_assist = tree_item_selected = lambda *args: None

    def __init__(self, parent):
        HtmlWindow.__init__(self, parent, text=context.ABOUT_RIDE)

    def close(self):
        self.Show(False)

    def destroy(self):
        self.close()
        self.Destroy()


class EditorPanel(wx.Panel):
    """Base class for all editor panels"""
    # TODO: Move outside default editor package, document
    name = doc = ''
    title = None
    undo = cut = copy = paste = delete = comment = uncomment = save \
        = show_content_assist = lambda self: None

    def __init__(self, plugin, parent, controller, tree):
        wx.Panel.__init__(self, parent)
        self.plugin = plugin
        self.controller = controller
        self._tree = tree

    def tree_item_selected(self, item):
        pass


class _RobotTableEditor(EditorPanel):
    name = 'table'
    doc = 'table editor'
    _settings_open_id = 'robot table settings open'

    def __init__(self, plugin, parent, controller, tree):
        EditorPanel.__init__(self, plugin, parent, controller, tree)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.Bind(wx.EVT_IDLE, self.OnIdle)
        self.SetSizer(self.sizer)
        if self.title:
            self.sizer.Add(self._create_header(self.title),
                           0, wx.EXPAND | wx.ALL, 5)
            # self.sizer.Add((0, 10))  # DEBUG why this?
        self._editors = []
        self._reset_last_show_tooltip()
        self._populate()
        self.plugin.subscribe(self._settings_changed, RideItemSettingsChanged)

    def _should_settings_be_open(self):
        if self._settings_open_id not in self.plugin.global_settings:
            return False
        return self.plugin.global_settings[self._settings_open_id]

    def _store_settings_open_status(self):
        self.plugin.global_settings[self._settings_open_id] = \
            self._settings.IsExpanded()

    def _settings_changed(self, data):
        if data.item == self.controller:
            for editor in self._editors:
                editor.update_value()

    def OnIdle(self, event):
        if self._last_shown_tooltip and self._mouse_outside_tooltip():
            self._last_shown_tooltip.hide()
            self._reset_last_show_tooltip()

    def _mouse_outside_tooltip(self):
        mx, my = wx.GetMousePosition()
        tx, ty = self._last_shown_tooltip.screen_position
        dx, dy = self._last_shown_tooltip.size
        return (mx < tx or mx > tx+dx) or (my < ty or my > ty+dy)

    def tooltip_allowed(self, tooltip):
        if wx.GetMouseState().ControlDown() or \
                self._last_shown_tooltip is tooltip:
            return False
        self._last_shown_tooltip = tooltip
        return True

    def _reset_last_show_tooltip(self):
        self._last_shown_tooltip = None

    def close(self):
        self.plugin.unsubscribe(
            self._settings_changed, RideItemSettingsChanged)
        self.Unbind(wx.EVT_MOTION)
        self.Show(False)

    def destroy(self):
        self.close()
        if wx.VERSION >= (3, 0, 3, ''):  # DEBUG wxPhoenix
            self.DestroyLater()
        else:
            self.Destroy()

    def _create_header(self, text, readonly=False):
        if readonly:
            text += ' (READ ONLY)'
        self._title_display = HeaderLabel(self, text)
        return self._title_display

    def _add_settings(self):
        self._settings = self._create_settings()
        self._restore_settings_open_status()
        self._editors.append(self._settings)
        self.sizer.Add(self._settings, 0, wx.ALL | wx.EXPAND, 2)

    def _create_settings(self):
        settings = Settings(self)
        settings.Bind(
            wx.EVT_COLLAPSIBLEPANE_CHANGED, self._collabsible_changed)
        settings.build(self.controller.settings, self.plugin, self._tree)<commit_msg>Change wx version detection for Destroy editor on 2.8.12.1.<commit_after>#  Copyright 2008-2015 Nokia Solutions and Networks
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

import wx

from robotide import robotapi, context
from robotide.controller.settingcontrollers import (
    DocumentationController, VariableController, TagsController)
from robotide.usages.UsageRunner import ResourceFileUsages
from robotide.publish import (
    RideItemSettingsChanged, RideInitFileRemoved, RideFileNameChanged)
from robotide.widgets import (
    ButtonWithHandler, Label, HeaderLabel, HorizontalSizer, HtmlWindow)
from .settingeditors import (
    DocumentationEditor, SettingEditor, TagsEditor,
    ImportSettingListEditor, VariablesListEditor, MetadataListEditor)


class WelcomePage(HtmlWindow):
    undo = cut = copy = paste = delete = comment = uncomment = save \
        = show_content_assist = tree_item_selected = lambda *args: None

    def __init__(self, parent):
        HtmlWindow.__init__(self, parent, text=context.ABOUT_RIDE)

    def close(self):
        self.Show(False)

    def destroy(self):
        self.close()
        self.Destroy()


class EditorPanel(wx.Panel):
    """Base class for all editor panels"""
    # TODO: Move outside default editor package, document
    name = doc = ''
    title = None
    undo = cut = copy = paste = delete = comment = uncomment = save \
        = show_content_assist = lambda self: None

    def __init__(self, plugin, parent, controller, tree):
        wx.Panel.__init__(self, parent)
        self.plugin = plugin
        self.controller = controller
        self._tree = tree

    def tree_item_selected(self, item):
        pass


class _RobotTableEditor(EditorPanel):
    name = 'table'
    doc = 'table editor'
    _settings_open_id = 'robot table settings open'

    def __init__(self, plugin, parent, controller, tree):
        EditorPanel.__init__(self, plugin, parent, controller, tree)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.Bind(wx.EVT_IDLE, self.OnIdle)
        self.SetSizer(self.sizer)
        if self.title:
            self.sizer.Add(self._create_header(self.title),
                           0, wx.EXPAND | wx.ALL, 5)
            # self.sizer.Add((0, 10))  # DEBUG why this?
        self._editors = []
        self._reset_last_show_tooltip()
        self._populate()
        self.plugin.subscribe(self._settings_changed, RideItemSettingsChanged)

    def _should_settings_be_open(self):
        if self._settings_open_id not in self.plugin.global_settings:
            return False
        return self.plugin.global_settings[self._settings_open_id]

    def _store_settings_open_status(self):
        self.plugin.global_settings[self._settings_open_id] = \
            self._settings.IsExpanded()

    def _settings_changed(self, data):
        if data.item == self.controller:
            for editor in self._editors:
                editor.update_value()

    def OnIdle(self, event):
        if self._last_shown_tooltip and self._mouse_outside_tooltip():
            self._last_shown_tooltip.hide()
            self._reset_last_show_tooltip()

    def _mouse_outside_tooltip(self):
        mx, my = wx.GetMousePosition()
        tx, ty = self._last_shown_tooltip.screen_position
        dx, dy = self._last_shown_tooltip.size
        return (mx < tx or mx > tx+dx) or (my < ty or my > ty+dy)

    def tooltip_allowed(self, tooltip):
        if wx.GetMouseState().ControlDown() or \
                self._last_shown_tooltip is tooltip:
            return False
        self._last_shown_tooltip = tooltip
        return True

    def _reset_last_show_tooltip(self):
        self._last_shown_tooltip = None

    def close(self):
        self.plugin.unsubscribe(
            self._settings_changed, RideItemSettingsChanged)
        self.Unbind(wx.EVT_MOTION)
        self.Show(False)

    def destroy(self):
        self.close()
        if wx.VERSION < (3, 0, 3, ''):  # DEBUG wxPhoenix
            self.Destroy()
        else:
            self.DestroyLater()

    def _create_header(self, text, readonly=False):
        if readonly:
            text += ' (READ ONLY)'
        self._title_display = HeaderLabel(self, text)
        return self._title_display

    def _add_settings(self):
        self._settings = self._create_settings()
        self._restore_settings_open_status()
        self._editors.append(self._settings)
        self.sizer.Add(self._settings, 0, wx.ALL | wx.EXPAND, 2)

    def _create_settings(self):
        settings = Settings(self)
        settings.Bind(
            wx.EVT_COLLAPSIBLEPANE_CHANGED, self._collabsible_changed)
        settings.build(self.controller.settings, self.plugin, self._tree)
{'fraction_non_alphanumeric': 0.08821548821548822, 'fraction_numerical': 0.0047138047138047135, 'mean_word_length': 2.829097605893186, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, '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': '220718', 'n_tokens_mistral': 3066, 'n_tokens_neox': 2936, 'n_words': 765}