def select_open_file(parent, msg="Select a file", **kwargs): wildcard = kwargs.pop("wildcard", DEFAULT_WILDCARD) style = kwargs.pop("style", wx.OPEN) multi = kwargs.pop("multi", False) if multi: style |= wx.MULTIPLE if kwargs.pop("exist", True): style |= wx.FILE_MUST_EXIST if kwargs.pop("change_dir", False): style |= wx.CHANGE_DIR t = kwargs.pop("t", None) dlg = wx.FileDialog( parent, message=wdu.ttt(msg, t), defaultDir=kwargs.pop("default_dir", ""), defaultFile=kwargs.pop("default_file", ""), wildcard=wdu.ttt(wildcard, t), style=style, name=kwargs.pop("name", "wxFileDialog"), **kwargs ) paths = dlg.GetPaths() if dlg.ShowModal() == wx.ID_OK else [] dlg.Destroy() if paths: return paths if multi else paths[0] return None
def quick_choice(parent=None, msg="Please select", **kwargs): t = kwargs.pop("t", None) caption = kwargs.pop("caption", "Please select") choices = kwargs.pop("choices", []) valid_choices = kwargs.pop("valid_choices", []) style = kwargs.pop("style", wx.CHOICEDLG_STYLE) dlg = wx.SingleChoiceDialog(parent, wdu.ttt(msg, t), wdu.ttt(caption, t), choices, style) ok_label = kwargs.pop("ok_label", None) cancel_label = kwargs.pop("cancel_label", None) # update button labels for i18n try: btn_sizer = dlg.Sizer.GetChildren()[2].Sizer.GetChildren()[1].Sizer items = btn_sizer.GetChildren() ok_btn, c_btn = items[1].GetWindow(), items[2].GetWindow() ok_btn.SetLabel(wdu.ttt(ok_label or ok_btn.GetLabel(), t)) c_btn.SetLabel(wdu.ttt(cancel_label or c_btn.GetLabel(), t)) except: pass while 1: if dlg.ShowModal() == wx.ID_OK: selected = dlg.GetStringSelection() if selected in valid_choices: dlg.Destroy() return selected continue break dlg.Destroy() return None
def select_open_file(parent, msg='Select a file', **kwargs): wildcard = kwargs.pop('wildcard', DEFAULT_WILDCARD) style = kwargs.pop('style', wx.FD_OPEN) multi = kwargs.pop('multi', False) if multi: style |= wx.FD_MULTIPLE if kwargs.pop('exist', True): style |= wx.FD_FILE_MUST_EXIST if kwargs.pop('change_dir', False): style |= wx.FD_CHANGE_DIR t = kwargs.pop('t', None) dlg = wx.FileDialog(parent, message=wdu.ttt(msg, t), defaultDir=kwargs.pop('default_dir', ''), defaultFile=kwargs.pop('default_file', ''), wildcard=wdu.ttt(wildcard, t), style=style, name=kwargs.pop('name', 'wxFileDialog'), **kwargs) paths = dlg.GetPaths() if dlg.ShowModal() == wx.ID_OK else [] dlg.Destroy() if paths: return paths if multi else paths[0] return None
def quick_entry(parent=None, caption='', msg='Enter', password=True, **kwargs): entry_cls = wx.PasswordEntryDialog if password else wx.TextEntryDialog t = kwargs.pop('t', None) root_pass = kwargs.pop('root_pass', 'guess') ok_label = kwargs.pop('ok_label', None) cancel_label = kwargs.pop('cancel_label', None) font = wxu.auto_get_font(parent, **kwargs) dlg = entry_cls(parent, wdu.ttt(msg, t), wdu.ttt(caption, t)) # update button labels for i18n try: sizers = dlg.Sizer.GetChildren() msg_wgt = sizers[0].Sizer.GetChildren()[0].GetWindow() # text_wgt = sizers[1].GetWindow() sizers2 = sizers[2].Sizer.GetChildren() # line_wgt = sizers2[0].GetWindow() btn_sizer = sizers2[1].Sizer items = btn_sizer.GetChildren() ok_btn, c_btn = items[1].GetWindow(), items[2].GetWindow() ok_btn.SetLabel(wdu.ttt(ok_label or ok_btn.GetLabel(), t)) c_btn.SetLabel(wdu.ttt(cancel_label or c_btn.GetLabel(), t)) [set_font(wgt, font) for wgt in (msg_wgt, ok_btn, c_btn)] except: pass size = dlg.GetClientSize() dlg.SetMinClientSize(size) dlg.SetMaxClientSize(size) dlg.SetValue(kwargs.pop('value', '')) set_font(dlg, font) while 1: dlg.SetFocus() if dlg.ShowModal() == wx.ID_OK: text = dlg.GetValue() if password: if text == root_pass: dlg.Destroy() return True else: text = text.strip() if text: dlg.Destroy() return text dlg.SetValue('') dlg.SetFocus() continue dlg.Destroy() return False if password else ''
def quick_about(*args, **kwargs): fmt = kwargs.pop('fmt', ABOUT_FORMAT) t = kwargs.get('t', None) copyright = kwargs.pop('copyright', wdu.get_copy_right()) authors = kwargs.pop('author', None) writers = kwargs.pop('writers', None) remark = kwargs.pop('remark', 'about this tool') description = fmt.format(wdu.ttt(remark, t), sys.version.split()[0], wx.VERSION_STRING, ', '.join(wx.PlatformInfo[1:]), wdu.get_platform_info()) if authors: if not isinstance(authors, list): authors = [authors] kwargs.update(developers=authors) if writers: if not isinstance(writers, list): writers = [writers] kwargs.update(doc_writers=writers) about_info = dict(description=description, copyright=copyright.replace('&', '&&'), **kwargs) about_box(**about_info)
def select_open_dir(parent, title="Select a directory", **kwargs): t = kwargs.pop("t", None) style = kwargs.pop("style", wx.DD_DEFAULT_STYLE) dlg = wx.DirDialog(parent, wdu.ttt(title, t), style=style, **kwargs) folder = dlg.GetPath() if dlg.ShowModal() == wx.ID_OK else None dlg.Destroy() return folder
def select_open_dir(parent, title='Select a directory', **kwargs): t = kwargs.pop('t', None) style = kwargs.pop('style', wx.DD_DEFAULT_STYLE) dlg = wx.DirDialog(parent, wdu.ttt(title, t), style=style, **kwargs) folder = dlg.GetPath() if dlg.ShowModal() == wx.ID_OK else None dlg.Destroy() return folder
def cat_echo_text(**kwargs): args = kwargs.get('args') kargs = kwargs.get('kargs') t = kwargs.get('t') text = kwargs.get('text', '') if text: if kargs: return wdu.ttt(text, t).format(**kargs) if args: if not isinstance(args, (tuple, list)): args = (args, ) return wdu.ttt(text, t).format(*args) return wdu.ttt(text, t) return text
def select_save_file(parent, msg='Save file as...', **kwargs): wildcard = kwargs.pop('wildcard', DEFAULT_WILDCARD) style = kwargs.pop('style', wx.FD_SAVE) if kwargs.pop('overwrite_prompt', True): style |= wx.FD_OVERWRITE_PROMPT if kwargs.pop('change_dir', False): style |= wx.FD_CHANGE_DIR t = kwargs.pop('t', None) dlg = wx.FileDialog(parent, message=wdu.ttt(msg, t), defaultDir=kwargs.pop('default_dir', ''), defaultFile=kwargs.pop('default_file', ''), wildcard=wdu.ttt(wildcard, t), style=style, **kwargs) path = dlg.GetPath() if dlg.ShowModal() == wx.ID_OK else None dlg.Destroy() return path
def add_path_picker(parent, id=-1, msg="Select a directory", **kwargs): t = kwargs.pop("t", None) kind = kwargs.pop("kind", "dir") tooltip = kwargs.pop("tooltip", "") multiline = kwargs.pop("multiline", False) btn_label = kwargs.pop("btn_label", "") size = kwargs.pop("size", (-1, -1)) prop = kwargs.pop("prop", 2) use_tc = kwargs.pop("use_tc", True) value = kwargs.pop("value", "") text_editable = kwargs.pop("text_editable", False) btn_enable = kwargs.pop("btn_enable", True) tc_bg = kwargs.pop("tc_bg", "white") tc_name = kwargs.pop("tc_name", "wxTextCtrl") btn_name = kwargs.pop("btn_name", "wxButton") wgt_cls = wx.DirPickerCtrl if kind == "dir" else wx.FilePickerCtrl if use_tc: kwargs.update(style=wx.DIRP_USE_TEXTCTRL) pc = wgt_cls( parent, id, message=wdu.ttt(msg, t), size=size, path=value, name=kwargs.pop("name", "wxDirPickerCtrl"), **kwargs ) if pc.HasTextCtrl(): pc.SetTextCtrlProportion(prop) tc, btn = pc.Sizer.GetChildren() tc = tc.GetWindow() btn = btn.GetWindow() if multiline: tc.SetWindowStyle(wx.TE_MULTILINE) btn.SetLabel(wdu.ttt(btn_label or btn.GetLabel(), t)) if tooltip: tooltip = wdu.ttt(tooltip, t) set_tooltip(tc, tooltip) set_tooltip(btn, tooltip) tc.SetEditable(text_editable) set_bg(tc, tc_bg) btn.Enable(btn_enable) tc.SetName(tc_name) btn.SetName(btn_name) return pc, tc, btn
def add_path_picker(parent, id=-1, msg='Select a directory', **kwargs): t = kwargs.pop('t', None) kind = kwargs.pop('kind', 'dir') tooltip = kwargs.pop('tooltip', '') multiline = kwargs.pop('multiline', False) btn_label = kwargs.pop('btn_label', '') size = kwargs.pop('size', (-1, -1)) prop = kwargs.pop('prop', 2) use_tc = kwargs.pop('use_tc', True) value = kwargs.pop('value', '') text_editable = kwargs.pop('text_editable', False) btn_enable = kwargs.pop('btn_enable', True) tc_bg = kwargs.pop('tc_bg', 'white') tc_name = kwargs.pop('tc_name', 'wxTextCtrl') btn_name = kwargs.pop('btn_name', 'wxButton') wgt_cls = wx.DirPickerCtrl if kind == 'dir' else wx.FilePickerCtrl if use_tc: kwargs.update(style=wx.DIRP_USE_TEXTCTRL) pc = wgt_cls(parent, id, message=wdu.ttt(msg, t), size=size, path=value, name=kwargs.pop('name', 'wxDirPickerCtrl'), **kwargs) if pc.HasTextCtrl(): pc.SetTextCtrlProportion(prop) tc, btn = pc.Sizer.GetChildren() tc = tc.GetWindow() btn = btn.GetWindow() if multiline: tc.SetWindowStyle(wx.TE_MULTILINE) btn.SetLabel(wdu.ttt(btn_label or btn.GetLabel(), t)) if tooltip: tooltip = wdu.ttt(tooltip, t) set_tooltip(tc, tooltip) set_tooltip(btn, tooltip) tc.SetEditable(text_editable) set_bg(tc, tc_bg) btn.Enable(btn_enable) tc.SetName(tc_name) btn.SetName(btn_name) tc.SetInsertionPoint(0) return pc, tc, btn
def quick_choice(parent=None, msg='Please select', **kwargs): t = kwargs.pop('t', None) caption = kwargs.pop('caption', 'Please select') choices = kwargs.pop('choices', []) valid_choices = kwargs.pop('valid_choices', []) style = kwargs.pop('style', wx.CHOICEDLG_STYLE) dlg = wx.SingleChoiceDialog(parent, wdu.ttt(msg, t), wdu.ttt(caption, t), choices, style) font = wxu.auto_get_font(parent, **kwargs) set_font(dlg, font) ok_label = kwargs.pop('ok_label', None) cancel_label = kwargs.pop('cancel_label', None) # update button labels for i18n try: sizers = dlg.Sizer.GetChildren() msg_wgt = sizers[0].Sizer.GetChildren()[0].GetWindow() # listbox = sizers[1].GetWindow() sizers2 = sizers[0].Sizer.GetChildren() # line = sizers2[0].GetWindow() btn_sizer = sizers2[1].Sizer items = btn_sizer.GetChildren() ok_btn, c_btn = items[1].GetWindow(), items[2].GetWindow() ok_btn.SetLabel(wdu.ttt(ok_label or ok_btn.GetLabel(), t)) c_btn.SetLabel(wdu.ttt(cancel_label or c_btn.GetLabel(), t)) set_font(msg_wgt, font) set_font(ok_btn, font) set_font(c_btn, font) except: pass while 1: if dlg.ShowModal() == wx.ID_OK: selected = dlg.GetStringSelection() if selected in valid_choices: dlg.Destroy() return selected continue break dlg.Destroy() return None
def quick_entry(parent=None, caption="", msg="Enter", password=True, **kwargs): entry_cls = wx.PasswordEntryDialog if password else wx.TextEntryDialog t = kwargs.pop("t", None) root_pass = kwargs.pop("root_pass", "guess") ok_label = kwargs.pop("ok_label", None) cancel_label = kwargs.pop("cancel_label", None) dlg = entry_cls(parent, wdu.ttt(msg, t), wdu.ttt(caption, t)) # update button labels for i18n try: btn_sizer = dlg.Sizer.GetChildren()[2].Sizer.GetChildren()[1].Sizer items = btn_sizer.GetChildren() ok_btn, c_btn = items[1].GetWindow(), items[2].GetWindow() ok_btn.SetLabel(wdu.ttt(ok_label or ok_btn.GetLabel(), t)) c_btn.SetLabel(wdu.ttt(cancel_label or c_btn.GetLabel(), t)) except: pass size = dlg.GetClientSize() dlg.SetMinClientSize(size) dlg.SetMaxClientSize(size) dlg.SetValue(kwargs.pop("value", "")) while 1: dlg.SetFocus() if dlg.ShowModal() == wx.ID_OK: text = dlg.GetValue() if password: if text == root_pass: dlg.Destroy() return True else: text = text.strip() if text: dlg.Destroy() return text dlg.SetValue("") dlg.SetFocus() continue dlg.Destroy() return False if password else ""
def add_statusbar(obj, widths=[-1, 170, 160], values=['', '', ''], **kwargs): t = kwargs.pop('t', None) sbar = obj.CreateStatusBar(len(widths)) sbar.SetStatusWidths(widths) for i, v in enumerate(values): if v is None: continue sbar.SetStatusText(wdu.ttt(v, t), i) return sbar
def add_statusbar(obj, widths=[-1, 170, 160], values=["", "", ""], **kwargs): t = kwargs.pop("t", None) sbar = obj.CreateStatusBar(len(widths)) sbar.SetStatusWidths(widths) for i, v in enumerate(values): if v is None: continue sbar.SetStatusText(wdu.ttt(v, t), i) return sbar
def about_box(**kwargs): t = kwargs.pop('t', None) info = AboutDialogInfo() icon = kwargs.pop('icon', None) icon_fmt = kwargs.pop('icon_fmt', None) if icon: if isinstance(icon, six.string_types): args = [icon] if icon_fmt: args.append(icon_fmt) info.SetIcon(wx.Icon(*args)) else: info.SetIcon(icon) # may be PyEmbeddedImage name = kwargs.pop('name', 'app name') version = kwargs.pop('version', '0.1') description = kwargs.pop('description', 'description') copyright = kwargs.pop('copyright', 'copyright') info.SetName(wdu.ttt(name, t)) info.SetVersion(wdu.ttt(version, t)) info.SetDescription(wdu.ttt(description, t)) info.SetCopyright(wdu.ttt(copyright, t)) website = kwargs.pop('website', '') if website: info.SetWebSite(website) licence = kwargs.pop('licence', '') if licence: info.SetLicence(licence) developers = kwargs.pop('developers', []) doc_writers = kwargs.pop('doc_writers', []) artists = kwargs.pop('artists', []) tranlators = kwargs.pop('tranlators', []) [info.AddDeveloper(developer) for developer in developers] [info.AddDocWriter(writer) for writer in doc_writers] [info.AddArtist(artist) for artist in artists] [info.AddTranslator(tranlator) for tranlator in tranlators] AboutBox(info)
def about_box(**kwargs): t = kwargs.pop("t", None) info = wx.AboutDialogInfo() icon = kwargs.pop("icon", None) icon_fmt = kwargs.pop("icon_fmt", None) if icon: if isinstance(icon, basestring): args = [icon] if icon_fmt: args.append(icon_fmt) info.SetIcon(wx.Icon(*args)) else: info.SetIcon(icon) # may be PyEmbeddedImage name = kwargs.pop("name", "app name") version = kwargs.pop("version", "0.1") description = kwargs.pop("description", "description") copyright = kwargs.pop("copyright", "copyright") info.SetName(wdu.ttt(name, t)) info.SetVersion(wdu.ttt(version, t)) info.SetDescription(wdu.ttt(description, t)) info.SetCopyright(wdu.ttt(copyright, t)) website = kwargs.pop("website", "") if website: info.SetWebSite(website) licence = kwargs.pop("licence", "") if licence: info.SetLicence(licence) developers = kwargs.pop("developers", []) doc_writers = kwargs.pop("doc_writers", []) artists = kwargs.pop("artists", []) tranlators = kwargs.pop("tranlators", []) [info.AddDeveloper(developer) for developer in developers] [info.AddDocWriter(writer) for writer in doc_writers] [info.AddArtist(artist) for artist in artists] [info.AddTranslator(tranlator) for tranlator in tranlators] wx.AboutBox(info)
def select_save_file(parent, msg="Save file as...", **kwargs): wildcard = kwargs.pop("wildcard", DEFAULT_WILDCARD) style = kwargs.pop("style", wx.SAVE) if kwargs.pop("overwrite_prompt", True): style |= wx.OVERWRITE_PROMPT if kwargs.pop("change_dir", False): style |= wx.CHANGE_DIR t = kwargs.pop("t", None) dlg = wx.FileDialog( parent, message=wdu.ttt(msg, t), defaultDir=kwargs.pop("default_dir", ""), defaultFile=kwargs.pop("default_file", ""), wildcard=wdu.ttt(wildcard, t), style=style, **kwargs ) path = dlg.GetPath() if dlg.ShowModal() == wx.ID_OK else None dlg.Destroy() return path
def __init__(self, frame, icon=None, text='TrayIcon', **kwargs): self.t = kwargs.get('t') TaskBarIcon.__init__(self) self.frame = frame if icon: if not isinstance(icon, six.string_types): icon = self.make_icon(icon) self.SetIcon(icon, wdu.ttt(text, self.t)) self.Bind(EVT_TASKBAR_LEFT_DOWN, self.on_restore) self.Bind(wx.EVT_MENU, self.on_restore, id=self.restore_id) self.Bind(wx.EVT_MENU, self.on_quit, id=self.quit_id)
def __init__(self, frame, icon=None, text="TrayIcon", **kwargs): self.t = kwargs.get("t") wx.TaskBarIcon.__init__(self) self.frame = frame if icon: if not isinstance(icon, basestring): icon = self.make_icon(icon) self.SetIcon(icon, wdu.ttt(text, self.t)) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_restore) self.Bind(wx.EVT_MENU, self.on_restore, id=self.restore_id) self.Bind(wx.EVT_MENU, self.on_quit, id=self.quit_id)
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 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 add_radio_box(parent, sizer=None, **kwargs): t = kwargs.pop('t', None) label = kwargs.pop('label', '') size = kwargs.pop('size', (-1, -1)) style = kwargs.pop('style', wx.RA_SPECIFY_COLS) choices = kwargs.pop('choices', []) cols = kwargs.pop('cols', 0) tooltip = kwargs.pop('tooltip', '') value = kwargs.pop('value', 0) wgt = wx.RadioBox(parent, -1, wdu.ttt(label, t), size=size, choices=choices, majorDimension=cols, style=style, name=kwargs.pop('name', 'wxRadioBox')) wgt.SetSelection(int(value)) set_tooltip(wgt, tooltip, t) pack(wgt, sizer, **kwargs) return wgt
def add_checkbox(parent, id=-1, **kwargs): t = kwargs.pop("t", None) label = kwargs.pop("label", "") size = kwargs.pop("size", (-1, -1)) value = kwargs.pop("value", True) font = kwargs.pop("font", None) tooltip = kwargs.pop("tooltip", "") fg = kwargs.pop("fg", None) bg = kwargs.pop("bg", None) wgt = wx.CheckBox(parent, id, wdu.ttt(label, t), size=size, name=kwargs.pop("name", "wxCheckBox")) set_tooltip(wgt, tooltip, t) set_font(wgt, font) set_fg(wgt, fg) set_bg(wgt, bg) wgt.SetValue(value) return wgt
def quick_about(*args, **kwargs): fmt = kwargs.pop("fmt", "{}\n\nPlatform:\nPython {}\nwxPython {} ({})\n{}\n\n") t = kwargs.get("t", None) copyright = kwargs.pop("copyright", wdu.get_copy_right()) author = kwargs.pop("author", "") remark = kwargs.pop("remark", "about this tool") description = fmt.format( wdu.ttt(remark, t), sys.version.split()[0], wx.VERSION_STRING, ", ".join(wx.PlatformInfo[1:]), wdu.get_platform_info(), ) if author: kwargs.update(developers=[author], doc_writers=[author]) about_info = dict(description=description, copyright=copyright.replace("&", "&&"), **kwargs) about_box(**about_info)
def add_checkbox(parent, id=-1, **kwargs): t = kwargs.pop('t', None) label = kwargs.pop('label', '') size = kwargs.pop('size', (-1, -1)) value = kwargs.pop('value', True) font = kwargs.pop('font', None) tooltip = kwargs.pop('tooltip', '') fg = kwargs.pop('fg', None) bg = kwargs.pop('bg', None) wgt = wx.CheckBox(parent, id, wdu.ttt(label, t), size=size, name=kwargs.pop('name', 'wxCheckBox'), style=kwargs.pop('style', 0)) set_tooltip(wgt, tooltip, t) set_font(wgt, font) set_fg(wgt, fg) set_bg(wgt, bg) wgt.SetValue(value) return wgt
def write_echo_text(**kwargs): ts_text = kwargs.get('ts_text') text = kwargs.get('text', '') t = kwargs.get('t') if kwargs.get('tff') and t: # t for file text = wdu.ttt(text, t) if isinstance(text, unicode): text = text.encode('utf-8') nl = kwargs.get('nl', True) log_mode = kwargs.get('log_mode', 'a') for log_file in kwargs.get('log_files', []): with open(log_file, log_mode) as f: if ts_text: f.write(ts_text) f.write(text) if nl: f.write('\n')
def add_button(parent, id=-1, **kwargs): t = kwargs.pop("t", None) label = kwargs.pop("label", "Button") size = kwargs.pop("size", (-1, -1)) tooltip = kwargs.pop("tooltip", "") font = kwargs.pop("font", None) fg = kwargs.pop("fg", None) bg = kwargs.pop("bg", None) icon = kwargs.pop("icon", None) style = kwargs.pop("style", wx.NO_BORDER) btn = wx.Button(parent, id, wdu.ttt(label, t), size=size, name=kwargs.get("name", "wxButton"), style=style) set_tooltip(btn, tooltip, t=t) set_font(btn, font) set_fg(btn, fg) set_bg(btn, bg) if icon: btn.SetBitmap(icon, kwargs.get("side", wx.LEFT)) btn.SetBitmapMargins(kwargs.get("margins", (2, 2))) return btn
def add_label(parent, id=-1, **kwargs): t = kwargs.get('t') label = kwargs.pop('label', '') font = kwargs.pop('font', None) size = kwargs.pop('size', (-1, -1)) tooltip = kwargs.pop('tooltip', '') fg = kwargs.pop('fg', None) bg = kwargs.pop('bg', None) style = kwargs.pop('style', None) nargs = dict(size=size, name=kwargs.get('name', 'wxStaticText')) if style: nargs.update(style=style) lbl = wx.StaticText(parent, id, wdu.ttt(label, t), **nargs) set_tooltip(lbl, tooltip, t) set_font(lbl, font) set_fg(lbl, fg) set_bg(lbl, bg) return lbl
def add_label(parent, id=-1, **kwargs): t = kwargs.get("t") label = kwargs.pop("label", "") font = kwargs.pop("font", None) size = kwargs.pop("size", (-1, -1)) tooltip = kwargs.pop("tooltip", "") fg = kwargs.pop("fg", None) bg = kwargs.pop("bg", None) style = kwargs.pop("style", None) nargs = dict(size=size, name=kwargs.get("name", "wxStaticText")) if style: nargs.update(style=style) lbl = wx.StaticText(parent, id, wdu.ttt(label, t), **nargs) set_tooltip(lbl, tooltip, t) set_font(lbl, font) set_fg(lbl, fg) set_bg(lbl, bg) return lbl
def __init__(self, parent=None, title='User Login', size=(500, 240), style=wx.CAPTION | wx.STAY_ON_TOP, root_user='******', root_pass='******', last_user='', password='', domains=[], server='', base_dn='', destroy=True, **kwargs): self.t = kwargs.get('t') self.enable_cancel = kwargs.get('enable_cancel', True) super(LoginWindow, self).__init__(parent, title=wdu.ttt(title, self.t), size=size, style=style) self.panel = wx.Panel(self) self.root_user = root_user self.root_pass = root_pass self.last_user = last_user self.pwd = password self.current_user = None self.domains = domains or [''] self.server = server self.base_dn = base_dn self.destroy = destroy font = self.GetFont() font.SetWeight(wx.BOLD) font.SetPointSize(13) self.panel.SetFont(font) self.init_ui() self.panel.Layout() self.Bind(wx.EVT_BUTTON, self.on_login, id=wx.ID_OK) self.Bind(wx.EVT_BUTTON, self.on_quit, id=wx.ID_CANCEL) self.CenterOnScreen() self.Refresh() self.ShowModal()
def add_radio_box(parent, sizer=None, **kwargs): t = kwargs.pop("t", None) label = kwargs.pop("label", "") size = kwargs.pop("size", (-1, -1)) style = kwargs.pop("style", wx.RA_SPECIFY_COLS) choices = kwargs.pop("choices", []) cols = kwargs.pop("cols", 0) tooltip = kwargs.pop("tooltip", "") value = kwargs.pop("value", 0) wgt = wx.RadioBox( parent, -1, wdu.ttt(label, t), size=size, choices=choices, majorDimension=cols, style=style, name=kwargs.pop("name", "wxRadioBox"), ) wgt.SetSelection(int(value)) set_tooltip(wgt, tooltip, t) pack(wgt, sizer, **kwargs) return wgt
def add_button(parent, id=-1, **kwargs): t = kwargs.pop('t', None) label = kwargs.pop('label', 'Button') size = kwargs.pop('size', (-1, -1)) tooltip = kwargs.pop('tooltip', '') font = kwargs.pop('font', None) fg = kwargs.pop('fg', None) bg = kwargs.pop('bg', None) icon = kwargs.pop('icon', None) style = kwargs.pop('style', wx.NO_BORDER) kw = dict(size=size, name=kwargs.get('name', 'wxButton')) if style: kw.update(style=style) btn = wx.Button(parent, id, wdu.ttt(label, t), **kw) set_tooltip(btn, tooltip, t=t) set_font(btn, font) set_fg(btn, fg) set_bg(btn, bg) if icon: btn.SetBitmap(icon, kwargs.get('side', wx.LEFT)) btn.SetBitmapMargins(kwargs.get('margins', (2, 2))) return btn
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 tt(self, text): return wdu.ttt(text, self.t)
def set_tooltip(wgt, tooltip='', t=None): if tooltip: func = wgt.SetToolTipString if OLD_WX else wgt.SetToolTip func(wdu.ttt(tooltip, t=t))
def set_tooltip(wgt, tooltip="", t=None): if tooltip: wgt.SetToolTipString(wdu.ttt(tooltip, t=t))
def add_staticbox(parent, id=-1, label='', orient='v', **kwargs): sbox = wx.StaticBox(parent, id, wdu.ttt(label, kwargs.pop('t', None)), name=kwargs.pop('name', 'wxStaticBox')) style = wx.VERTICAL if orient == 'v' else wx.HORIZONTAL sbsizer = wx.StaticBoxSizer(sbox, style) return sbox, sbsizer
def CreatePopupMenu(self): menu = wx.Menu() menu.Append(self.restore_id, wdu.ttt('Restore', self.t)) menu.AppendSeparator() menu.Append(self.quit_id, wdu.ttt('Quit', self.t)) return menu
def add_staticbox(parent, id=-1, label="", orient="v", **kwargs): sbox = wx.StaticBox(parent, id, wdu.ttt(label, kwargs.pop("t", None)), name=kwargs.pop("name", "wxStaticBox")) style = wx.VERTICAL if orient == "v" else wx.HORIZONTAL sbsizer = wx.StaticBoxSizer(sbox, style) return sbox, sbsizer
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 CreatePopupMenu(self): menu = wx.Menu() menu.Append(self.restore_id, wdu.ttt("Restore", self.t)) menu.AppendSeparator() menu.Append(self.quit_id, wdu.ttt("Quit", self.t)) return menu
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()