2014-11-12 20:41:29 -06:00
|
|
|
import wx
|
2018-03-14 13:34:56 -06:00
|
|
|
import wx.adv
|
2015-08-16 08:42:17 -05:00
|
|
|
import paths
|
|
|
|
import languageHandler
|
|
|
|
import sys
|
2014-11-12 20:41:29 -06:00
|
|
|
|
2015-01-20 22:07:13 -06:00
|
|
|
toolkit = "wx"
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
### Code responses for WX dialogs.
|
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# this is when an user presses OK on a dialogue.
|
2014-11-12 20:41:29 -06:00
|
|
|
OK = wx.ID_OK
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is when an user presses cancel on a dialogue.
|
2014-11-12 20:41:29 -06:00
|
|
|
CANCEL = wx.ID_CANCEL
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is when an user closes the dialogue or an id to create the close button.
|
2014-11-12 20:41:29 -06:00
|
|
|
CLOSE = wx.ID_CLOSE
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# The response for a "yes" Button pressed on a dialogue.
|
2014-11-12 20:41:29 -06:00
|
|
|
YES = wx.ID_YES
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is when the user presses No on a default dialogue.
|
2014-11-12 20:41:29 -06:00
|
|
|
NO = wx.ID_NO
|
|
|
|
|
2015-03-31 17:46:15 -06:00
|
|
|
###events
|
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is raised when the application must be closed.
|
2014-11-12 20:41:29 -06:00
|
|
|
CLOSE_EVENT = wx.EVT_CLOSE
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is activated when a button is pressed.
|
2014-11-12 22:37:52 -06:00
|
|
|
BUTTON_PRESSED = wx.EVT_BUTTON
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This is raised when a checkbox changes its status.
|
2015-02-26 15:21:26 -06:00
|
|
|
CHECKBOX = wx.EVT_CHECKBOX
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-16 21:37:29 -06:00
|
|
|
# This is activated when an user enter text on an edit box.
|
2014-11-15 19:40:19 -06:00
|
|
|
ENTERED_TEXT = wx.EVT_TEXT
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This is raised when a user activates a menu.
|
2014-12-29 14:35:08 -06:00
|
|
|
MENU = wx.EVT_MENU
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This is raised when a user presses any key in the control.
|
2014-12-29 14:35:08 -06:00
|
|
|
KEYPRESS = wx.EVT_CHAR_HOOK
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This is raised when a user releases a key in the control.
|
2014-12-29 14:35:08 -06:00
|
|
|
KEYUP = wx.EVT_KEY_UP
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This happens when a notebook tab is changed, It is used in Treebooks too.
|
2015-01-19 12:15:57 -06:00
|
|
|
NOTEBOOK_PAGE_CHANGED = wx.EVT_TREEBOOK_PAGE_CHANGED
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# This happens when a radiobutton group changes its status.
|
2015-02-01 21:13:18 -06:00
|
|
|
RADIOBUTTON = wx.EVT_RADIOBUTTON
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
# Taskbar mouse clicks.
|
2018-03-14 13:34:56 -06:00
|
|
|
TASKBAR_RIGHT_CLICK = wx.adv.EVT_TASKBAR_RIGHT_DOWN
|
|
|
|
TASKBAR_LEFT_CLICK = wx.adv.EVT_TASKBAR_LEFT_DOWN
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2014-11-12 20:41:29 -06:00
|
|
|
def exit_application():
|
2015-03-31 17:46:15 -06:00
|
|
|
""" Closes the current window cleanly. """
|
|
|
|
wx.GetApp().ExitMainLoop()
|
2014-11-12 20:41:29 -06:00
|
|
|
|
2014-12-29 14:35:08 -06:00
|
|
|
def connect_event(parent, event, func, menuitem=None, *args, **kwargs):
|
2015-03-31 17:46:15 -06:00
|
|
|
""" Connects an event to a function.
|
|
|
|
parent wx.window: The widget that will listen for the event.
|
|
|
|
event widgetUtils.event: The event that will be listened for the parent. The event should be one of the widgetUtils events.
|
|
|
|
function func: The function that will be connected to the event."""
|
|
|
|
if menuitem == None:
|
|
|
|
return getattr(parent, "Bind")(event, func, *args, **kwargs)
|
|
|
|
else:
|
|
|
|
return getattr(parent, "Bind")(event, func, menuitem, *args, **kwargs)
|
2015-01-20 22:07:13 -06:00
|
|
|
|
|
|
|
def connectExitFunction(exitFunction):
|
2015-03-31 17:46:15 -06:00
|
|
|
""" This connect the events in WX when an user is turning off the machine."""
|
|
|
|
wx.GetApp().Bind(wx.EVT_QUERY_END_SESSION, exitFunction)
|
|
|
|
wx.GetApp().Bind(wx.EVT_END_SESSION, exitFunction)
|
|
|
|
|
|
|
|
class BaseDialog(wx.Dialog):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(BaseDialog, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_response(self):
|
|
|
|
return self.ShowModal()
|
|
|
|
|
|
|
|
def get(self, control):
|
|
|
|
if hasattr(self, control):
|
|
|
|
control = getattr(self, control)
|
|
|
|
if hasattr(control, "GetValue"): return getattr(control, "GetValue")()
|
|
|
|
elif hasattr(control, "GetLabel"): return getattr(control, "GetLabel")()
|
|
|
|
else: return -1
|
|
|
|
else: return 0
|
|
|
|
|
|
|
|
def set(self, control, text):
|
|
|
|
if hasattr(self, control):
|
|
|
|
control = getattr(self, control)
|
|
|
|
if hasattr(control, "SetValue"): return getattr(control, "SetValue")(text)
|
|
|
|
elif hasattr(control, "SetLabel"): return getattr(control, "SetLabel")(text)
|
|
|
|
elif hasattr(control, "ChangeValue"): return getattr(control, "ChangeValue")(text)
|
|
|
|
else: return -1
|
|
|
|
else: return 0
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
self.Destroy()
|
|
|
|
|
|
|
|
def set_title(self, title):
|
|
|
|
self.SetTitle(title)
|
|
|
|
|
|
|
|
def get_title(self):
|
|
|
|
return self.GetTitle()
|
|
|
|
|
2015-04-03 16:57:08 -06:00
|
|
|
class mainLoopObject(wx.App):
|
2015-03-31 17:46:15 -06:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.app = wx.App()
|
2015-08-16 08:42:17 -05:00
|
|
|
self.lc = wx.Locale()
|
|
|
|
lang=languageHandler.getLanguage()
|
|
|
|
wxLang=self.lc.FindLanguageInfo(lang)
|
|
|
|
if not wxLang and '_' in lang:
|
|
|
|
wxLang=self.lc.FindLanguageInfo(lang.split('_')[0])
|
|
|
|
if hasattr(sys,'frozen'):
|
|
|
|
self.lc.AddCatalogLookupPathPrefix(paths.app_path("locales"))
|
|
|
|
if wxLang:
|
|
|
|
self.lc.Init(wxLang.Language)
|
2015-03-31 17:46:15 -06:00
|
|
|
|
2015-04-03 16:57:08 -06:00
|
|
|
def run(self):
|
2015-03-31 17:46:15 -06:00
|
|
|
self.app.MainLoop()
|
|
|
|
|