def gestureAction(_self, _cmd):
        self = ObjCInstance(_self)
        view = self.view
        recognizer = self.recognizer
        handler_func = self.handler_func
        data = Data()
        data.recognizer = recognizer
        data.view = view
        location = recognizer.locationInView_(view.objc_instance)
        data.location = ui.Point(location.x, location.y)
        data.state = recognizer.state()
        data.number_of_touches = recognizer.numberOfTouches()

        if (_is_objc_type(recognizer, UIPanGestureRecognizer) or _is_objc_type(
                recognizer, UIScreenEdgePanGestureRecognizer)):
            trans = recognizer.translationInView_(ObjCInstance(view))
            vel = recognizer.velocityInView_(ObjCInstance(view))
            data.translation = ui.Point(trans.x, trans.y)
            data.velocity = ui.Point(vel.x, vel.y)
        elif _is_objc_type(recognizer, UIPinchGestureRecognizer):
            data.scale = recognizer.scale()
            data.velocity = recognizer.velocity()
        elif _is_objc_type(recognizer, UIRotationGestureRecognizer):
            data.rotation = recognizer.rotation()
            data.velocity = recognizer.velocity()

        handler_func(data)
Beispiel #2
0
    def _pan_action(self, sender):
        (data, action) = self._context(sender)
        trans = data.recognizer.translationInView_(ObjCInstance(data.view))
        vel = data.recognizer.velocityInView_(ObjCInstance(data.view))
        data.translation = ui.Point(trans.x, trans.y)
        data.velocity = ui.Point(vel.x, vel.y)

        action(data)
Beispiel #3
0
 def __init__(self, id, touch, node):
   self.touch_id = id
   self.phase = ('began', 'moved', 'stationary', 'ended', 'cancelled')[touch.phase()]
   loc = touch.locationInNode_(node)
   self.location = ui.Point(loc.x, loc.y)
   prev = touch.previousLocationInNode_(node)
   self.prev_location = ui.Point(prev.x, prev.y)
   self.timestamp = touch.timestamp()
 def __init__(self,
              location=ui.Point(0, 0),
              prev_location=ui.Point(0, 0),
              phase=0,
              timestamp=0):
     self.location = location
     self.prev_location = prev_location
     self.phase = phase
     self.timestamp = timestamp
def cg_to_py(value):
    if type(value) == ObjCInstanceMethodProxy:
        value = value()
    if type(value) == CGPoint:
        return ui.Point(value.x, value.y)
    elif type(value) == CGVector:
        return ui.Point(value.dx, value.dy)
    elif type(value) == CGRect:
        return Rect(value.origin.x, value.origin.y, value.size.width,
                    value.size.height)
    elif type(value) == CGSize:
        return Size(value.width, value.height)
Beispiel #6
0
	def touch_begann(self,touch):
		'''when starting a touch, fiest check if there are any points very near by.  if so, set currpt to that to allow dragging prsvious points,
		if not, add a new point.
		'''
		self.curridx=-1
		currpt=(touch.location.x,touch.location.y)
		#search existing points for a near match
		for i,p in enumerate(self.pts):
			if abs(ui.Point(*p)-ui.Point(*currpt))<20:
				self.curridx=i
		# if not match found, add a new point
		if self.curridx==-1:
			self.pts.append(currpt)
		self.set_needs_display()	
Beispiel #7
0
 def __init__(self, *args, **kwargs):
     ui.View.__init__(self, *args, **kwargs)
     MKMapView = ObjCClass('MKMapView')
     frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height))
     self.mk_map_view = MKMapView.alloc().initWithFrame_(frame)
     flex_width, flex_height = (1 << 1), (1 << 4)
     self.mk_map_view.setAutoresizingMask_(flex_width | flex_height)
     self_objc = ObjCInstance(self)
     self_objc.addSubview_(self.mk_map_view)
     self.mk_map_view.release()
     self.long_press_action = None
     self.scroll_action = None
     #NOTE: The button is only used as a convenient action target for the gesture recognizer. While this isn't documented, the underlying UIButton object has an `-invokeAction:` method that takes care of calling the associated Python action.
     self.gesture_recognizer_target = ui.Button()
     self.gesture_recognizer_target.action = self.long_press
     UILongPressGestureRecognizer = ObjCClass(
         'UILongPressGestureRecognizer')
     self.recognizer = UILongPressGestureRecognizer.alloc(
     ).initWithTarget_action_(self.gesture_recognizer_target,
                              sel('invokeAction:')).autorelease()
     self.mk_map_view.addGestureRecognizer_(self.recognizer)
     self.long_press_location = ui.Point(0, 0)
     self.map_delegate = OMMapViewDelegate.alloc().init()  #.autorelease()
     self.mk_map_view.setDelegate_(self.map_delegate)
     self.map_delegate.map_view_ref = weakref.ref(self)
     _map_delegate_cache[self.map_delegate.ptr] = self.map_delegate
