<commit_before>import pygtk
pygtk.require('2.0')
import gtk
import cairo
import pangocairo
import pango
import goocanvas
import random
import math

def calc_extents(ctx, fontName, text):
    layout = pangocairo.CairoContext(ctx).create_layout()
    layout.set_font_description(pango.FontDescription(fontName))
    layout.set_text(text)
    return layout.get_pixel_size()

class Colors:
    frame = 0x808080FF
    text = 0xE0E0E0FF
    box = 0x303030FF
    defPort = 0x404040FF
    audioPort = 0x004060FF
    controlPort = 0x008000FF
    eventPort = 0x800000FF
    activePort = 0x808080FF
    draggedWire = 0xFFFFFFFF
    connectedWire = 0x808080FF

class VisibleWire():
    def __init__(self, src, dest, wire):
        """src is source ModulePort, dst is destination ModulePort, wire is a goocanvas.Path"""
        self.src = src
        self.dest = dest
        self.wire = wire
    def delete(self):
        self.wire.remove()
        self.src.module.remove_wire(self)
        self.dest.module.remove_wire(self)

class ModulePort():
    fontName = "DejaVu Sans 9"
    type = "port"
    def __init__(self, module, portData):
        self.module = module
        self.portData = portData
        self.isInput = self.get_parser().is_port_input(portData)
        self.box = self.title = None
            
    def get_parser(self):
        return self.module.get_parser()
        
    def get_id(self):
        return self.get_parser().get_port_id(self.portData)

    def calc_width(self, ctx):
        return calc_extents(ctx, self.fontName, self.get_parser().get_port_name(self.portData))[0] + 4 * self.module.margin

    def render(self, ctx, parent, y):
        module = self.module
        (width, margin, spacing) = (module.width, module.margin, module.spacing)
        al = "left"
        portName = self.get_parser().get_port_name(self.portData)
        title = goocanvas.Text(parent = parent, text = portName, font = self.fontName, width = width - 2 * margin, x = margin, y = y, alignment = al, fill_color_rgba = Colors.text, hint_metrics = cairo.HINT_METRICS_ON, pointer_events = False, wrap = False)
        height = 1 + int(title.get_requested_height(ctx, width - 2 * margin))
        title.ensure_updated()
        bnds = title.get_bounds()
        bw = bnds.x2 - bnds.x1 + 2 * margin
        if not self.isInput:
            title.translate(width - bw, 0)
        color = self.get_parser().get_port_color(self.portData)
        if self.isInput:
            box = goocanvas.Rect(parent = parent, x = 0.5, y = y - 0.5, width = bw, height = height + 1, line_width = 0, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
        else:
            box = goocanvas.Rect(parent = parent, x = width - bw - 0.5, y = y - 0.5, width = bw, height = height + 1, line_width = 0, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
        box.lower(title)
        y += height + spacing
        box.type = "port"
        self.orig_color = color
        box.object = box.module = self
        box.portData = self.portData
        title.portData = self.portData
        self.box = box
        self.title = title
        return y

class ModuleBox():<commit_msg>Use triangle ports in conndiagram.py.<commit_after>import pygtk
pygtk.require('2.0')
import gtk
import cairo
import pangocairo
import pango
import goocanvas
import random
import math

def calc_extents(ctx, fontName, text):
    layout = pangocairo.CairoContext(ctx).create_layout()
    layout.set_font_description(pango.FontDescription(fontName))
    layout.set_text(text)
    return layout.get_pixel_size()

class Colors:
    frame = 0x808080FF
    text = 0xE0E0E0FF
    box = 0x303030FF
    defPort = 0x404040FF
    audioPort = 0x004060FF
    controlPort = 0x008000FF
    eventPort = 0x800000FF
    activePort = 0x808080FF
    draggedWire = 0xFFFFFFFF
    connectedWire = 0x808080FF

class VisibleWire():
    def __init__(self, src, dest, wire):
        """src is source ModulePort, dst is destination ModulePort, wire is a goocanvas.Path"""
        self.src = src
        self.dest = dest
        self.wire = wire
    def delete(self):
        self.wire.remove()
        self.src.module.remove_wire(self)
        self.dest.module.remove_wire(self)

def path_move(x, y):
    return "M %s %s" % (x, y)
def path_line(x, y):
    return "L %s %s" % (x, y)

class ModulePort():
    fontName = "DejaVu Sans 9"
    type = "port"
    def __init__(self, module, portData):
        self.module = module
        self.portData = portData
        self.isInput = self.get_parser().is_port_input(portData)
        self.box = self.title = None
            
    def get_parser(self):
        return self.module.get_parser()
        
    def get_id(self):
        return self.get_parser().get_port_id(self.portData)

    def calc_width(self, ctx):
        return calc_extents(ctx, self.fontName, self.get_parser().get_port_name(self.portData))[0] + 4 * self.module.margin + 15

    @staticmethod
    def input_arrow(x, y, w, h):
        return path_move(x, y) + path_line(x + w - 10, y) + path_line(x + w, y + h / 2) + path_line(x + w - 10, y + h) + path_line(x, y + h) + path_line(x, y)

    @staticmethod
    def output_arrow(x, y, w, h):
        return path_move(x + w, y) + path_line(x + 10, y) + path_line(x, y + h / 2) + path_line(x + 10, y + h) + path_line(x + w, y + h) + path_line(x + w, y)

    def render(self, ctx, parent, y):
        module = self.module
        (width, margin, spacing) = (module.width, module.margin, module.spacing)
        al = "left"
        portName = self.get_parser().get_port_name(self.portData)
        title = goocanvas.Text(parent = parent, text = portName, font = self.fontName, width = width - 2 * margin, x = margin, y = y, alignment = al, fill_color_rgba = Colors.text, hint_metrics = cairo.HINT_METRICS_ON, pointer_events = False, wrap = False)
        height = 1 + int(title.get_requested_height(ctx, width - 2 * margin))
        title.ensure_updated()
        bnds = title.get_bounds()
        bw = bnds.x2 - bnds.x1 + 2 * margin
        if not self.isInput:
            title.translate(width - bw, 0)
        color = self.get_parser().get_port_color(self.portData)
        bw += 10
        if self.isInput:
            box = goocanvas.Path(parent = parent, data = self.input_arrow(0.5, y - 0.5, bw, height + 1), line_width = 0, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
        else:
            box = goocanvas.Path(parent = parent, data = self.output_arrow(width - bw, y - 0.5, bw, height + 1), line_width = 0, fill_color_rgba = color, stroke_color_rgba = Colors.frame)
        box.lower(title)
        y += height + spacing
        box.type = "port"
        self.orig_color = color
        box.object = box.module = self
        box.portData = self.portData
        title.portData = self.portData
        self.box = box
        self.title = title
        return y

class ModuleBox():
{'fraction_non_alphanumeric': 0.11223750905141203, 'fraction_numerical': 0.026357711803041275, 'mean_word_length': 2.632824829037349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2720902', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2339, 'n_words': 567}