def __init__(self, parent, conn): worldname = conn.world.get('name') wx.Dialog.__init__(self, parent, title="Debug MCP: " + worldname, style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) self.connection = conn self.output_pane = wx.TextCtrl(self, style=wx.TE_READONLY | wx.TE_NOHIDESEL | wx.TE_MULTILINE | wx.TE_RICH) self.addEvents() if (prefs.get('save_mcp_window_size')): w = prefs.get('mcp_window_width') or 600 h = prefs.get('mcp_window_height') or 400 self.SetSize([int(w), int(h)]) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.output_pane, 1, wx.ALL | wx.GROW, 5) self.SetSizer(sizer) self.connection.status_bar.feature_icons['MCP'].Bind( wx.EVT_LEFT_UP, self.toggle_visible)
def createGeneralPanel(self): gp = wx.Panel(self.book) gp.save_size_checkbox = wx.CheckBox(gp, -1, 'Save Window Size') gp.save_size_checkbox.SetValue(prefs.get('save_window_size')) gp.autoconnect_checkbox = wx.CheckBox( gp, -1, 'Autoconnect to last world at startup') gp.autoconnect_checkbox.SetValue(prefs.get('autoconnect_last_world')) gp.xmouse_checkbox = wx.CheckBox( gp, -1, 'Use X-style mouse copy/paste behavior') gp.xmouse_checkbox.SetValue(prefs.get('use_x_copy_paste')) gp.local_echo_checkbox = wx.CheckBox(gp, -1, 'Echo Typed Commands') gp.local_echo_checkbox.SetValue(prefs.get('local_echo')) gp.scroll_on_output_checkbox = wx.CheckBox( gp, -1, 'Scroll to bottom when new text arrives') gp.scroll_on_output_checkbox.SetValue(prefs.get('scroll_on_output')) gp.panel_sizer = wx.BoxSizer(wx.VERTICAL) gp.panel_sizer.Add(gp.save_size_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.autoconnect_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.xmouse_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.local_echo_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.scroll_on_output_checkbox, flag=wx.ALL, border=10) gp.SetSizer(gp.panel_sizer) return gp
def __init__(self, parent, conn): worldname = conn.world.get('name') wx.Dialog.__init__(self, parent, title="Debug MCP: " + worldname, style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE) self.active = False self.output_pane = None self.connection = conn self.addEvents() if (prefs.get('save_mcp_window_size')): w = prefs.get('mcp_window_width') or 600 h = prefs.get('mcp_window_height') or 400 self.SetSize([int(w), int(h)]) self.output_pane = DebugMCPPane(self) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.output_pane, 1, wx.ALL | wx.GROW, 5) self.SetSizer(sizer) # pre-stage monkey-patching self.connection.mcp.orig_debug = self.connection.mcp.debug
def createFontPanel(self): fcp = wx.Panel(self.book) font = wx.Font(prefs.get('font')) fgcolour = prefs.get('fgcolour') bgcolour = prefs.get('bgcolour') # output sample/controls fcp.sample = ExpandoTextCtrl(fcp, style=wx.TE_READONLY | wx.TE_RICH | wx.TE_MULTILINE, size=wx.Size(400, -1)) fcp.font_ctrl = wx.FontPickerCtrl(fcp, style=wx.FNTP_FONTDESC_AS_LABEL | wx.FNTP_USEFONT_FOR_LABEL, font=font) fcp.theme_picker = wx.Choice(fcp, choices=Theme.all_theme_names()) fcp.ansi_checkbox = wx.CheckBox(fcp, -1, 'Use ANSI colors') # TODO - get and set these two at display time not create time fcp.theme = prefs.get('theme') fcp.theme_picker.SetSelection(fcp.theme_picker.FindString(fcp.theme)) if prefs.get('use_ansi'): fcp.ansi_checkbox.SetValue(True) fcp.theme_picker.Enable() else: fcp.ansi_checkbox.SetValue(False) fcp.theme_picker.Disable() ansi_sizer = wx.BoxSizer(wx.HORIZONTAL) ansi_sizer.Add(fcp.ansi_checkbox, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER) ansi_sizer.Add(fcp.theme_picker, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER) panel_sizer = wx.BoxSizer(wx.VERTICAL) panel_sizer.Add(fcp.sample, 0, wx.RIGHT | wx.LEFT | wx.EXPAND | wx.TOP, 10) panel_sizer.AddSpacer(10) panel_sizer.Add(fcp.font_ctrl, 0, wx.EXPAND, 0) panel_sizer.AddSpacer(10) panel_sizer.Add(ansi_sizer, 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 10) self.Bind(wx.EVT_FONTPICKER_CHANGED, self.update_sample_text, fcp.font_ctrl) self.Bind(wx.EVT_CHOICE, self.update_sample_text, fcp.theme_picker) self.Bind(wx.EVT_CHECKBOX, self.update_sample_text, fcp.ansi_checkbox) self.Bind(EVT_ETC_LAYOUT_NEEDED, self.resize_everything, fcp.sample) fcp.SetSizer(panel_sizer) fcp.Layout() return fcp
def __init__(self, parent): wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL) self.SetTextColour(prefs.get("fgcolour")) self.SetBackgroundColour(prefs.get("bgcolour")) font = wx.NullFont font.SetNativeFontInfoFromString(prefs.get("font")) self.SetFont(font)
def createFontPanel(self): fcp = wx.Panel(self.book) font = wx.NullFont font.SetNativeFontInfoFromString(prefs.get('font')) fgcolour = prefs.get('fgcolour') bgcolour = prefs.get('bgcolour') # output sample/controls fcp.sample = wx.TextCtrl (fcp, style = wx.TE_READONLY) fcp.font_ctrl = wx.FontPickerCtrl(fcp, style = wx.FNTP_FONTDESC_AS_LABEL | wx.FNTP_USEFONT_FOR_LABEL) bsize = fcp.font_ctrl.GetSize().GetHeight() button_size = [bsize, bsize] fcp.fgcolour_ctrl = wx.ColourPickerCtrl(fcp, col = fgcolour, size = button_size) fcp.bgcolour_ctrl = wx.ColourPickerCtrl(fcp, col = bgcolour, size = button_size) fcp.sample.SetFont(font) fcp.sample.SetBackgroundColour(bgcolour) fcp.sample.SetForegroundColour(fgcolour) fcp.sample.SetValue('Emerson says, "This is what your window will look like."') fcp.ansi_checkbox = wx.CheckBox(fcp, -1, 'Use ANSI colors') fcp.ansi_checkbox.SetValue( True if prefs.get('use_ansi') == "True" else False ) fc_sizer = wx.FlexGridSizer(1, 3, 5, 10) fc_sizer.Add(fcp.font_ctrl , 0, wx.EXPAND, 0) fc_sizer.Add(fcp.fgcolour_ctrl, 0) fc_sizer.Add(fcp.bgcolour_ctrl, 0) fc_sizer.AddGrowableCol(0) #fc_sizer.Fit(fcp) ansi_sizer = wx.BoxSizer(wx.VERTICAL) ansi_sizer.Add(fcp.ansi_checkbox) #ansi_sizer.Fit(fcp) panel_sizer = wx.BoxSizer(wx.VERTICAL) panel_sizer.Add(fcp.sample, 0, wx.RIGHT|wx.LEFT|wx.EXPAND|wx.TOP, 10) panel_sizer.Add(fc_sizer, 0, wx.RIGHT|wx.LEFT|wx.EXPAND, 10) panel_sizer.AddSpacer(bsize) panel_sizer.Add(ansi_sizer) self.Bind(wx.EVT_FONTPICKER_CHANGED , self.update_sample_text, fcp.font_ctrl) self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.update_sample_text, fcp.fgcolour_ctrl) self.Bind(wx.EVT_COLOURPICKER_CHANGED, self.update_sample_text, fcp.bgcolour_ctrl) fcp.SetSizer(panel_sizer) return fcp
def createGeneralPanel(self): gp = wx.Panel(self.book) gp.save_size_checkbox = wx.CheckBox(gp, -1, 'Save Window Size') gp.save_size_checkbox.SetValue( True if prefs.get('save_window_size') == 'True' else False ) gp.autoconnect_checkbox = wx.CheckBox(gp, -1, 'Autoconnect to last world at startup') gp.autoconnect_checkbox.SetValue( True if prefs.get('autoconnect_last_world') == 'True' else False ) gp.panel_sizer = wx.BoxSizer(wx.VERTICAL) gp.panel_sizer.Add(gp.save_size_checkbox, flag = wx.ALL, border = 10) gp.panel_sizer.Add(gp.autoconnect_checkbox, flag = wx.ALL, border = 10) gp.SetSizer(gp.panel_sizer) return gp
def copy_from_selection(self, evt=None): uxcp = prefs.get('use_x_copy_paste') if uxcp and platform == 'linux': wx.TheClipboard.UsePrimarySelection(True) self.Copy() if uxcp and platform == 'linux': wx.TheClipboard.UsePrimarySelection(False)
def onSize(self, evt): if prefs.get('save_window_size'): size = self.GetSize() prefs.set('window_width', str(size.GetWidth())) prefs.set('window_height', str(size.GetHeight())) self.Layout() evt.Skip()
def copy_from_selection(self, evt): uxcp = prefs.get("use_x_copy_paste") == "True" if uxcp and platform == "linux": wx.TheClipboard.UsePrimarySelection(True) self.Copy() if uxcp and platform == "linux": wx.TheClipboard.UsePrimarySelection(False)
def getOptionalIngDic (self, ivw, mult, prefs): """Return a dictionary of optional ingredients with a TRUE|FALSE value Alternatively, we return a boolean value, in which case that is the value for all ingredients. The dictionary will tell us which ingredients to add to our shopping list. We look at prefs to see if 'shop_always_add_optional' is set, in which case we don't ask our user.""" debug("getOptionalIngDic (ivw):",5) #vw = ivw.select(optional=True) vw = filter(lambda r: r.optional==True, ivw) # optional_mode: 0==ask, 1==add, -1==dont add optional_mode=prefs.get('shop_handle_optional',0) if optional_mode: if optional_mode==1: return True elif optional_mode==-1: return False elif len(vw) > 0: if not None in [i.shopoptional for i in vw]: # in this case, we have a simple job -- load our saved # defaults dic = {} for i in vw: if i.shopoptional==2: dic[i.ingkey]=True else: dic[i.ingkey]=False return dic # otherwise, we ask our user oid=OptionalIngDialog(vw, prefs, mult) retval = oid.run() if retval: return retval else: raise de.UserCancelError("Option Dialog cancelled!")
def getOptionalIngDic(self, ivw, mult, prefs): """Return a dictionary of optional ingredients with a TRUE|FALSE value Alternatively, we return a boolean value, in which case that is the value for all ingredients. The dictionary will tell us which ingredients to add to our shopping list. We look at prefs to see if 'shop_always_add_optional' is set, in which case we don't ask our user.""" debug("getOptionalIngDic (ivw):", 5) # vw = ivw.select(optional=True) vw = filter(lambda r: r.optional == True, ivw) # optional_mode: 0==ask, 1==add, -1==dont add optional_mode = prefs.get('shop_handle_optional', 0) if optional_mode: if optional_mode == 1: return True elif optional_mode == -1: return False elif len(vw) > 0: if not None in [i.shopoptional for i in vw]: # in this case, we have a simple job -- load our saved # defaults dic = {} for i in vw: if i.shopoptional == 2: dic[i.ingkey] = True else: dic[i.ingkey] = False return dic # otherwise, we ask our user oid = OptionalIngDialog(vw, prefs, mult) retval = oid.run() if retval: return retval else: raise de.UserCancelError("Option Dialog cancelled!")
def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) self.status_bar = StatusBar(self) self.SetStatusBar(self.status_bar) self.buildMenu() self.about_info = None self.connect_dialog = None self.prefs_editor = None self.worlds_list = None h = 600 w = 800 if prefs.get('save_window_size'): if prefs.get('window_width'): w = int(prefs.get('window_width')) if prefs.get('window_height'): h = int(prefs.get('window_height')) self.SetSize((w, h)) self.tabs = wx.Notebook(self) self.addEvents() if prefs.get('autoconnect_last_world') == 'True': world = worlds.get(prefs.get('last_world')) if world: self.openWorld(world)
def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) self.status_bar = StatusBar(self) self.SetStatusBar(self.status_bar) self.about_info = None self.connect_dialog = None self.prefs_editor = None self.worlds_list = None self.shortlist = [] self.buildMenu() h = 600 w = 800 if prefs.get('save_window_size'): if prefs.get('window_width'): w = int(prefs.get('window_width')) if prefs.get('window_height'): h = int(prefs.get('window_height')) self.SetSize((w, h)) self.tabs = MOONotebook(self) self.addEvents() if prefs.get('autoconnect_last_world'): world = worlds.get(prefs.get('last_world')) if world: self.openWorld(world) else: wx.CallAfter(self.showWorldsList) else: wx.CallAfter(self.showWorldsList)
def send_to_connection(self, evt): if self.connection: stuff = self.GetValue() self.cmd_history.add(stuff) self.connection.output(stuff + "\n") self.Clear() if prefs.get('local_echo') and (not 'ECHO' in self.connection.iac or self.connection.iac['ECHO'] == True): self.connection.output_pane.display(">" + stuff + "\n")
def runEditor(self): cmd = re.split(' +', prefs.get('external_editor')) cmd.append(self.tmpfilename) proc = subprocess.call(cmd) # blocks the thread while the editor runs, then send it: self._send_file_if_needed(None) # ...and remove the temp file. os.remove(self.tmpfilename) self.watchTimer.Stop()
def left_mouse_up(self, evt): if self.is_dragging: self.is_dragging = False if prefs.get('use_x_copy_paste'): if platform == 'linux': wx.TheClipboard.UsePrimarySelection(True) if self.CanCopy(): self.Copy() if platform == 'linux': wx.TheClipboard.UsePrimarySelection(False) evt.Skip(True)
def createGeneralPanel(self): gp = wx.Panel(self.book) gp.save_size_checkbox = wx.CheckBox(gp, -1, 'Save Window Size') gp.save_size_checkbox.SetValue(prefs.get('save_window_size')) gp.autoconnect_checkbox = wx.CheckBox( gp, -1, 'Autoconnect to last world at startup') gp.autoconnect_checkbox.SetValue(prefs.get('autoconnect_last_world')) gp.xmouse_checkbox = wx.CheckBox( gp, -1, 'Use X-style mouse copy/paste behavior') gp.xmouse_checkbox.SetValue(prefs.get('use_x_copy_paste')) gp.panel_sizer = wx.BoxSizer(wx.VERTICAL) gp.panel_sizer.Add(gp.save_size_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.autoconnect_checkbox, flag=wx.ALL, border=10) gp.panel_sizer.Add(gp.xmouse_checkbox, flag=wx.ALL, border=10) gp.SetSizer(gp.panel_sizer) return gp
def __init__(self, parent, connection): wx.PopupWindow.__init__(self, parent, flags=wx.BORDER_SIMPLE) self.verbs = [] self.names = [] self.parent = parent self.completion_list = CompletionList(self) self.last_completed = None self.connection = connection self.SetBackgroundColour(prefs.get("fgcolour")) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.completion_list, 1, wx.ALL | wx.EXPAND, 2) self.SetSizer(sizer)
def restyle_thyself(self): basic_style = rtc.RichTextAttr() self.fg_colour = prefs.get('fgcolour') self.bg_colour = prefs.get('bgcolour') basic_style.SetTextColour (self.fg_colour) basic_style.SetBackgroundColour(self.bg_colour) self.SetBackgroundColour(self.bg_colour) self.SetBasicStyle(basic_style) self.basic_style = basic_style # is there a way to construct a font directly from an InfoString, instead of making # a generic one and then overriding it like this? font = wx.NullFont font.SetNativeFontInfoFromString(prefs.get('font')) self.SetFont(font) # set one-half character's worth of left / top margin font_width, font_height = self.font_size() # Apparently Centos' Wx doesn't have this, so commenting it out. #self.SetMargins((font_width / 2, -1)) self.update_size()
def runEditor(self): cmd = re.split(' +', prefs.get('external_editor')) cmd.append(self.tmpfilename) # block the thread while the editor runs... subprocess.Popen(cmd).wait() # ...then send it once the editor exits... self._send_file_if_needed(None) # ...and remove the temp file. os.remove(self.tmpfilename) self.watchTimer.Stop()
def __init__(self, parent, conn): worldname = conn.world.get('name') wx.Dialog.__init__(self, parent, title = "Debug MCP: " + worldname, style = wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE ) self.active = False self.output_pane = None self.connection = conn self.addEvents() if (prefs.get('save_mcp_window_size')): w = prefs.get('mcp_window_width') or 600 h = prefs.get('mcp_window_height') or 400 self.SetSize([int(w), int(h)]) self.output_pane = DebugMCPPane(self) sizer = wx.BoxSizer( wx.VERTICAL ) sizer.Add(self.output_pane, 1, wx.ALL|wx.GROW, 5) self.SetSizer(sizer) # pre-stage monkey-patching self.connection.mcp.orig_debug = self.connection.mcp.debug
def Show(self, val=True): self.world_picker.Clear() for world in worlds: self.world_picker.Append(world) last_world_name = prefs.get('last_world', '') last_world = self.world_picker.FindString(last_world_name) # if we no longer have that world, go back to the top of the list if last_world < 0: last_world_name = self.world_picker.GetString(0) last_world = self.world_picker.FindString(last_world_name) self.world_picker.SetSelection(last_world) self.fill_thyself() super(WorldsList, self).Show(val)
def __init__(self, parent): wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL) self.parent = parent self.SetTextColour(Theme.fetch().get('foreground')) self.SetBackgroundColour(Theme.fetch().get('background')) font = wx.Font(prefs.get('font')) self.SetFont(font) self.Bind(wx.EVT_KEY_DOWN, self.parent.parent.check_for_interesting_keystrokes)
def __init__(self, parent, connection): BasePane.__init__(self, parent, connection, style=wx.TE_PROCESS_ENTER | wx.TE_MULTILINE) self.cmd_history = CommandHistory(self) self.tab_completion = TabCompletion(self, connection) self.tabs = wx.GetApp().GetTopWindow().tabs self.Bind(wx.EVT_TEXT_ENTER, self.send_to_connection) self.Bind(wx.EVT_TEXT, self.onTextChange) self.Bind(wx.EVT_KEY_DOWN, self.check_for_interesting_keystrokes) if prefs.get("use_x_copy_paste") == "True": self.Bind(wx.EVT_MIDDLE_DOWN, self.paste_from_selection) self.Bind(rtc.EVT_RICHTEXT_SELECTION_CHANGED, self.copy_from_selection) self.Clear() self.restyle_thyself()
def __init__ (self,vw,prefs,mult=1,default=False): debug("__init__ (self,vw,default=False):",5) self.rd = recipeManager.get_recipe_manager() de.ModalDialog.__init__( self, default, label=_("Select optional ingredients"), sublabel=_("Please specify which of the following optional ingredients you'd like to include on your shopping list.")) self.mult = mult self.vw=vw self.ret = {} self.create_tree() self.cb = gtk.CheckButton("Always use these settings") self.cb.set_active(prefs.get('remember_optionals_by_default',False)) alignment = gtk.Alignment() alignment.set_property('xalign',1.0) alignment.add(self.cb) self.vbox.add(alignment) alignment.show() self.cb.show()
def restyle_thyself(self): basic_style = rtc.RichTextAttr() self.theme = Theme.fetch() basic_style.SetTextColour(self.fg_colour) basic_style.SetBackgroundColour(self.bg_colour) self.SetBackgroundColour(self.bg_colour) self.SetBasicStyle(basic_style) self.basic_style = basic_style font = wx.Font(prefs.get('font')) self.SetFont(font) # set one-half character's worth of left / top margin font_width, font_height = self.font_size() # Apparently Centos' Wx doesn't have this, so commenting it out. #self.SetMargins((font_width / 2, -1)) self.update_size()
def createPathsPanel(self): pp = wx.Panel(self.book) editor_label = wx.StaticText(pp, -1, "External Editor") pp.external_editor = wx.TextCtrl(pp, -1, "") pp.external_editor.SetValue( prefs.get('external_editor') ) #pp.external_editor.Fit() editor_sizer = wx.FlexGridSizer(1,2,5,10) editor_sizer.Add(editor_label, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) editor_sizer.Add(pp.external_editor, 1, wx.EXPAND, 0) editor_sizer.AddGrowableCol(1) pp.panel_sizer = wx.BoxSizer(wx.VERTICAL) pp.panel_sizer.Add(editor_sizer, 0, wx.EXPAND | wx.ALL, 10) pp.SetSizer(pp.panel_sizer) return pp
def createPathsPanel(self): pp = wx.Panel(self.book) editor_label = wx.StaticText(pp, -1, "External Editor") pp.external_editor = wx.TextCtrl(pp, -1, "") pp.external_editor.SetValue(prefs.get('external_editor')) editor_sizer = wx.FlexGridSizer(1, 2, 5, 10) editor_sizer.Add(editor_label, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 0) editor_sizer.Add(pp.external_editor, 1, wx.EXPAND, 0) editor_sizer.AddGrowableCol(1) pp.panel_sizer = wx.BoxSizer(wx.VERTICAL) pp.panel_sizer.Add(editor_sizer, 0, wx.EXPAND | wx.ALL, 10) pp.SetSizer(pp.panel_sizer) return pp
def doansi_no_blink(self): if not prefs.get('use_ansi_blink'): return end = self.GetInsertionPoint() if self.blink: if self.blink_start: for c in range(self.blink_start, end): s = wx.TextAttr() self.GetStyle(c, s) self.blink_chars.append( (c, s.GetTextColour(), s.GetBackgroundColour())) self.blink_start = self.blink = False if self.fast_blink: if self.fast_blink_start: for c in range(self.fast_blink_start, end): s = wx.TextAttr() self.GetStyle(c, s) self.fast_blink_chars.append( (c, s.GetTextColour(), s.GetBackgroundColour())) self.fast_blink_start = self.fast_blink = False
def fetch(cls, themename=''): global all_themes return all_themes[themename or prefs.get('theme')]
def doansi_fast_blink(self): if prefs.get('use_ansi_blink'): self.fast_blink = True self.fast_blink_start = self.GetInsertionPoint()
def display(self, text): self.SetInsertionPointEnd() text = text.decode("latin-1") # TODO - is this the right thing and/or place for this? # self.Freeze() # causing delay on last line - TODO: investigate for line in text.split("\n"): line = line + "\n" if prefs.get("use_mcp") == "True": line = self.connection.mcp.output_filter(line) if not line: continue # output_filter returns falsie if it handled it. # if (True or prefs.get('render_emoji') == 'True'): # TODO - preference? "if (we detect an emoji)?" # line = emoji.emojize(line, use_aliases = True) if prefs.get("use_ansi") == "True": # Dear lord this is sorta ugly # snip and ring bells # TODO -- "if beep is enabled in the prefs" line, count = re.subn("\007", "", line) for b in range(0, count): print("DEBUG: found an ANSI beep") wx.Bell() # chop the line into text, ansi, text, ansi.... bits = re.split("\033\[(\d+(?:;\d+)*)m", line) for idx, bit in enumerate(bits): if bit == "": continue # if it's ansi... if idx % 2: # pick apart the ANSI stuff. codes = [int(c) for c in bit.split(";")] while codes: command, payload = ansi_codes[codes.pop(0)] if command == "control": if payload == "normal": self.EndAllStyles() self.intensity = "" self.inverse = False self.fg_colour = prefs.get("fgcolour") self.bg_colour = prefs.get("bgcolour") self.set_current_colours() elif payload == "bright": self.intensity = "bright" self.set_current_colours() elif payload == "dim": self.intensity = "dim" self.set_current_colours() elif payload == "italic": self.BeginItalic() elif payload == "underline": self.BeginUnderline() elif payload == "blink": print('Got an ANSI "blink"') # TODO - create timer # apply style name # periodically switch foreground color to background elif payload == "inverse": self.inverse = True self.set_current_colours() elif payload == "conceal": print('Got an ANSI "conceal"') elif payload == "strike": font = self.GetFont() font.SetStrikethrough(True) self.BeginFont(font) elif payload == "normal_weight": self.intensity = "" self.set_current_colours() elif payload == "no_italic": self.EndItalic() elif payload == "no_underline": self.EndUnderline() elif payload == "no_blink": print('Got an ANSI "no_blink"') # TODO - remove blink-code-handles style elif payload == "no_conceal": print('Got an ANSI "no_conceal"') elif payload == "no_strike": font = self.GetFont() font.SetStrikethrough(False) self.BeginFont(font) elif payload == "framed": print('Got an ANSI "framed"') elif payload == "encircled": print('Got an ANSI "encircled"') elif payload == "overline": print('Got an ANSI "overline"') elif payload == "no_framed_encircled": print('Got an ANSI "no_framed_encircled"') elif payload == "no_overline": print('Got an ANSI "no_overline"') elif command == "foreground" or command == "background": if payload == "extended": subtype = codes.pop(0) # 24-bit color if subtype == 2: colour = self.theme.rgb_to_hex((codes.pop(0), codes.pop(0), codes.pop(0))) # 256-color elif subtype == 5: colour = self.theme.index256_to_hex(codes.pop(0)) else: print("Got an unknown fg/bg ANSI subtype: " + str(subtype)) else: colour = payload if command == "foreground": self.fg_colour = colour else: self.bg_colour = colour self.set_current_colours() else: print("unknown ANSI command:", command) else: # is a text-only chunk, check for URLs if prefs.get("highlight_urls") == "True": matches = re.split(utility.URL_REGEX, bit) for chunk in matches: if chunk is None: continue if re.match(utility.URL_REGEX, chunk): self.BeginURL(chunk) self.BeginUnderline() current_intensity = self.intensity self.intensity = "normal" self.BeginTextColour(self.lookup_colour("blue")) self.intensity = current_intensity self.WriteText(chunk) self.EndTextColour() self.EndUnderline() self.EndURL() else: self.WriteText(chunk) else: self.WriteText(bit)
def ScrollIfAppropriate(self): if self.is_at_bottom() or prefs.get("scroll_on_output") == "True": self.ShowPosition(self.GetLastPosition()) self.Refresh()
def HandleResize(self, evt): size = self.GetSize() input_height = int(prefs.get('input_height')) or 25 self.SetSashPosition(size.GetHeight() - input_height, True) self.output_pane.ScrollIfAppropriate()
t1=time() try: page=ump.get_page(testpage,"utf-8",tunnel="disabled",tout=1) basetime=time()-t1 except Exception,e: ump.dialogpg.update(message="[COLOR red]Tunnel test page is down[/COLOR]") return import prefs try: interval=int(float(addon.getSetting("tn_chk_prd"))) except: interval=1 attrs=[] for tunnel in tunnels.keys(): lasttime=prefs.get("tunnelstates",tunnel,"lastcheck") if isinstance(lasttime,float) and time()-lasttime<interval*60*60 and not force: continue prefs.set("tunnelstates",tunnel,"lastcheck",time()) page="" reason="Tunnel Error" t1=time() ping=tout*1000 try: page=ump.get_page(testpage,"utf-8",tunnel=tunnel,tout=tout,forcetunnel=True,throttle=False) ping=int((time()-t1-basetime)*1000) reason=str(ping) except Exception,e: reason=str(e.message) pass name=tunnel.replace("_"," ").title()
def paste_with_middle_mouse(self, evt): if prefs.get('use_x_copy_paste'): self.connection.input_pane.paste_from_selection()
def ScrollIfAppropriate(self): if (self.is_at_bottom() or prefs.get('scroll_on_output')): self.ShowPosition(self.GetLastPosition()) self.Refresh()
def onSize(self, evt): if (prefs.get('save_mcp_window_size')): size = self.GetSize() prefs.set('mcp_window_width', size.GetWidth()) prefs.set('mcp_window_height', size.GetHeight()) evt.Skip()
def display(self, text): self.SetInsertionPointEnd() self.Freeze() if self.global_queue: text = self.global_queue + text self.global_queue = '' # it is not clear whether this is the correct (a) thing to do, or # (b) place to do it, but some wackass MUDs seem to be sending \r\n # with an ANSI blob in between(!!!). Going Unixy and just using \n text = re.sub('\r', '', text) # line-based filters should do their thing, returning None if they ate # everything they should enqueue any partial lines they're "in the # middle of" handling and be ready for the rest of the line; then they # should examine the remainder for further handling or enqueueing. for fil in self.filters: text = fil(self, text) if text == None: return # output_filter must return None if it handled it #if (True or prefs.get('render_emoji'): # TODO - preference? "if (we detect an emoji)?" #text = emoji.emojize(text, use_aliases = True) if prefs.get('use_ansi'): # Dear lord this is sorta ugly # TODO -- let's make this whole thing an external filter that # returns text chunks and TextAttrs to blat at the screen. For # now, we can still do it line-by-line, but eventually we might # want to be properly character-based/VT supporting. # For now, we'll stick the FANSI character poop into an # external filter. if self.connection.world.get("use_fansi"): text = fansi_replace(text) # snip and ring bells # TODO -- "if beep is enabled in the prefs" text, count = re.subn("\007", '', text) for b in range(0, count): print("DEBUG: found an ANSI beep") wx.Bell() # chop the text into text, ansi, text, ansi.... bits = re.split('\033\[(\d+(?:;\d+)*)m', text) for idx, bit in enumerate(bits): # if we're on the last bit, check whether it might be a partial ANSI blob if idx == len(bits) - 1: if re.search('\033', bit): print( f"I think I have a spare ANSI bit ({bit}), requeueing it" ) self.global_queue += bit break if bit == '': continue # if it's ansi... if (idx % 2): # pick apart the ANSI stuff. codes = [int(c) for c in bit.split(';')] while codes: command, payload = ansi_codes[codes.pop(0)] if command == 'foreground' or command == "background": if payload == "extended": subtype = codes.pop(0) # 24-bit color if subtype == 2: colour = self.theme.rgb_to_hex( (codes.pop(0), codes.pop(0), codes.pop(0))) # 256-color elif subtype == 5: colour = self.theme.index256_to_hex( codes.pop(0)) else: print( "Got an unknown fg/bg ANSI subtype: " + str(subtype)) else: colour = payload if command == "foreground": self.fg_colour = colour else: self.bg_colour = colour self.style_thyself() elif command == 'control': switcher = { 'normal': self.doansi_normal, 'bright': self.doansi_bright, 'dim': self.doansi_dim, 'italic': self.doansi_italic, 'underline': self.doansi_underline, 'blink': self.doansi_blink, 'fast_blink': self.doansi_fast_blink, 'inverse': self.doansi_inverse, 'conceal': self.doansi_conceal, 'strike': self.doansi_strike, 'double_underline': self.doansi_double_underline, 'normal_weight': self.doansi_normal_weight, 'no_italic': self.doansi_no_italic, 'no_underline': self.doansi_no_underline, 'no_blink': self.doansi_no_blink, 'no_conceal': self.doansi_no_conceal, 'no_strike': self.doansi_no_strike, 'framed': self.doansi_framed, 'encircled': self.doansi_encircled, 'overline': self.doansi_overline, 'no_framed_encircled': self.doansi_no_framed_encircled, 'no_overline': self.doansi_no_overline, 'default_fg': self.doansi_default_fg, 'default_bg': self.doansi_default_bg, } ansifunc = switcher.get( payload, lambda: print("Unknown ANSI control sequence")) ansifunc() self.style_thyself() else: print("unknown ANSI command:", command) else: # is a text-only chunk, check for URLs if prefs.get('highlight_urls'): matches = utility.URL_REGEX.split(bit) for chunk in matches: if not chunk: continue if utility.URL_REGEX.match(chunk): self.BeginURL(chunk) self.BeginUnderline() current_intensity = self.intensity self.intensity = 'normal' self.BeginTextColour( self.lookup_colour('blue')) self.intensity = current_intensity self.WriteText(chunk) self.EndTextColour() self.EndUnderline() self.EndURL() else: self.WriteText(chunk) else: self.WriteText(bit) else: self.WriteText(text) self.Thaw()
try: page = ump.get_page(testpage, "utf-8", tunnel="disabled", tout=1) basetime = time() - t1 except Exception, e: ump.dialogpg.update( message="[COLOR red]Tunnel test page is down[/COLOR]") return import prefs try: interval = int(float(addon.getSetting("tn_chk_prd"))) except: interval = 1 attrs = [] for tunnel in tunnels.keys(): lasttime = prefs.get("tunnelstates", tunnel, "lastcheck") if isinstance( lasttime, float ) and time() - lasttime < interval * 60 * 60 and not force: continue prefs.set("tunnelstates", tunnel, "lastcheck", time()) page = "" reason = "Tunnel Error" t1 = time() ping = tout * 1000 try: page = ump.get_page(testpage, "utf-8", tunnel=tunnel, tout=tout, forcetunnel=True,
def OnSize(self, evt): size = self.GetSize() input_height = int(prefs.get('input_height')) or 25 self.SetSashPosition(size.GetHeight() - input_height, True) self.output_pane.ScrollIfAppropriate() evt.Skip()
def ScrollIfAppropriate(self): if ((not self.is_scrolled_back) or prefs.get('scroll_on_output')): self.ShowPosition(self.GetLastPosition()) self.Refresh()
def __init__(self, parent): wx.Dialog.__init__(self, parent, name = 'Worlds List', style = wx.RESIZE_BORDER) self.parent = parent worlds_label = wx.StaticText(self, label = "World:") self.world_picker = wx.Choice(self, style = wx.CB_SORT ) for world in worlds: self.world_picker.Append(world) host_label = wx.StaticText(self, label = "Host:") port_label = wx.StaticText(self, label = "Port:") self.host = wx.TextCtrl(self) # stick port + type into their own boxsizer self.port = wx.SpinCtrl(self) self.port.SetRange(1, 65535) self.port.SetValue(7777) self.conntype = wx.Choice(self, choices = conntypes ) port_sizer = wx.BoxSizer(wx.HORIZONTAL) port_sizer.Add(self.port, 1, wx.EXPAND) port_sizer.Add([5,5], 0, wx.EXPAND) port_sizer.Add(self.conntype, 0, wx.EXPAND) self.ssh_username_label = wx.StaticText(self, label = "SSH User:"******"SSH Host:") self.ssh_username = wx.TextCtrl(self) self.ssh_loc_host = wx.TextCtrl(self) self.auto_login_check = wx.CheckBox(self, label = "Auto-Login") self.login_script_label = wx.StaticText(self, label = "Login Script:") self.login_script = wx.TextCtrl(self) self.username_label = wx.StaticText(self, label = "Username:"******"Password:"******"Description:"), wx.VERTICAL) desc_box.Add(self.desc, 1, wx.EXPAND) #self.note = wx.TextCtrl(self, style = wx.TE_MULTILINE|wx.BORDER_NONE) #note_box = wx.StaticBoxSizer(wx.StaticBox(self, label = "Notes:"), wx.VERTICAL) #note_box.Add(self.note, 1, wx.EXPAND) self.mcp_check = wx.CheckBox(self, label = "MCP 2.1") self.login_dialog_check = wx.CheckBox(self, label = "Use Login Dialog") self.shortlist_check = wx.CheckBox(self, label = "On Short List") checkbox_sizer = wx.GridSizer(3, 2, 0, 0) checkbox_sizer.AddMany([ (self.mcp_check , 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5), (self.login_dialog_check, 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5), (self.shortlist_check , 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5), ]) new_button = wx.Button(self, label = "New") reset_button = wx.Button(self, label = "Reset") save_button = wx.Button(self, label = "Save") button_sizer = wx.FlexGridSizer(cols = 3, rows = 1, hgap = 0, vgap = 0) button_sizer.AddMany ([ (new_button , 0, wx.ALL|wx.ALIGN_RIGHT, 5), (reset_button, 0, wx.ALL , 5), (save_button , 0, wx.ALL , 5), ]) button_sizer.AddGrowableCol(0) self.Bind(wx.EVT_BUTTON, self.on_new, new_button) self.Bind(wx.EVT_BUTTON, self.on_reset, reset_button) self.Bind(wx.EVT_BUTTON, self.on_save, save_button) world_details_staticbox = wx.StaticBox(self) self.world_details_box = wx.StaticBoxSizer(world_details_staticbox, wx.VERTICAL) self.world_details_box.AddMany ([ (field_sizer , 0, wx.ALL|wx.EXPAND, 5), (desc_box , 1, wx.ALL|wx.EXPAND, 5), #(note_box , 1, wx.ALL|wx.EXPAND, 5), (checkbox_sizer, 0, wx.EXPAND , 5), (button_sizer , 0, wx.EXPAND , 0), ]) main_button_sizer = self.CreateButtonSizer( wx.OK | wx.CANCEL ) # Hax: change the "OK" button to "Connect" # This is a hoop-jumping exercise to use the platform-specific locations # of "OK" and "Cancel" instead of the hoop-jumping exercise of making my # own buttons. There's almost certainly a better way to do this. for b in main_button_sizer.GetChildren(): bwin = b.GetWindow() if (not bwin) or (bwin.GetLabel() != '&OK'): continue bwin.SetLabel('&Connect') break main_sizer = wx.BoxSizer(wx.VERTICAL) main_sizer.Add(self.world_details_box, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10) main_sizer.Add(main_button_sizer , 0, wx.EXPAND | wx.ALL , 5) last_world_name = prefs.get('last_world') last_world = self.world_picker.FindString(last_world_name) # if we no longer have that world, go back to the top of the list if last_world < 0: last_world_name = self.world_picker.GetString(0) last_world = self.world_picker.FindString(last_world_name) self.world_picker.SetSelection(last_world) self.fill_thyself() self.SetSizerAndFit(main_sizer) self.Layout() self.Centre(wx.BOTH) self.Bind(wx.EVT_CHOICE, self.select_world, self.world_picker) self.Bind(wx.EVT_CHOICE, self.show_fields_if_appropriate, self.conntype) self.Bind(wx.EVT_CHECKBOX, self.show_fields_if_appropriate, self.auto_login_check) self.Bind(wx.EVT_BUTTON, self.on_connect, id = wx.ID_OK) self.show_fields_if_appropriate()