def drawRandomPath(path):
    center = ui.Point(canvasWidth / 2, canvasHeight / 2)
    path.move_to(center.x, center.y)

    drawLoop = random.randint(3, 40)  #100

    for i in range(drawLoop):
        lineType = random.choice(("line", "curve"))
        if (lineType == "line"):
            path.line_to(getRandomLength(), getRandomLength())
        else:
            path.add_quad_curve(getRandomLength(), getRandomLength(),
                                getRandomLength(), getRandomLength())

    path.close()

    r = getRandomColor()
    g = getRandomColor()
    b = getRandomColor()
    fillColor = (r, g, b)
    ui.set_color(fillColor)
    path.fill()

    drawColor = (r - 0.1, g - 0.1, b - 0.1)
    ui.set_color(drawColor)
    if drawLoop < 40:
        path.stroke()
 def long_press(self, sender):
     #NOTE: The `sender` argument will always be the dummy ui.Button that's used as the gesture recognizer's target, just ignore it...
     gesture_state = self.recognizer.state()
     if gesture_state == 1 and callable(self.long_press_action):
         loc = self.recognizer.locationInView_(self.mk_map_view)
         self.long_press_location = ui.Point(loc.x, loc.y)
         self.long_press_action(self)
Beispiel #10
0
def draw_random():
	with ui.ImageContext(canvasWidth, canvasHeight) as imageContext:
		
		rect = ui.Path.rect(border, border, canvasWidth - border*2, canvasHeight - border*2)
		ui.set_color("white")
		rect.fill()
		
		path = ui.Path()
		center = ui.Point(canvasWidth/2, canvasHeight/2)
		path.move_to(center.x, center.y)		
		
		drawLoop = random.randint(3, 100)
		
		for i in range(drawLoop):
			lineType = random.choice(("line", "curve"))
			if(lineType == "line"):
				path.line_to(getRandomLength(), getRandomLength())
			else:
				path.add_quad_curve(getRandomLength(), getRandomLength(), getRandomLength(), getRandomLength())
		
		path.close()
		
		r = getRandomColor()
		g = getRandomColor()
		b = getRandomColor()
		fillColor = (r, g, b)
		ui.set_color(fillColor)
		path.fill()
		
		drawColor = (r-0.1, g-0.1, b-0.1)
		ui.set_color(drawColor)
		if drawLoop < 40:
			path.stroke()
		
		return imageContext.get_image()
Beispiel #11
0
def draw_random():
    with ui.ImageContext(canvasWidth, canvasHeight) as imageContext:

        rect = ui.Path.rect(border, border, canvasWidth - border * 2,
                            canvasHeight - border * 2)
        ui.set_color("white")
        rect.fill()

        path = ui.Path()
        center = ui.Point(250, 250)
        path.move_to(center.x, center.y)

        drawLoop = random.randint(3, 100)

        for i in range(drawLoop):
            path.line_to(getRandomLength(), getRandomLength())

        path.close()

        r = getRandomColor()
        g = getRandomColor()
        b = getRandomColor()
        fillColor = (r, g, b)
        ui.set_color(fillColor)
        path.fill()

        drawColor = (r - 0.1, g - 0.1, b - 0.1)
        ui.set_color(drawColor)
        path.stroke()

        return imageContext.get_image()
