Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from pymt import *
- class PDWorkspace(MTWindow):
- def __init__(self, **kwargs):
- super(PDWorkspace, self).__init__(**kwargs)
- class MTRect(MTWidget):
- def __init__(self, color, **kwargs):
- super(MTRect, self).__init__(**kwargs)
- self.color = color
- def draw(self):
- set_color(self.color)
- drawRectangle(self.pos, self.size)
- class PDWidget(MTSlider):
- _inlets = [] # inlets list
- _outlets = [] # outlets list
- _object = None # object
- connections = [] # Ponto final da conex�o, o inicial � no outlet
- drawLine = False
- initial_point = (0, 0)
- cursor_point = (0, 0)
- def __init__(self, inlets, outlets, **kwargs):
- super(PDWidget, self).__init__(**kwargs) # MTWidget init
- for x in range(inlets):
- self._inlets.append(MTRect((0,1,1,1), pos=(self.pos[0], self.pos[1] + self.size[1]), size=(10, 10)))
- self.add_widget(self._inlets[x])
- self._inlets[x]
- for x in range(outlets):
- self._outlets.append(MTRect((1,0,0,1), pos=(self.pos[0], self.pos[1] - 10), size=(10,10)))
- self.add_widget(self._outlets[x])
- def on_touch_down(self, touch):
- for outlet in self._outlets:
- if(outlet.collide_point(touch.x, touch.y)):
- self.drawLine = True
- self.initial_point = touch.pos
- super(PDWidget, self).on_touch_down(touch)
- def on_touch_move(self, touch):
- if self.drawLine:
- self.cursor_point = touch.pos
- super(PDWidget, self).on_touch_move(touch)
- def on_touch_up(self, touch):
- for widget in self.parent.children:
- if widget != self and isinstance(widget, PDWidget):
- for inlet in widget._inlets:
- if inlet.collide_point(touch.x, touch.y):
- connections.append((self.initial_point,touch.pos))
- self.drawLine = False
- def draw(self):
- self.pos = self.parent.pos
- if self.drawLine:
- drawLine([self.initial_point[0], self.initial_point[1], self.cursor_point[0], self.cursor_point[1]], width=1)
- for connection in connections:
- drawLine([connection[0][0],connection[0][1], connection[1][0], connection[1][1]], width=1)
- super(PDWidget, self).draw()
- if __name__ == "__main__":
- workspace = MTWindow()
- test = PDWidget(1, 1, pos=(100,300))
- scat = MTScatterWidget()
- w = MTWidget()
- w.add_widget(test)
- scat.add_widget(w)
- workspace.add_widget(scat)
- '''
- @scat.event
- def on_touch_down(touch):
- for x in scat.children:
- x.on_touch_down(touch)
- @scat.event
- def on_touch_move(touch):
- for x in scat.children:
- x.on_touch_move(touch)
- @scat.event
- def on_touch_up(touch):
- for x in scat.children:
- x.on_touch_up(touch)
- '''
- runTouchApp()
Advertisement
Add Comment
Please, Sign In to add comment