<reponame>Tombmyst/Empire
from empire.python.typings import *

import wx
from json import dumps


def append_menu_item(self_value: Any, text: str, handler: Callable, item_id: int = wx.ID_ANY):
    item: wx.MenuItem = wx.MenuItem(self_value, item_id, text)
    self_value.Append(item)
    self_value.Bind(wx.EVT_MENU, handler, item)


def close_dialog(self_value: wx.Dialog, event: wx.CommandEvent):
    if self_value.IsModal():
        self_value.EndModal(event.EventObject.Id)
    else:
        try:
            self_value.Close()
        except RecursionError:
            pass
    self_value.Destroy()


def confirm_dialog(parent: Any, question: str) -> bool:
    """
    Encapsulates the wx.MessageDialog and things to just return True if user says Yes, false otherwise
    :param parent: Parent window
    :param question: The question strings
    :return: True if yes
    """
    confirm = wx.MessageDialog(parent, question, 'Confirm', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
    confirm_result = confirm.ShowModal()
    return confirm_result == wx.ID_YES


def stringify_object(obj: object, indent: int = 2, sort_keys: bool = True) -> str:
    return dumps(obj.__dict__, indent=indent, sort_keys=sort_keys)


def stringify_command_event(event: wx.CommandEvent) -> str:
    s: str = ''
    s += '\nEvent Type: {}'.format(str(event.EventType))
    s += '\nExtra Long: {}'.format(str(event.ExtraLong))
    s += '\nID: {}'.format(str(event.Id))
    s += '\nInt: {}'.format(str(event.GetInt()))
    s += '\nSelection: {}'.format(str(event.GetSelection()))
    s += '\nString: {}'.format(str(event.GetString()))
    return s

from empire.python.typings import *

import wx
from json import dumps


def append_menu_item(self_value: Any, text: str, handler: Callable, item_id: int = wx.ID_ANY):
    item: wx.MenuItem = wx.MenuItem(self_value, item_id, text)
    self_value.Append(item)
    self_value.Bind(wx.EVT_MENU, handler, item)


def close_dialog(self_value: wx.Dialog, event: wx.CommandEvent):
    if self_value.IsModal():
        self_value.EndModal(event.EventObject.Id)
    else:
        try:
            self_value.Close()
        except RecursionError:
            pass
    self_value.Destroy()


def confirm_dialog(parent: Any, question: str) -> bool:
    """
    Encapsulates the wx.MessageDialog and things to just return True if user says Yes, false otherwise
    :param parent: Parent window
    :param question: The question strings
    :return: True if yes
    """
    confirm = wx.MessageDialog(parent, question, 'Confirm', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
    confirm_result = confirm.ShowModal()
    return confirm_result == wx.ID_YES


def stringify_object(obj: object, indent: int = 2, sort_keys: bool = True) -> str:
    return dumps(obj.__dict__, indent=indent, sort_keys=sort_keys)


def stringify_command_event(event: wx.CommandEvent) -> str:
    s: str = ''
    s += '\nEvent Type: {}'.format(str(event.EventType))
    s += '\nExtra Long: {}'.format(str(event.ExtraLong))
    s += '\nID: {}'.format(str(event.Id))
    s += '\nInt: {}'.format(str(event.GetInt()))
    s += '\nSelection: {}'.format(str(event.GetSelection()))
    s += '\nString: {}'.format(str(event.GetString()))
    return s
Encapsulates the wx.MessageDialog and things to just return True if user says Yes, false otherwise     :param parent: Parent window     :param question: The question strings     :return: True if yes