Beispiel #12
0
    def draw(self):
        ''' called by iOS whenever set_needs_display is called, or whenever os decides it is needed, for instance view rotates'''
        # set color to red
        ui.set_color((1, 0, 0))
        # create a copy of self.pts, and append the current point
        drawpts = self.pts

        if drawpts:
            # move path to first point:
            pth = ui.Path()
            pth.move_to(*drawpts[0])
            p0 = drawpts[0]
            for p in drawpts[1:]:
                # for each point after the first, draw a line from the previous point, compute length vector L
                # draw the line segment
                pth.line_to(*p)
                # compute point which is halfway along line between the
                # start/end point.  L is the vector pointing from start to
                # finish.  H is the Point at the halfway, referenced back to
                # global origin
                L = (ui.Point(*p) - ui.Point(*p0))
                P0 = ui.Point(*p0)
                H = P0 + L / 2  # halfway point
                # put text at the halfway point, containing length ofmsegment *
                # scale
                ui.draw_string('%3.2f' % abs(L * self.scale.value / 10),
                               (H.x, H.y, 0, 0),
                               color='red')
                # set starting point for next line segment
                p0 = p
            pth.stroke()  # draw the path
            if len(drawpts) > 2:  # 'close' the path to show area computed
                with ui.GState():
                    pth = ui.Path()
                    pth.move_to(*drawpts[-1])
                    pth.line_to(*drawpts[0])
                    pth.set_line_dash([2, 3])
                    ui.set_color((1, .5, .5, .5))
                    pth.stroke()
            # create a 10 pixel circle at last entered point
            ui.Path.oval(drawpts[-1][0] - 5, drawpts[-1][1] - 5, 10, 10).fill()
            # show circles for previously entered points. smaller and lighter
            ui.set_color((1, .5, .5))
            for p in drawpts[0:-1]:
                ui.Path.oval(p[0] - 3, p[1] - 3, 6, 6).fill()
Beispiel #13
0
	def touch_began(self,touch):
		l=list(touch.location)
		self._pt=l
		self.set_needs_display()
		if ui.Point(*l) in self.resize.frame:
			self.resizing=True
		else:
			self.resizing=False
		self.parent.bringSubviewToFront_(self)
Beispiel #14
0
	def handle_touch_moved(self,data):
		if hasattr(self,'data'):
			dt=data.translation-self.data.translation
		else:
			dt=data.translation
		self.touch_moved(Touch(data.location, data.location-dt, data.state))
		self.data=data
		if data.state==Gestures.ENDED:
			self.data.translation=ui.Point(0,0)
			self.touch_ended(Touch(data.location, data.location-dt, data.state))
    def __init__(self, *args, **kwargs):
        ui.View.__init__(self, *args, **kwargs)
        MKMapView = ObjCClass('MKMapView')

        frame = CGRect(CGPoint(0, 0), CGSize(self.width, self.height))
        self.mk_map_view = MKMapView.alloc().initWithFrame_(frame)
        self.mk_map_view.ui_view = self
        #print(dir(self.mk_map_view.region()))
        flex_width, flex_height = (1 << 1), (1 << 4)
        self.mk_map_view.setAutoresizingMask_(flex_width | flex_height)
        self_objc = ObjCInstance(self)
        self_objc.addSubview_(self.mk_map_view)
        self.mk_map_view.release()
        self.long_press_action = None
        self.scroll_action = None
        #NOTE: The button is only used as a convenient action target for the gesture recognizer. While this isn't documented, the underlying UIButton object has an `-invokeAction:` method that takes care of calling the associated Python action.
        self.gesture_recognizer_target = ui.Button()
        self.gesture_recognizer_target.action = self.long_press
        UILongPressGestureRecognizer = ObjCClass(
            'UILongPressGestureRecognizer')
        self.recognizer = UILongPressGestureRecognizer.alloc(
        ).initWithTarget_action_(self.gesture_recognizer_target,
                                 sel('invokeAction:')).autorelease()
        self.mk_map_view.addGestureRecognizer_(self.recognizer)
        self.long_press_location = ui.Point(0, 0)
        self.map_delegate = MyMapViewDelegate.alloc().init()  #.autorelease()
        self.mk_map_view.setDelegate_(self.map_delegate)
        self.map_delegate.map_view_ref = weakref.ref(self)
        _map_delegate_cache[self.map_delegate.ptr] = self.map_delegate

        # Add a map type button
        maptype_button = ui.Button()
        maptype_button.frame = (self.width - 82, 2, 80, 20)
        maptype_button.border_width = 1
        maptype_button.corner_radius = 5
        maptype_button.border_color = 'red'
        maptype_button.background_color = (1, 0, 0, 0.8)
        maptype_button.tint_color = 'black'
        maptype_button.title = 'map type'
        maptype_button.action = self.maptype_button_action
        self.add_subview(maptype_button)
        self.mk_map_view.mapType = 0

        camera_button = ui.Button()
        camera_button.frame = (maptype_button.x - 40 - 2, 2, 40, 20)
        camera_button.border_width = 1
        camera_button.corner_radius = 5
        camera_button.border_color = 'red'
        camera_button.background_color = (1, 0, 0, 0.8)
        self.add_subview(camera_button)
        camera_button.tint_color = 'black'
        camera_button.title = '3D'
        camera_button.action = self.camera_button_action

        self.update_interval = 2  # call update each 2 seconds
 def draw(self):
     ui.set_color((1, 0, 0))
     drawpts = [p for p in self.pts]
     if self.currpt:
         drawpts += [self.currpt]
     if drawpts:
         pth = ui.Path()
         pth.move_to(*drawpts[0])
         p0 = drawpts[0]
         for p in drawpts[1:]:
             if p:
                 pth.line_to(*p)
                 L = (ui.Point(*p) - ui.Point(*p0))
                 P0 = ui.Point(*p0)
                 p0 = p
                 H = P0 + L / 2
                 ui.draw_string('%3.2f' % abs(L * float(self.scale.text)),
                                (H.x, H.y, 0, 0),
                                color='red')
         pth.stroke()
         ui.Path.oval(drawpts[-1][0] - 5, drawpts[-1][1] - 5, 10, 10).fill()
