def popup(parent=None, caption="caption", **kwargs): t = kwargs.get("t") btn = kwargs.pop("btn", wx.OK) need_return = kwargs.pop("need_return", False) size = kwargs.pop("size", (-1, -1)) icon = kwargs.pop("icon", "i") msg = kwargs.pop("msg", "") icon = ICONS.get(icon, ICONS["i"]) if isinstance(msg, basestring): if not isinstance(msg, unicode): umsg = msg.decode(wdu.detect_encoding(msg)["encoding"]) else: umsg = msg else: umsg = "{}".format(msg) if t: umsg = wdu.ttt(umsg, t) title = wdu.ttt(caption, t) else: title = caption dlg = gmd.GenericMessageDialog(parent, umsg, title, btn | icon, size=size) help_label = kwargs.get("help_label", "Help") ok_label = kwargs.get("ok_label", "OK") cancel_label = kwargs.get("cancel_label", "Cancel") yes_label = kwargs.get("yes_label", "Yes") no_label = kwargs.get("no_label", "No") if t: help_label = wdu.ttt(help_label, t) ok_label = wdu.ttt(ok_label, t) cancel_label = wdu.ttt(cancel_label, t) yes_label = wdu.ttt(yes_label, t) no_label = wdu.ttt(no_label, t) dlg.SetHelpLabel(help_label) dlg.SetOKLabel(ok_label) dlg.SetOKCancelLabels(ok_label, cancel_label) dlg.SetYesNoLabels(yes_label, no_label) dlg.SetYesNoCancelLabels(yes_label, no_label, cancel_label) dlg.SetMessage(umsg) if need_return: return dlg dlg.CenterOnParent() result = dlg.ShowModal() dlg.Destroy() return result
def popup_smd(parent=None, msg='', caption='Message', **kwargs): t = kwargs.get('t') btn_label = kwargs.get('btn_label', 'OK') if isinstance(msg, six.string_types): if not isinstance(msg, six.text_type): umsg = msg.decode(wdu.detect_encoding(msg)['encoding']) else: umsg = msg else: umsg = '{}'.format(msg) if t: btn_label = wdu.ttt(btn_label, t) umsg = wdu.ttt(umsg, t) title = wdu.ttt(caption, t) else: title = caption font = wxu.auto_get_font(parent, **kwargs) dlg = wx.lib.dialogs.ScrolledMessageDialog(parent, umsg, title) try: dlg.GetChildren()[1].SetLabel(btn_label) set_font() except: pass if parent and hasattr(parent, 'opened_dlg'): if parent.opened_dlg is not None: parent.opened_dlg += 1 set_font(dlg, font) dlg.ShowModal() if parent and hasattr(parent, 'opened_dlg'): if parent.opened_dlg is not None: parent.opened_dlg -= 1 dlg.Destroy()
def echo_text(rtc, text='', fg=None, bg=None, ts=True, nl=True, italic=False, align=None, underline=False, bold=False, ts_style=False, font=None, size=None, clear=False, keep_date=True, **kwargs): if ts: now = datetime.now() if keep_date: ts_text = '[{}] '.format(now) else: ts_text = '[{}] '.format(str(now).split(' ', 1)[-1]) else: ts_text = '' if text and isinstance(text, six.string_types): if not isinstance(text, six.text_type): utext = text.decode(wdu.detect_encoding(text)['encoding']) else: utext = text else: utext = '{}'.format(text) write_echo_text(ts_text=ts_text, text=utext, nl=nl, **kwargs) if kwargs.get('no_echo', False): if clear: rtc.Clear() return rtc.SetInsertionPointEnd() rta = rt.RichTextAttr() rta.SetAlignment(RTC_ALIGNS['default']) rta.SetTextColour('black') rta.SetBackgroundColour('white') rta.SetFontStyle(wx.FONTSTYLE_NORMAL) rta.SetFontWeight(wx.FONTWEIGHT_NORMAL) rta.SetFontUnderlined(False) rtc.SetDefaultStyle(rta) if ts_text and not ts_style: rtc.WriteText(ts_text) align = RTC_ALIGNS.get(align) if align: rta.SetAlignment(align) if fg: rta.SetTextColour(fg) if bg: rta.SetBackgroundColour(bg) if font: rta.SetFontFaceName(font) if size: rta.SetFontSize(size) if bold is True: rta.SetFontWeight(wx.FONTWEIGHT_BOLD) elif bold is False: rta.SetFontWeight(wx.FONTWEIGHT_NORMAL) if italic is True: rta.SetFontStyle(wx.FONTSTYLE_ITALIC) elif italic is False: rta.SetFontStyle(wx.FONTSTYLE_NORMAL) if underline is not None: rta.SetFontUnderlined(underline) rtc.BeginStyle(rta) if ts_text and ts_style: rtc.WriteText(ts_text) rtc.WriteText(cat_echo_text(text=utext, **kwargs)) rtc.EndStyle() if nl: rtc.Newline() rtc.ShowPosition(rtc.GetLastPosition()) if clear: rtc.Clear()
def popup(parent=None, caption='caption', **kwargs): t = kwargs.get('t') font = wxu.auto_get_font(parent, **kwargs) btn = kwargs.pop('btn', wx.OK) need_return = kwargs.pop('need_return', False) size = kwargs.pop('size', (-1, -1)) icon = kwargs.pop('icon', 'i') msg = kwargs.pop('msg', '') icon = ICONS.get(icon, ICONS['i']) if isinstance(msg, six.string_types): if not isinstance(msg, six.text_type): umsg = msg.decode(wdu.detect_encoding(msg)['encoding']) else: umsg = msg else: umsg = '{}'.format(msg) if t: umsg = wdu.ttt(umsg, t) title = wdu.ttt(caption, t) else: title = caption dlg_kw = dict() if OLD_WX: dlg_cls = gmd.GenericMessageDialog dlg_kw.update(size=size) else: dlg_cls = wx.MessageDialog dlg = dlg_cls(parent, umsg, title, btn | icon, **dlg_kw) help_label = kwargs.get('help_label', 'Help') ok_label = kwargs.get('ok_label', 'OK') cancel_label = kwargs.get('cancel_label', 'Cancel') yes_label = kwargs.get('yes_label', 'Yes') no_label = kwargs.get('no_label', 'No') if t: help_label = wdu.ttt(help_label, t) ok_label = wdu.ttt(ok_label, t) cancel_label = wdu.ttt(cancel_label, t) yes_label = wdu.ttt(yes_label, t) no_label = wdu.ttt(no_label, t) dlg.SetHelpLabel(help_label) dlg.SetOKLabel(ok_label) dlg.SetOKCancelLabels(ok_label, cancel_label) dlg.SetYesNoLabels(yes_label, no_label) dlg.SetYesNoCancelLabels(yes_label, no_label, cancel_label) dlg.SetMessage(umsg) set_font(dlg, font) if need_return: return dlg dlg.CenterOnParent() opened_dlg = False if parent and hasattr(parent, 'opened_dlg'): if parent.opened_dlg is not None: opened_dlg = True if opened_dlg: parent.opened_dlg += 1 result = dlg.ShowModal() dlg.Destroy() if opened_dlg: parent.opened_dlg -= 1 return result
def echo_text(rtc, text='', fg=None, bg=None, ts=True, nl=True, italic=False, align=None, underline=False, bold=False, ts_style=False, font=None, size=None, clear=False, **kwargs): t = kwargs.get('t', None) ts_text = '[{}] '.format(datetime.now()) if ts else '' if isinstance(text, basestring): if not isinstance(text, unicode): utext = text.decode(wdu.detect_encoding(text)['encoding']) else: utext = text else: utext = '{}'.format(text) write_echo_text(ts_text=ts_text, text=utext, nl=nl, **kwargs) if kwargs.get('no_echo', False): if clear: rtc.Clear() return rtc.SetInsertionPointEnd() rta = rt.RichTextAttr() rta.SetAlignment(RTC_ALIGNS['default']) rta.SetTextColour('black') rta.SetBackgroundColour('white') rta.SetFontStyle(wx.FONTSTYLE_NORMAL) rta.SetFontWeight(wx.FONTWEIGHT_NORMAL) rta.SetFontUnderlined(False) rtc.SetDefaultStyle(rta) if ts_text and not ts_style: rtc.WriteText(ts_text) align = RTC_ALIGNS.get(align) if align: rta.SetAlignment(align) if fg: rta.SetTextColour(fg) if bg: rta.SetBackgroundColour(bg) if font: rta.SetFontFaceName(font) if size: rta.SetFontSize(size) if bold is True: rta.SetFontWeight(wx.FONTWEIGHT_BOLD) elif bold is False: rta.SetFontWeight(wx.FONTWEIGHT_NORMAL) if italic is True: rta.SetFontStyle(wx.FONTSTYLE_ITALIC) elif italic is False: rta.SetFontStyle(wx.FONTSTYLE_NORMAL) if underline is not None: rta.SetFontUnderlined(underline) rtc.BeginStyle(rta) if ts_text and ts_style: rtc.WriteText(ts_text) rtc.WriteText(wdu.ttt(utext, t)) rtc.EndStyle() if nl: rtc.Newline() rtc.ShowPosition(rtc.GetLastPosition()) if clear: rtc.Clear()
def popup_smd(parent=None, msg="", caption="Message", **kwargs): t = kwargs.get("t") btn_label = kwargs.get("btn_label", "OK") if isinstance(msg, basestring): if not isinstance(msg, unicode): umsg = msg.decode(wdu.detect_encoding(msg)["encoding"]) else: umsg = msg else: umsg = "{}".format(msg) if t: btn_label = wdu.ttt(btn_label, t) umsg = wdu.ttt(umsg, t) title = wdu.ttt(caption, t) else: title = caption dlg = wx.lib.dialogs.ScrolledMessageDialog(parent, umsg, title) try: dlg.GetChildren()[1].SetLabel(btn_label) except: pass dlg.ShowModal() dlg.Destroy()