<commit_before>import sys
import logging

import wx
import wx.grid
import wx.html
import requests
from wx.lib.mixins.inspection import InspectableApp

from eve_mlp.common import *


log = logging.getLogger(__name__)


def resource(path):
    ideas = [
        os.path.join(os.path.dirname(sys.argv[0]), path),
        os.path.join(os.environ.get("_MEIPASS2", "/"), path),
        path,
    ]
    for n in range(0, 5):
        parts = ([".."] * n + [path])
        ideas.append(os.path.join(*parts))
    for p in ideas:
        if os.path.exists(p):
            return p
    return None


class CharTable(wx.grid.PyGridTableBase):
    def __init__(self, grid, config):
        wx.grid.PyGridTableBase.__init__(self)
        self.grid = grid
        self.config = config

    def GetNumberCols(self):
        return 2

    def GetNumberRows(self):
        return len(self.config["usernames"]) + 1

    def GetColLabelValue(self, col):
        return ["Username", "Password", "Action"][col]

    def GetRowLabelValue(self, row):
        return row

    def GetValue(self, row, col):
        if row == len(self.config["usernames"]):
            return ""

        if col == 0:
            return self.config["usernames"][row]
        if col == 1:
            username = self.config["usernames"][row]
            if username in self.config["passwords"]:
                return "*" * 8
            else:
                return "-" * 8

        return "x"

    def SetValue(self, row, col, value):
        end = len(self.config["usernames"])

        # final row
        if row == end:
            if value == "":
                # final row is empty, no change
                pass
            else:
                # final row has had something added to it
                if col == 0:
                    self.config["usernames"].append(value)
                    msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, 1)
                    self.grid.ProcessTableMessage(msg)

        # username column
        elif col == 0:
            if value == "":
                # a username has been deleted
                username = self.config["usernames"][row]
                del self.config["usernames"][row]
                if username in self.config["passwords"]:
                    del self.config["passwords"][username]
                msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, row, 1)
                self.grid.ProcessTableMessage(msg)
            else:
                # a username has been modified
                self.config["usernames"][row] = value

        # password column
        elif col == 1:
            username = self.config["usernames"][row]
            if value == "":
                # password deleted
                del self.config["passwords"][username]
            else:
                # password set
                self.config["passwords"][username] = value


        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
        self.grid.ProcessTableMessage(msg)

        self.grid.ForceRefresh()


class LauncherPanel(wx.Panel):
    def __init__(self, parent, config):
        wx.Panel.__init__(self, parent)
        self.config = config

        box = wx.StaticBoxSizer(wx.StaticBox(self, label="Character List"), wx.VERTICAL)

        char_list = wx.grid.Grid(parent, -1)
        self.char_table = CharTable(char_list, parent.config)
        char_list.SetTable(self.char_table)
        char_list.SetColLabelValue(0, "Name")
        char_list.SetColLabelValue(1, "Password")
        char_list.SetColLabelValue(2, "Action")
        launch_all = wx.Button(self, -1, "Launch All")

        box.Add(char_list, 1)
        box.Add(launch_all, 0, wx.EXPAND)

        self.Bind(wx.EVT_BUTTON, self.OnLaunchAll, launch_all)

        self.SetSizer(box)
        self.Layout()

    def OnLaunchAll(self, evt):
        for username, password in self.config["passwords"].items():
            if username and password:
                from mock import Mock
                #token = do_login(username, password)
                token = "TOKEN"
                launch(token, Mock(dry=True, singularity=False))


class NewsPanel(wx.Panel):
    def __init__(self, parent, config):
        wx.Panel.__init__(self, parent)
        self.config = config

        nb = wx.Notebook(self)

        self.html = wx.html.HtmlWindow(nb)
        try:
            # TODO: async load
            data = requests.get("http://code.shishnet.org/eve-mlp/news.html").text
        except Exception as e:
            data = "Couldn't get news: %s" % str(e)
        self.html.SetPage(data)
        nb.AddPage(self.html, "MLP")

        box = wx.StaticBoxSizer(wx.StaticBox(self, label="News"), wx.VERTICAL)
        box.Add(nb, 1, wx.EXPAND)<commit_msg>place for more news tabs<commit_after>import sys
import logging

import wx
import wx.grid
import wx.html
import requests
from wx.lib.mixins.inspection import InspectableApp

from eve_mlp.common import *


log = logging.getLogger(__name__)


