def tokenString(self): font = NSFont.fontWithName_size_(fallbackFont.fontName(), 10) attr = _textAttributesForStyle(self._style, font) attr[NSForegroundColorAttributeName] = self.color() if NSUnderlineColorAttributeName in attr: attr[NSUnderlineColorAttributeName] = self.color() txt = self.token() if txt == "Token": txt = "Fallback" else: txt = txt.replace("Token.", "") return NSMutableAttributedString.alloc().initWithString_attributes_(txt, attr)
if not cutoff: names.append(l.parent.name) theseLayers = [] for m in Font.masters: for gname in names: layer = Font.glyphs[gname].layers[m.id] # print(layer) theseLayers.append(layer) theseLayers.append(GSControlLayer.newline()) if theseLayers: # Font.currentTab.layers.append( theseLayers ) # BROKEN IN 1224 # WORKAROUND: string = NSMutableAttributedString.alloc().init() for l in theseLayers: if l.className() == "GSLayer": char = Font.characterForGlyph_(l.parent) A = NSAttributedString.alloc().initWithString_attributes_( unichr(char), {"GSLayerIdAttrib": l.layerId}) elif l.className() == "GSBackgroundLayer": char = Font.characterForGlyph_(l.parent) A = NSAttributedString.alloc().initWithString_attributes_( unichr(char), { "GSLayerIdAttrib": l.layerId, "GSShowBackgroundAttrib": True }) elif l.className() == "GSControlLayer": char = l.parent.unicodeChar() A = NSAttributedString.alloc().initWithString_(unichr(char))
def renderSIP(self, notification): settings = SIPSimpleSettings() if settings.logs.trace_sip_in_gui == Disabled: return event_data = notification.data self.sipBytes += len(event_data.data) if self._siptrace_start_time is None: self._siptrace_start_time = notification.datetime self._siptrace_packet_count += 1 text = NSMutableAttributedString.alloc().init() if self.lastSIPMessageWasDNS: text.appendAttributedString_(self.newline) self.lastSIPMessageWasDNS = False if event_data.received: self.sipInCount += 1 text.appendAttributedString_(self.receivedText) else: self.sipOutCount += 1 text.appendAttributedString_(self.sendingText) line = " Packet %d, +%s\n" % (self._siptrace_packet_count, (notification.datetime - self._siptrace_start_time)) text.appendAttributedString_(NSAttributedString.alloc().initWithString_(line)) line = "%s: %s:%d -(SIP over %s)-> %s:%d\n" % (notification.datetime, event_data.source_ip, event_data.source_port, event_data.transport, event_data.destination_ip, event_data.destination_port) text.appendAttributedString_(NSAttributedString.alloc().initWithString_(line)) data = event_data.data.strip() first, rest = data.split("\n", 1) applications = None method = None msg_type = None event = None code = None if data.startswith("SIP/2.0"): try: code = first.split()[1] attribs = self.boldRedTextAttribs if code[0] in ["4", "5", "6"] else self.boldTextAttribs for line in data.split("\n"): line = line.strip() if line.startswith("Event:"): try: event = line.split(" ", 1)[1] except IndexError: pass continue if line.startswith("CSeq"): cseq, _number, _method = line.split(" ", 2) try: applications = self.filter_sip_methods[_method.strip()] method = _method msg_type = 'response' except KeyError: pass continue if settings.logs.trace_sip_in_gui == Full: text.appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(first+"\n", attribs)) text.appendAttributedString_(NSAttributedString.alloc().initWithString_(rest+"\n")) else: text.appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(first+"\n", attribs)) except: text.appendAttributedString_(NSAttributedString.alloc().initWithString_(data+"\n")) else: _method = first.split()[0] try: applications = self.filter_sip_methods[_method] method = _method msg_type = 'offer' except KeyError: pass for line in data.split("\n"): line = line.strip() if line.startswith("Event:"): try: event = line.split(" ", 1)[1] except IndexError: pass continue if settings.logs.trace_sip_in_gui == Full: text.appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(first+"\n", self.boldTextAttribs)) text.appendAttributedString_(NSAttributedString.alloc().initWithString_(rest+"\n")) else: text.appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(first+"\n", self.boldTextAttribs)) self.sipInfoLabel.setStringValue_("%d SIP messages sent, %d SIP messages received, %sytes" % (self.sipOutCount, self.sipInCount, format_size(self.sipBytes))) if self.filter_sip_application is not None and applications is not None: if self.filter_sip_application not in applications: return self.sipTextView.textStorage().appendAttributedString_(text) self.sipTextView.textStorage().appendAttributedString_(self.newline) self.sipTextView.scrollRangeToVisible_(NSMakeRange(self.sipTextView.textStorage().length()-1, 1))