本文整理汇总了Python中kivy.uix.scatter.Scatter类的典型用法代码示例。如果您正苦于以下问题:Python Scatter类的具体用法?Python Scatter怎么用?Python Scatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_touch_up
def on_touch_up(self, touch):
"""
Defines action whe the criterion is touched up
:param touch: the touch point (position, type of touch, ...)
"""
if not self.destroyed:
from ZoneUtilisateur import ZoneUtilisateur
if self.collide_point(touch.x, touch.y) and self.parent is not None and self.support != "tablette" and not self.validated:
for child in self.parent.children:
if child.__class__ == ZoneUtilisateur and child.collide_point(self.center[0], self.center[1]) and child.is_connected():
data = '{"Criterion" : "' + self.texte + '", "IdUser" : "' + str(
self.createur.identifier) + '", "TextType" : "' + self.text_type + '", "Links" : ['
for link in self.links:
data += '{ "IdImage" :"' + str(link.id_img) + '",'
data += '"SrcImage" : "' + self.parent.get_animal(link.id_img).src_image + '",'
data += '"IdUser" :"' + str(link.id_usr) + '",'
data += '"Distance" :"' + str(link.distance) + '",'
data += '"Angle" :"' + str(link.angle) + '"},'
if len(self.links) > 0:
data = data[:-1]
data += '], "Fusionneurs" : ['
for participants in self.fusionneurs:
data += '{"IdUser" : "' + str(participants.identifier) + '"},'
if len(self.fusionneurs) > 0 :
data = data[:-1]
data += ']}\n'
self.parent.server.send_msg(data, child.user.socket)
self.canvas.clear()
self.destroyed = True
self.parent.criterions.remove(self)
self.parent.remove_widget(self)
Scatter.on_touch_up(self, touch)
示例2: build
def build(self):
f = FloatLayout()
s = Scatter()
l = Label(text="Hello!", font_size=150)
f.add_widget(s)
s.add_widget(l)
return f
示例3: build
def build(self):
f = FloatLayout()
b = Button(pos_hint={'x': 0.5, 'center_y': .5},text='Hello world', font_size=14)
s = Scatter()
l = Label(text="Hello!",font_size=150)
def select_to(*args):
try:
print args[1][0]
except:
pass
fi = FileChooserIconView()
f.add_widget(s)
s.add_widget(l)
l.add_widget(b)
def callback(instance):
print('The button <%s> is being pressed' % instance.text)
f.add_widget(fi)
b.bind(on_press=callback)
fi.bind(on_selection=select_to)
return f
示例4: on_touch_down
def on_touch_down (self, touch):
if not 'markerid' in touch.profile:
return
hand_id = int(touch.fid / self.hand_gesture_offset)
gesture_id = touch.fid % self.hand_gesture_offset
if not self.object_moving and gesture_id == self.grab_gesture:
self.canvas.clear()
self.draw()
self.canvas.add(Ellipse(pos=(touch.x-self.x, touch.y-self.y), size=(30,30)))
"""
" grab "
"""
if self.my_object.collide_point(touch.x-self.x, touch.y-self.y):
self.play_grab_sound()
# does not seem necessary
# self.my_object.dispatch('on_touch_down', touch)
self.object_moving = True
self.my_object.owner_id = hand_id
self.object_grabbed_event()
return True
# keeps x-location of touch, to use for sliding the workspace later
"""
" sense sliding "
"""
if self.object_moving and hand_id != self.my_object.owner_id:
touch.ud['initial'] = touch.x
print 'started sliding'
# calls same function in it's ancestor
Scatter.on_touch_down(self, touch)
示例5: build
def build(self):
layout_main = BoxLayout(
orientation='vertical',
)
text_input = TextInput(
font_size=150,
height=200,
size_hint_y=None,
text='default',
)
layout = FloatLayout()
scatter = Scatter()
label = Label(
text="default",
font_size=150,
)
text_input.bind(text=label.setter('text'))
layout.add_widget(scatter)
scatter.add_widget(label)
# Order is important - first is top/left
layout_main.add_widget(text_input)
layout_main.add_widget(layout)
return layout_main
示例6: __init__
def __init__(self, **kwargs):
super(ImagesCarousel, self).__init__(**kwargs)
for image in carousel_images:
scatter = Scatter()
image_to_add = Image(source=mypath+image)
scatter.add_widget(image_to_add)
self.add_widget(scatter)
示例7: __init__
def __init__(self,*args, **kwargs):
super(ImagesCarousel, self).__init__(**kwargs)
for image in carousel_images:
scatter = Scatter(pos=(100,200), scale=4, do_scale=True)
image_to_add = Image(source=images_path+image)
scatter.add_widget(image_to_add)
self.add_widget(scatter)
示例8: on_touch_up
def on_touch_up (self, touch):
# calls same function in it's ancestor, and slides the workspace
Scatter.on_touch_up(self, touch)
if not 'markerid' in touch.profile:
return
hand_id = int(touch.fid / self.hand_gesture_offset)
gesture_id = touch.fid % self.hand_gesture_offset
self.canvas.clear()
self.draw()
"""
" starts sliding "
"""
if ('initial' in touch.ud) and touch.ud['initial'] != None and self.object_moving and hand_id != self.my_object.owner_id and self.x <= 0 and ((-1*self.x) % self.single_width() == 0):
print 'about to slide'
current = self.current_workspace()
if touch.ud['initial'] > touch.x:
if abs(touch.ud['initial'] - touch.x) > self.slide_threshold:
current = current + 1
if current >= len(self.frames):
current = len(self.frames) - 1
else:
self.workspace_slide_event()
else:
if abs(touch.ud['initial'] - touch.x) > self.slide_threshold:
current = current - 1
if current < 0:
current = 0
else:
self.workspace_slide_event()
self.slide(current)
touch.ud['initial'] = None
return False
示例9: on_touch_move
def on_touch_move(self, touch):
"""
Update the distance and angle between the animal and each of his links and set the user touching the animal
:param touch: the position of the touch
"""
from main import Tablette
if self.collide_point(touch.x, touch.y) and self.parent is not None:
for criterion in self.parent.criterions:
value = criterion.has_link(self.identifier)
if value != -1:
criterion.update_link(value, self.center)
for child in self.parent.children:
if child.__class__ == ZoneUtilisateur and child.collide_point(self.center[0], self.center[1]):
if self.current_user is None or self.current_user.identifier != child.user.identifier:
self.parent.server.send_msg(
'{"Image" : "' + str(self.src_image) + '", "ID" : "' + str(self.identifier) + '"}\n',
child.user.socket)
self.set_user(child.user)
if self.parent.__class__.__name__ == Tablette.__name__:
if touch.y > self.parent.height - 40:
self.parent.client.send_msg('{"Animal" : "' + str(self.identifier) + '"}')
self.parent.remove_animal(self)
Scatter.on_touch_move(self, touch)
示例10: input_menu
def input_menu(self):
''' create containers for menu gui '''
main_layout = BoxLayout(orientation='vertical', size_hint=(None, None), size=(400,200))
button_layout = BoxLayout(orientation='horizontal')
# add transparent background
with main_layout.canvas.before:
Color(.5, .5, .5, .2)
self.rect = Rectangle(size=main_layout.size, pos=main_layout.pos)
# create components
label = Label(font_size=25, text='Enter Username')
done_button = Button(font_size=25, text='Done')
exit_button = Button(font_size=25, text='Exit')
# button events
done_button.bind(on_release=self.get_flickr_images)
exit_button.bind(on_release=self.exit_application)
# add components to containers
main_layout.add_widget(label)
main_layout.add_widget(textbox)
button_layout.add_widget(done_button)
button_layout.add_widget(exit_button)
main_layout.add_widget(button_layout)
s = Scatter(size_hint=(None, None), size=(450,250), pos=(300, 300), do_rotation=False, do_scale=False)
s.add_widget(main_layout)
self.root.add_widget(s)
示例11: set_background
def set_background(self):
graphics_widget = FloatLayout()
for td in self.textures_data:
filename,xpos,ypos,width,height = td.split(":")
xpos = float(xpos)
ypos = float(ypos)
image = MyImage(keep_ratio=True, allow_stretch=False, color=(0,0,0,0))
image.set_shadow(False)
with image.canvas:
Rectangle(texture=self.textures[filename].texture, size=(float(width) * X_BLOCK, float(height) * Y_BLOCK))
scatter = Scatter(do_rotation=False, do_scale=False, do_translation=False)
scatter.pos = (xpos * X_BLOCK, ypos * Y_BLOCK)
scatter.add_widget(image)
graphics_widget.add_widget(scatter)
#for td in self.sprites_data:
# filename,xpos,ypos,width,height = td.split(":")
# xpos = float(xpos)
# ypos = float(ypos)
# image = MyImage(texture = self.sprites[filename].texture, keep_ratio=True, allow_stretch=False)
# image.set_shadow(False)
# scatter = Scatter(do_rotation=False, do_scale=False, do_translation=False)
# scatter.pos = (xpos * X_BLOCK, (ypos + 4) * Y_BLOCK / 2)
# scatter.add_widget(image)
# graphics_widget.add_widget(scatter)
# scatter.scale = 6 - ypos * 1.5
return graphics_widget
示例12: on_touch_move
def on_touch_move (self, touch):
if self.object_moving and touch.uid == self.my_object.owner_id:
tx = touch.x
ty = touch.y
tx = self.push_out_border (tx, self.single_width())
ty = self.push_out_border (ty, self.height)
self.my_object.relocate(tx - self.x, ty - self.y)
"""
" border slide "
"""
if self.enable_border_slide:
if self.on_right_border(touch) and not self.sliding:
self.sliding = True
Timer(self.border_delay,self.slide_right).start()
if self.on_left_border(touch) and not self.sliding:
self.sliding = True
Timer(self.border_delay,self.slide_left).start()
if not self.on_right_border(touch) and not self.on_left_border(touch) and self.sliding:
self.stop_slide = True
"""
" highlight target "
"""
if self.my_target.collide_point(touch.x-self.x, touch.y-self.y):
self.my_target.highlight(True)
else:
self.my_target.highlight(False)
if not self.object_moving or touch.uid != self.my_object.owner_id:
Scatter.on_touch_move(self, touch)
示例13: _add_expanded_image
def _add_expanded_image (self, wid):
for child in self._expansion_cont.children:
if type (child) == FloatLayout:
self._expansion_cont.remove_widget (child)
self.pre_cont = BoxLayout (size_hint = (1, 1), padding=10, orientation='horizontal')
self.pre_cont.canvas.add (Color (0,0,0,0.75))
self.pre_cont.canvas.add (Rectangle (size=self._expansion_cont.size))
_handler = Scatter ()
_image = Image (source = self._img.source,
keep_ratio =False, allow_stretch=True)
_btn = Button (text='Hide', size_hint = (0.05, 1))
def _center (wid, val):
img_width = val[0]*0.75
img_height = img_width / _image.image_ratio
_image.size = (img_width, img_height)
_image.pos = ((val[0] - img_width)/2, (val[1] - img_height) / 2)
_handler.bind (size=_center)
_btn.bind (on_release =self._rmv_expanded_image)
_handler.add_widget (_image)
self.pre_cont.add_widget (_btn)
self.pre_cont.add_widget (_handler)
self._expansion_cont.add_widget (self.pre_cont)
示例14: on_touch_down
def on_touch_down(self, touch):
"""
Defines actions to perform when the criterion is touched up
:param touch: the touch point (position, type of touch, ...)
"""
if not self.destroyed:
if self.collide_point(touch.x, touch.y):
Scatter.on_touch_down(self, touch)
if touch.is_double_tap and self.support != "tablette":
if self.zoom_mode:
self.size = (120,120)
self.zoom_mode = False
else:
self.size = (400, 400)
self.zoom_mode = True
self.remove_widget(self.label_question)
self.remove_widget(self.label_text)
self.label_text_pos = [5, 5 + self.size[1] / 5]
self.label_text_size = [self.size[0] - 10, self.size[1] - 30 - 2 * self.size[1] / 5]
self.label_question_pos = [5, self.size[1] - self.size[1] / 5 - 25]
self.label_question_size = [self.size[0] - 10, 20]
self.label_question = Label(text=self.text_type, text_size=self.label_question_size,
pos=self.label_question_pos, halign="left", valign='top',
size=self.label_question_size)
self.label_text = Label(text=self.text, text_size=self.label_text_size, pos=self.label_text_pos,
valign='top', halign="left", size_hint_y=None, multiline=True,
size=self.label_text_size)
self.add_widget(self.label_question)
self.add_widget(self.label_text)
示例15: create_controller
def create_controller():
#create controller for swiping and pinching in the center
# few parameters for scaling
# this defines the active area of dragging/zooming
normal_scale = 4.5
# amount of pinch for zoom in and out
zoom_in_scale = 5.5
zoom_out_scale = 3.5
# distance to drag in x and y direction for action
x_sensitive= Window.center[0]/3
y_sensitive = Window.center[1]/3
# Controller(scatter object) that can be scaled and translate
controller = Scatter(size_hint = (None,None), do_rotation=False, do_translation=True,
do_scale=True, scale = normal_scale,
scale_min= zoom_out_scale, scale_max=zoom_in_scale, center = Window.center)
# a reference object to show the active area
#control_object = Image()
#controller.add_widget(control_object)
#create microscope control parts
microscope_control = microscope_controller()
mc.step = 100
# this provides actions when moving and zooming the scatter objects
def control_feedback(arg1, arg2):
'the callback functions for controller scatter object'
if controller.center[0] - Window.center[0] > x_sensitive:
microscope_control.drag_right()
elif controller.center[0] - Window.center[0] < -1* x_sensitive:
microscope_control.drag_left()
elif controller.center[1] - Window.center[1] > y_sensitive:
microscope_control.drag_top()
elif controller.center[1] - Window.center[1] < -1*y_sensitive:
microscope_control.drag_bot()
elif controller.scale < zoom_out_scale*1.1:
microscope_control.pinch_out()
elif controller.scale > zoom_in_scale*0.9:
microscope_control.pinch_in()
'after taking actions, reset scatter location and scale'
controller.center = Window.center
controller.scale = normal_scale
# bind a function to controller when release touch
controller.bind(on_touch_up = control_feedback)
return controller