def resource(path):
    ideas = [
        os.path.join(os.path.dirname(sys.argv[0]), path),
        os.path.join(os.environ.get("_MEIPASS2", "/"), path),
        path,
    ]
    for n in range(0, 5):
        parts = ([".."] * n + [path])
        ideas.append(os.path.join(*parts))
    for p in ideas:
        if os.path.exists(p):
            return p
    return None


class CharTable(wx.grid.PyGridTableBase):
    def __init__(self, grid, config):
        wx.grid.PyGridTableBase.__init__(self)
        self.grid = grid
        self.config = config

    def GetNumberCols(self):
        return 2

    def GetNumberRows(self):
        return len(self.config["usernames"]) + 1

    def GetColLabelValue(self, col):
        return ["Username", "Password", "Action"][col]

    def GetRowLabelValue(self, row):
        return row

    def GetValue(self, row, col):
        if row == len(self.config["usernames"]):
            return ""

        if col == 0:
            return self.config["usernames"][row]
        if col == 1:
            username = self.config["usernames"][row]
            if username in self.config["passwords"]:
                return "*" * 8
            else:
                return "-" * 8

        return "x"

    def SetValue(self, row, col, value):
        end = len(self.config["usernames"])

        # final row
        if row == end:
            if value == "":
                # final row is empty, no change
                pass
            else:
                # final row has had something added to it
                if col == 0:
                    self.config["usernames"].append(value)
                    msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, 1)
                    self.grid.ProcessTableMessage(msg)

        # username column
        elif col == 0:
            if value == "":
                # a username has been deleted
                username = self.config["usernames"][row]
                del self.config["usernames"][row]
                if username in self.config["passwords"]:
                    del self.config["passwords"][username]
                msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, row, 1)
                self.grid.ProcessTableMessage(msg)
            else:
                # a username has been modified
                self.config["usernames"][row] = value

        # password column
        elif col == 1:
            username = self.config["usernames"][row]
            if value == "":
                # password deleted
                del self.config["passwords"][username]
            else:
                # password set
                self.config["passwords"][username] = value


        msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
        self.grid.ProcessTableMessage(msg)

        self.grid.ForceRefresh()


class LauncherPanel(wx.Panel):
    def __init__(self, parent, config):
        wx.Panel.__init__(self, parent)
        self.config = config

        box = wx.StaticBoxSizer(wx.StaticBox(self, label="Character List"), wx.VERTICAL)

        char_list = wx.grid.Grid(parent, -1)
        self.char_table = CharTable(char_list, parent.config)
        char_list.SetTable(self.char_table)
        char_list.SetColLabelValue(0, "Name")
        char_list.SetColLabelValue(1, "Password")
        char_list.SetColLabelValue(2, "Action")
        launch_all = wx.Button(self, -1, "Launch All")

        box.Add(char_list, 1)
        box.Add(launch_all, 0, wx.EXPAND)

        self.Bind(wx.EVT_BUTTON, self.OnLaunchAll, launch_all)

        self.SetSizer(box)
        self.Layout()

    def OnLaunchAll(self, evt):
        for username, password in self.config["passwords"].items():
            if username and password:
                from mock import Mock
                #token = do_login(username, password)
                token = "TOKEN"
                launch(token, Mock(dry=True, singularity=False))


class NewsPanel(wx.Panel):
    def add_http_panel(self, url, name):
#        https://client.eveonline.com/launcherv3
#        DIV.overview>ARTICLE.news
        html = wx.html.HtmlWindow(self.nb)
        try:
            # TODO: async load
            data = requests.get(url).text
        except Exception as e:
            data = "Couldn't get %s:\n%s" % (url, str(e))
        html.SetPage(data)
        self.nb.AddPage(html, name)

    def __init__(self, parent, config):
        wx.Panel.__init__(self, parent)
        self.config = config

        self.nb = wx.Notebook(self)

        self.add_http_panel("http://code.shishnet.org/eve-mlp/news.html", "MLP News")

        box = wx.StaticBoxSizer(wx.StaticBox(self, label="News"), wx.VERTICAL)
        box.Add(self.nb, 1, wx.EXPAND)
{'fraction_non_alphanumeric': 0.11750355763366538, 'fraction_numerical': 0.00477739377922342, 'mean_word_length': 1.923922734026746, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '5953661', 'n_tokens_mistral': 3036, 'n_tokens_neox': 2890, 'n_words': 640}