Beispiel #17
0
def draw_pie(p, r, fill_color='black'):
    p = max(0.0, min(1.0, p))
    ui.set_color(fill_color)
    path = ui.Path()
    center = ui.Point(r, r)
    path.move_to(center.x, center.y)
    start = radians(-90)
    end = start + p * radians(360)
    path.add_arc(r, r, r, start, end)
    path.close()
    ui.set_color(fill_color)
    path.fill()
Beispiel #18
0
def draw_pie(p, r, fill_color='black'):
    p = max(0.0, min(1.0, p))
    with ui.ImageContext(r * 2, r * 2) as ctx:
        ui.set_color(fill_color)
        path = ui.Path()
        center = ui.Point(r, r)
        path.move_to(center.x, center.y)
        start = radians(-90)
        end = start + p * radians(360)
        path.add_arc(r, r, r, start, end)
        path.close()
        ui.set_color(fill_color)
        path.fill()
        return ctx.get_image()
    def draw(self):
        if not self.drawing_on: return

        cr = ui.Rect(*self.bounds).inset(*self.margin)

        p = max(0.0, min(1.0, self.value))
        r = cr.width / 2
        path = ui.Path.oval(*cr)
        path.line_width = .5
        ui.set_color(self.stroke_color)
        path.stroke()
        center = ui.Point(r, r)
        path.move_to(center.x, center.y)
        start = radians(-90)
        end = start + p * radians(360)
        path.add_arc(r, r, r, start, end)
        path.close()
        ui.set_color(self.fill_color)
        path.eo_fill_rule = True
        path.fill()

        self.draw_label()
Beispiel #20
0
	def owner_draw(self):
		owner = self.owner
	
		cell_rect = owner.cv
		
		p = max(0.0, min(1.0, owner.value))
		r = cell_rect.width / 2
		ui.set_color(owner.fill_color)
		
		path = ui.Path.oval(*cell_rect.inset(1, 1))	
		path.line_width = .5
		center = ui.Point(r, r)
		path.move_to(center.x, center.y)
		start = radians(-90)
		end = start + p * radians(360)
		path.add_arc(r, r, r, start, end)
		path.close()
		ui.set_color(owner.fill_color)
		path.eo_fill_rule = True
		path.fill()
		
		self.draw_label()
# coding: utf-8

# https://forum.omz-software.com/topic/2518/tip-useful-objects-like-rect-obj-in-scene-module-others-also


from scene import Rect

#==============================

import scene, ui
assert dir(scene.Point())   == dir(ui.Point())
assert dir(scene.Rect())    == dir(ui.Rect())
assert dir(scene.Vector2()) == dir(ui.Vector2())
print('Success!')

#==============================

>>> ui.Rect(1,1,5,5) in ui.Rect(0,0,10,10)
True
>>> ui.Rect(1,1,15,15) in ui.Rect(0,0,10,10)
False
>>> ui.Point(1,1) in ui.Rect(0,0,10,10)
True
>>> ui.Point(-1,1) in ui.Rect(0,0,10,10)
False

#==============================

assert(ui.Rect is scene.Rect)

#==============================
Beispiel #22
0
 def _location(self, view, recog):
     loc = recog.locationInView_(ObjCInstance(view))
     return ui.Point(loc.x, loc.y)