Guest User

Untitled

a guest
May 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.00 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from pymt import *
  3.  
  4. class PDWorkspace(MTWindow):
  5.  
  6.     def __init__(self, **kwargs):
  7.         super(PDWorkspace, self).__init__(**kwargs)
  8.  
  9. class MTRect(MTWidget):
  10.  
  11.     def __init__(self, color, **kwargs):
  12.         super(MTRect, self).__init__(**kwargs)
  13.         self.color = color
  14.  
  15.     def draw(self):
  16.         set_color(self.color)
  17.         drawRectangle(self.pos, self.size)
  18.  
  19. class PDWidget(MTSlider):
  20.  
  21.     _inlets = [] # inlets list
  22.     _outlets = [] # outlets list
  23.     _object = None # object
  24.  
  25.     connections = [] # Ponto final da conex�o, o inicial � no outlet
  26.  
  27.     drawLine = False
  28.     initial_point = (0, 0)
  29.     cursor_point = (0, 0)
  30.  
  31.     def __init__(self, inlets, outlets, **kwargs):
  32.  
  33.         super(PDWidget, self).__init__(**kwargs) # MTWidget init
  34.  
  35.         for x in range(inlets):
  36.             self._inlets.append(MTRect((0,1,1,1), pos=(self.pos[0], self.pos[1] + self.size[1]), size=(10, 10)))
  37.             self.add_widget(self._inlets[x])
  38.             self._inlets[x]        
  39.  
  40.         for x in range(outlets):
  41.             self._outlets.append(MTRect((1,0,0,1), pos=(self.pos[0], self.pos[1] - 10), size=(10,10)))
  42.             self.add_widget(self._outlets[x])
  43.  
  44.     def on_touch_down(self, touch):
  45.         for outlet in self._outlets:
  46.             if(outlet.collide_point(touch.x, touch.y)):
  47.                 self.drawLine = True
  48.                 self.initial_point = touch.pos
  49.  
  50.         super(PDWidget, self).on_touch_down(touch)
  51.  
  52.     def on_touch_move(self, touch):
  53.         if self.drawLine:
  54.             self.cursor_point = touch.pos
  55.  
  56.         super(PDWidget, self).on_touch_move(touch)
  57.  
  58.     def on_touch_up(self, touch):
  59.         for widget in self.parent.children:
  60.             if widget != self and isinstance(widget, PDWidget):
  61.                 for inlet in widget._inlets:
  62.                     if inlet.collide_point(touch.x, touch.y):
  63.                         connections.append((self.initial_point,touch.pos))
  64.         self.drawLine = False
  65.    
  66.     def draw(self):
  67.         self.pos = self.parent.pos
  68.  
  69.         if self.drawLine:
  70.             drawLine([self.initial_point[0], self.initial_point[1], self.cursor_point[0], self.cursor_point[1]], width=1)
  71.         for connection in connections:
  72.             drawLine([connection[0][0],connection[0][1], connection[1][0], connection[1][1]], width=1)
  73.        
  74.  
  75.         super(PDWidget, self).draw()
  76.            
  77. if __name__ == "__main__":
  78.  
  79.     workspace = MTWindow()
  80.     test = PDWidget(1, 1, pos=(100,300))
  81.     scat = MTScatterWidget()
  82.     w = MTWidget()
  83.     w.add_widget(test)
  84.     scat.add_widget(w)
  85.     workspace.add_widget(scat)
  86.     '''
  87.    @scat.event
  88.    def on_touch_down(touch):
  89.        for x in scat.children:
  90.            x.on_touch_down(touch)
  91.  
  92.    @scat.event
  93.    def on_touch_move(touch):
  94.        for x in scat.children:
  95.            x.on_touch_move(touch)
  96.  
  97.    @scat.event
  98.    def on_touch_up(touch):
  99.        for x in scat.children:
  100.            x.on_touch_up(touch)
  101.  
  102.    '''
  103.  
  104.     runTouchApp()
Advertisement
Add Comment
Please, Sign In to add comment