Ejemplo n.º 1
0
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.screen_size)
        dx, dy = int(dx / self.pan_scale[1]), int(dy / self.pan_scale[1])

        if buttons == 1:
            if self.incr:
                t = self.document.text
                n = float(t) if '.' in t else int(t)
                i = dy / 10 if (modifiers == 1 or modifiers == 17) else dy
                r = n + i
                s = str(r) if isinstance(r, int) else "%.2f" % r
                self.document.text = s
                self.caret.visible = False
                self.caret.position = self.caret.mark = len(self.document.text)
                self.resize_field()
                self.x -= dx
                self.y -= dy
                self.need_update = True
            elif self.resize:
                self.w = max(self.w + dx * 2, 70)
                self.h = max(self.h - dy * 2, 30)
                self.x -= dx
                self.y -= dy
            elif self.hover and self.caret.visible:
                self.caret.on_mouse_drag(x, y, dx, dy, buttons, modifiers)
                self.x -= dx
                self.y -= dy
        self.style()
Ejemplo n.º 2
0
    def on_mouse_release(self, x, y, button, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.get_size())

        if button == 1:
            self.node_drag = False
            self.connection = False

            if self.select:
                select = []
                for node in self.nodes:
                    if point_intersect_quad((node.x, node.y),
                                            (self.c + self.w)):
                        select.append(node)
                        node.draw_color = color_inverse(node.color)
                self.selected_nodes = select
                self.w, self.c = (0, 0), (0, 0)
                self.select = False
            else:
                self.selected_nodes = []

            cn = self.connecting_node
            if cn:
                for node in self.nodes:
                    if node.intersect_point((x, y)):
                        if node != cn['node']:
                            if (node.selectedInput['name'] != 'none'
                                    and cn['mode'] == 'output'):
                                self.connect_out_to_in(node)
                            elif (node.selectedOutput['name'] != 'none'
                                  and cn['mode'] == 'input'):
                                self.connect_in_to_out(node)
                cn = self.connecting_node
Ejemplo n.º 3
0
    def on_mouse_press(self, x, y, button, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.screen_size)

        if self.intersect_corner((x, y)):
            self.resize = True
        elif button == 1 and self.hover:
            self.set_focus()
            self.caret.on_mouse_press(x, y, button, modifiers)
Ejemplo n.º 4
0
    def on_mouse_press(self, x, y, button, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.screen_size)

        if button == 1:
            if self.hover:
                self.set_focus()
                self.caret.on_mouse_press(x, y, button, modifiers)
            else:
                self.lost_focus()
Ejemplo n.º 5
0
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.screen_size)
        dx, dy = int(dx / self.pan_scale[1]), int(dy / self.pan_scale[1])

        if buttons == 1 and self.resize:
            width = max(self.node.editor_size[0] + dx, 300)
            height = max(self.node.editor_size[1] - dy, 150)
            self.node.editor_size = width, height
        elif buttons == 1 and self.hover:
            self.caret.on_mouse_drag(x, y, dx, dy, buttons, modifiers)
Ejemplo n.º 6
0
    def on_mouse_press(self, x, y, button, modifiers):
        if self.menu.click(x, y):
            return

        x, y = x_y_pan_scale(x, y, self.pan_scale, self.get_size())

        if button == 1:
            if self.field:
                self.pop_handlers()
                self.push_handlers()
                self.field = None
            if self.code_editor:
                if self.code_editor.intersect_point((x, y)):
                    return
                else:
                    if self.code_editor.hover:
                        self.pop_handlers()
                        self.push_handlers()
                    self.code_editor = None
            for node in self.nodes:
                if node.intersect_point((x, y)):
                    if (node in self.selected_nodes
                            and len(self.selected_nodes) > 1):
                        self.node_drag = True
                        return
                    else:
                        si = node.selectedInput['name'] != 'none'
                        so = node.selectedOutput['name'] != 'none'
                        if si or so:
                            self.pointer = (x, y)
                            self.connection = True
                            if si:
                                self.disconnect_node(node)
                            elif so:
                                self.connecting_node = \
                                    {'node': node,
                                     'put': node.selectedOutput,
                                     'mode': 'output'}
                            return
                        if isinstance(node, Node):
                            self.code_editor = CodeEditor(node)
                        elif isinstance(node, Field) and not self.field:
                            self.push_handlers(node)
                            self.field = node
                        self.selected_nodes = [node]
                        self.node_drag = True
                        return
            self.select = True
            self.selectPoint = (x, y)
Ejemplo n.º 7
0
    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        x, y = x_y_pan_scale(x, y, self.pan_scale, self.get_size())
        dx, dy = int(dx / self.pan_scale[1]), int(dy / self.pan_scale[1])

        if self.node_drag and buttons != 5:
            for node in self.selected_nodes:
                node.x += dx
                node.y += dy
                node.make_child_active()
        elif self.select:
            self.w = self.selectPoint
            self.c = (x, y)
        elif self.connection:
            self.pointer = (x, y)
            for node in self.nodes:
                node.intersect_point((x, y))

        if buttons == 4 or buttons == 5:
            self.pan_scale[0][0] += dx
            self.pan_scale[0][1] += dy
Ejemplo n.º 8
0
    def on_mouse_motion(self, x, y, dx, dy):
        self.mouse = (x, y)

        x, y = x_y_pan_scale(x, y, self.pan_scale, self.get_size())
        self.pointer = (x, y)

        if not self.selected_nodes:
            if self.code_editor:
                if self.code_editor.intersect_point(self.pointer):
                    if not self.code_editor.hover and not self.field:
                        self.push_handlers(self.code_editor)
                    self.code_editor.pan_scale = self.pan_scale
                    self.code_editor.screen_size = self.get_size()
                    self.code_editor.hover = True
                    self.code_editor.node.hover = True
                    return
            elif self.field:
                if self.field.intersect_point((x, y)):
                    self.field.pan_scale = self.pan_scale
                    self.field.screen_size = self.get_size()