Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
moveimage.py
import ui
class MoveView(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.current_location = None
self.image = ui.Image('test:Mandrill')
self.iv = ui.ImageView(image=self.image)
self.add_subview(self.iv)
def touch_began(self, touch):
self.current_location = touch.location
def change_size(self):
self.remove_subview(self.iv)
self.iv = ui.ImageView(frame=(0,0,self.width, self.height), image=self.image)
self.add_subview(self.iv)
def touch_moved(self, touch):
sgindex = self.superview['segmentedcontrol1'].selected_index
x,y = touch.location
if self.current_location:
x1, y1 = self.current_location
else:
self.current_location = x,y
return
self.current_location = x,y
if sgindex == 0:
self.x += (x-x1)
self.y += (y-y1)
elif sgindex == 1:
self.x += (x-x1)
elif sgindex == 2:
self.y += (y-y1)
elif sgindex == 3:
self.width += (x-x1)
self.height += (y-y1)
self.change_size()
elif sgindex == 4:
self.width += (x-x1)
self.change_size()
elif sgindex == 5:
self.height += (y-y1)
self.change_size()
def touch_ended(self, touch):
self.current_location = None
v = ui.load_view()
v.present('sheet')
[
{
"class" : "View",
"attributes" : {
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)",
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)",
"enabled" : true,
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)",
"flex" : ""
},
"frame" : "{{0, 0}, {500, 500}}",
"selected" : false,
"nodes" : [
{
"class" : "View",
"attributes" : {
"name" : "view1",
"corner_radius" : 0,
"border_width" : 1,
"class" : "View",
"frame" : "{{244, 222}, {100, 100}}",
"custom_class" : "MoveView",
"uuid" : "0F68E9E0-8A86-4CEB-ABA8-81ABB150D594"
},
"frame" : "{{200, 200}, {100, 100}}",
"selected" : false,
"nodes" : [
]
},
{
"class" : "SegmentedControl",
"attributes" : {
"flex" : "LR",
"segments" : "xy|x|y|wh|w|h",
"name" : "segmentedcontrol1",
"action" : "",
"class" : "SegmentedControl",
"frame" : "{{234, 258}, {120, 29}}",
"uuid" : "E37907E4-B4F6-45A5-B3AD-254417A14FB8"
},
"frame" : "{{25, 425}, {450, 50}}",
"selected" : true,
"nodes" : [
]
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.