本文整理汇总了Python中kivy.uix.image.Image.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Image.bind方法的具体用法?Python Image.bind怎么用?Python Image.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.image.Image
的用法示例。
在下文中一共展示了Image.bind方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
def __init__(self, previous, image_set, fragment_list=None, **kwargs):
super(GameScreen, self).__init__(**kwargs)
# screen we came from, to pass on to game over/victory screen
self.previous = previous
# set image for the map and prepare it for color selection
self.source = image_set.sources["raw"]
self.image.imdata = utils.ImageArray.load(self.source)
self.image.bind(on_touch_down=self.color_drop)
# loads fragments from fragment directory
self.f_index = 0
self.fragments = []
if os.path.exists(config.fragment_directory):
for f in os.listdir(config.fragment_directory):
if fragment_list is None or f in fragment_list:
imgpath = os.path.join(config.fragment_directory, f)
if os.path.isfile(imgpath):
img = Image(source=imgpath)
img.bind(on_touch_down=self.im_press)
self.fragments.append(img)
# cursor options
self.cursor_active = False
self.cursor_array = self.fragments
self.picker = None
self.scatter = None
self.cutter_event = None
# starting values
self.completion = 0
self.tree_start = self.tree.height
self.forest_color = None
self.started = False
示例2: display_help_screen
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
def display_help_screen(self):
# display the help screen on a Popup
image = Image(source='graphics/help_screen.png')
help_screen = Popup(title='Quick Guide through DEFLECTOUCH',
attach_to=self,
size_hint=(0.98, 0.98),
content=image)
image.bind(on_touch_down=help_screen.dismiss)
help_screen.open()
示例3: get_row_item
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
def get_row_item(self, index, controller):
"""
Build and return a formatted DisplayItem for the folder.
"""
# Initialize
album = self.albums[index]
if 'tracks' not in album.keys():
self._populate_album(album)
di = DisplayItem()
add_label = di.ids.labels.add_widget
# Add header
add_label(Label(
text=u"[b][color=#FFFF00]{0} : {1}[/color][/b]".format(
album['artist'], album['album']),
markup=True))
# Add images + warnings
if len(album['images']) == 0:
di.ids.images.add_widget(Image(source="images/album.png"))
else:
for source in album['images']:
image = Image(source=source, allow_stretch=True)
image.bind(on_touch_down=lambda w, t:
w.collide_point(*t.pos) and controller.stop())
di.ids.images.add_widget(image)
[add_label(Label(
text=u"[color=#FF0000]{0}[/color]".format(warn)))
for warn in album['warnings']]
# Add tracks
for k, track in enumerate(album['tracks']):
playing = bool(
controller.playing_album == controller.album_index and
controller.playing_track == k)
pl_label = PlaylistLabel(
controller=controller,
text=track,
album_index=index,
track_index=k)
add_label(pl_label)
if playing:
controller.set_selected(pl_label)
return di
示例4: GridHangman
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class GridHangman(GridLayout):
"""3rd level grid for Hangman graphic."""
def __init__(self, **kwargs):
super(GridHangman, self).__init__(**kwargs)
self.rows = 2
self.row_force_default=True
self.row_default_height=180
self.imgsource = 'images/hangman-1-11.png'
self.hangman = Image(source=self.imgsource, size=(500,500))
self.add_widget(self.hangman)
self.hangman.bind(on_press=change_img)
self.wrongletters = Label(text='')
self.add_widget(self.wrongletters)
self.bind(pos=callback_pos)
示例5: MyBigImage
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class MyBigImage(FloatLayout):
def __init__(self, **kwargs):
super(MyBigImage, self).__init__(**kwargs)
self.velocity = [8, 6]
self.addImage("bluerose.png")
self.sound = self.sound = SoundLoader.load("glass.ogg")
Clock.schedule_interval(self.moving, 1.0/3)
def addImage(self, filename):
self.image = Image(source=filename, mipmap=True)
self.image.size_hint = None, None
self.image.width = 140
self.image.height = 140
self.image.pos = 300+random.randint(-200,200), 200+random.randint(-150,150)
self.add_widget(self.image)
self.image.bind(on_touch_down=self.touchMove)
def moving(self, dt):
self.sound.play()
x, y = self.image.pos
if x < 0: x = 0
if y < 0: y = 0
x = x + self.velocity[0]
y = y + self.velocity[1]
self.image.pos = x, y
ww = app.root.width - 128
hh = app.root.height - 128
if x > ww:
self.velocity[0] = - random.randint(1,10)
elif x <= 0:
self.velocity[0] = random.randint(1,10)
if y > hh:
self.velocity[1] = - random.randint(1,10)
elif y <= 0:
self.velocity[1] = random.randint(1,10)
return
def touchMove(self, image, touch):
if image.collide_point( *touch.pos):
Clock.unschedule(self.moving)
return True
return super(MyBigImage, self).on_touch_down(touch)
示例6: MyBigImage
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class MyBigImage(FloatLayout):
def __init__(self, **kwargs):
super(MyBigImage, self).__init__(**kwargs)
for i in range(20):
self.addImage("bluerose.png")
def addImage(self, filename):
self.image = Image(source=filename, mipmap=True)
self.image.size_hint = None, None
self.image.width = 140
self.image.height = 140
self.image.pos = 300+random.randint(-200,200), 200+random.randint(-150,150)
self.add_widget(self.image)
self.image.bind(on_touch_move=self.touchMove)
def touchMove(self, image, touch):
if image.collide_point( *touch.pos):
image.pos = image.pos[0]+touch.dx, image.pos[1]+touch.dy
return True
return super(MyBigImage, self).on_touch_down(touch)
示例7: AnimatedButton
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class AnimatedButton(Label):
state = OptionProperty('normal', options=('normal', 'down'))
allow_stretch = BooleanProperty(True)
keep_ratio = BooleanProperty(False)
border = ObjectProperty(None)
anim_delay = ObjectProperty(None)
background_normal = StringProperty(
'atlas://data/images/defaulttheme/button')
texture_background = ObjectProperty(None)
background_down = StringProperty(
'atlas://data/images/defaulttheme/button_pressed')
def __init__(self, **kwargs):
super(AnimatedButton, self).__init__(**kwargs)
self.register_event_type('on_press')
self.register_event_type('on_release')
#borderImage.border by default is ...
self.border = (16, 16, 16, 16)
#Image to display depending on state
self.img = Image(source = self.background_normal,
allow_stretch = self.allow_stretch,
keep_ratio = self.keep_ratio, mipmap = True)
#reset animation if anim_delay is changed
def anim_reset(*l):
self.img.anim_delay = self.anim_delay
self.bind(anim_delay = anim_reset)
self.anim_delay = .1
#update self.texture when image.texture changes
self.img.bind(texture = self.on_tex_changed)
self.on_tex_changed()
#update image source when background image is changed
def background_changed(*l):
self.img.source = self.background_normal
self.anim_delay = .1
self.bind(background_normal = background_changed)
def on_tex_changed(self, *largs):
self.texture_background = self.img.texture
def _do_press(self):
self.state = 'down'
def _do_release(self):
self.state = 'normal'
def on_touch_down(self, touch):
if not self.collide_point(touch.x, touch.y):
return False
if self in touch.ud:
return False
touch.grab(self)
touch.ud[self] = True
_animdelay = self.img.anim_delay
self.img.source = self.background_down
self.img.anim_delay = _animdelay
self._do_press()
self.dispatch('on_press')
return True
def on_touch_move(self, touch):
return self in touch.ud
def on_touch_up(self, touch):
if touch.grab_current is not self:
return
assert(self in touch.ud)
touch.ungrab(self)
_animdelay = self.img._coreimage.anim_delay
self.img.source = self.background_normal
self.anim_delay = _animdelay
self._do_release()
self.dispatch('on_release')
return True
def on_press(self):
pass
def on_release(self):
pass
示例8: build
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
def build(self):
self.from_move = None
self.to_move = None
self.chessboard = ChessBoard()
self.analysis_board = ChessBoard()
self.squares = []
self.use_engine = False
self.last_touch_down_move = None
self.last_touch_up_move = None
parent = BoxLayout(size_hint=(1,1))
grid = GridLayout(cols = 8, rows = 8, spacing = 0, size_hint=(1, 1))
for i, name in enumerate(SQUARES):
bt = Image(allow_stretch=True)
bt.sq = i
bt.name = name
# bt.border = [0,0,0,0]
if i in light_squares:
bt.sq_color = "l"
bt.background_down = "img/empty-l.png"
# bt.background_color=[1,1,1,1]
else:
bt.sq_color = "d"
bt.background_down = "img/empty-d.png"
# bt.background_color=[0,0,0,0]
# print i
# bt.bind(on_press=self.callback)
bt.bind(on_touch_down=self.touch_down_move)
bt.bind(on_touch_up=self.touch_up_move)
# bt.bind(on_touch_up=self.touch_move)
grid.add_widget(bt)
self.squares.append(bt)
b = BoxLayout(size_hint=(0.15,0.15))
## Spacers
# b.add_widget(Button(spacing=1))
# b.add_widget(Button(spacing=1))
# b.add_widget(Button(spacing=1))
# Move control buttons
# back_bt = Button(markup=True)
# # back_bt.background_normal="img/empty-l.png"
# back_bt.text="[color=ff3333]Back[/color]"
# back_bt.bind(on_press=self.back)
# b.add_widget(back_bt)
#
save_bt = Button(markup=True)
#fwd_bt.background_normal="img/empty-d.png"
save_bt.text="[color=3333ff]Save[/color]"
# save_bt.text="Save"
save_bt.bind(on_press=self.save)
b.add_widget(save_bt)
# b.add_widget(Button(spacing=10))
# b.add_widget(Button(spacing=10))
# b.add_widget(Button(spacing=10))
# grid.add_widget(b)
# board_box.add_widget(grid)
# board_box.add_widget(b)
# fen_input = TextInput(text="FEN", focus=True, multiline=False)
# def on_fen_input(instance):
# self.chessboard.setFEN(instance.text)
# self.refresh_board()
## print 'The widget', instance.text
#
# fen_input.bind(on_text_validate=on_fen_input)
## self._keyboard.bind(on_key_down=self._on_keyboard_down)
#
#
# b.add_widget(fen_input)
settings_bt = Button(markup=True, text='Setup')
settings_bt.bind(on_press=self.go_to_settings)
b.add_widget(settings_bt)
# self.root.current='settings'
parent.add_widget(grid)
info_grid = GridLayout(cols = 1, rows = 4, spacing = 1, size_hint=(0.3, 1), orientation='vertical')
info_grid.add_widget(b)
self.game_score = ScrollableLabel('New Game', ref_callback=self.go_to_move)
info_grid.add_widget(self.game_score)
self.engine_score = ScrollableLabel('[ref=engine_toggle]Analysis[/ref]', ref_callback=self.add_eng_moves)
#.........这里部分代码省略.........
示例9: updatePrompt
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
def updatePrompt(self, hint, input_data, correct_answer, type, promptType, tl, **kwargs):
global box1
global box3
global box3data
global promptE
global ib
global timerbar
global timerholder
global timerO
ib.clear_widgets(children=None)
# if input_data is of mc format
# newSource = args[0]
# potentialAnswers = args[1]
# correctAnswer = args[2]
box1.remove_widget(promptE)
timerholder.remove_widget(timerbar)
box3 = []
box3data = []
timerbar = None
for pa in input_data:
box3.append(Button(text=str(pa),
size_hint_x=0.5,
size_hint_y=0.5,
font_size=20))
box3data.append(pa)
for i in range(0, len(input_data)):
if box3data[i]==correct_answer:
box3[i].bind(on_release=InGame.takeCorrect)
else:
box3[i].bind(on_release=InGame.takeWrong)
ib.add_widget(box3[i])
# if the hint provided is an image
if type == "mc":
if promptType == "texture":
promptE = Image(source=hint, size_hint_x=0.5)
else:
promptE = Button(text="(sound)", size_hint_x=0.3, font_size=64, color=[1,1,1, 1])
promptE.bind(on_release=InGame.playCurrentPrompt)
InGame.playCurrentPrompt()
else:
promptE = Button(text=hint,
size_hint_x=0.5,
size_hint_y=0.5,
font_size=64,
color=[1,1,1, 1],
pos_hint={'center_y': 0.5},
disabled=True,
opacity=1.0)
box1.add_widget(promptE)
timerbar = ProgressBar(max=100,
value=100,
size_hint_y=1.0,
size_hint_x=1.0
)
timerholder.add_widget(timerbar)
timerO = Animation(value=0, duration=tl)
timerO.start(timerbar)
timerO.bind(on_complete=InGame.takeTime)
示例10: Bubble
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class Bubble(GridLayout):
'''Bubble class, see module documentation for more information.
'''
background_color = ListProperty([1, 1, 1, 1])
'''Background color, in the format (r, g, b, a).
:data:`background_color` is a :class:`~kivy.properties.ListProperty`,
default to [1, 1, 1, 1].
'''
border = ListProperty([16, 16, 16, 16])
'''Border used for :class:`~kivy.graphics.vertex_instructions.BorderImage`
graphics instruction, used itself for :data:`background_image`.
Can be used when using custom background.
It must be a list of 4 value: (top, right, bottom, left). Read the
BorderImage instruction for more information about how to play with it.
:data:`border` is a :class:`~kivy.properties.ListProperty`, default to (16,
16, 16, 16)
'''
background_image = StringProperty('data/images/bubble.png')
'''Background image of the bubble
:data:`background_image` is a :class:`~kivy.properties.StringProperty`,
default to 'data/images/bubble.png'.
'''
arrow_image = StringProperty('data/images/bubble_arrow.png')
''' Image of the arrow pointing to the bubble
:data:`arrow_image` is a :class:`~kivy.properties.StringProperty`,
default to 'data/images/bubble_arrow.png'.
'''
arrow_pos = OptionProperty('bottom_mid',
options=('left_top', 'left_mid', 'left_bottom', 'top_left',
'top_mid', 'top_right', 'right_top', 'right_mid',
'right_bottom', 'bottom_left', 'bottom_mid', 'bottom_right'))
'''Specifies the position of the arrow relative to the bubble.
Can be one of: left_top, left_mid, left_bottom top_left, top_mid, top_right
right_top, right_mid, right_bottom bottom_left, bottom_mid, bottom_right.
:data:`arrow_pos` is a :class:`~kivy.properties.OptionProperty`,
default to 'bottom_mid'.
'''
background_texture = ObjectProperty(None)
'''Specifies the background texture of the bubble
:data:`background_texture` is a :class:`~kivy.properties.ObjectProperty`,
default to 'None'.
'''
content = ObjectProperty(None)
'''This is the object where the main content of the bubble is held
:data:`content` is a :class:`~kivy.properties.ObjectProperty`,
default to 'None'.
'''
orientation = OptionProperty('horizontal',
options=('horizontal', 'vertical'))
'''This specifies the manner in which the children inside bubble
are arranged. can be one of 'vertical', 'horizontal'
:data:`orientation` is a :class:`~kivy.properties.OptionProperty`,
default to 'horizontal'.
'''
def __init__(self, **kwargs):
self._arrow_layout = GridLayout(rows=1)
self._bk_img = Image(
source=self.background_image, allow_stretch=True,
keep_ratio=False, color=self.background_color)
self.background_texture = self._bk_img.texture
self._arrow_img = Image(source=self.arrow_image,
color=self.background_color)
self.content = content = BubbleContent()
super(Bubble, self).__init__(**kwargs)
self.add_widget(content)
self._bk_img.bind(on_texture=self._on_texture)
self.on_arrow_pos()
def _on_texture(self, *l):
self.background_texture = self._bk_img.texture
def add_widget(self, *l):
content = self.content
if content is None:
return
if l[0] == content or l[0] == self._arrow_img\
or l[0] == self._arrow_layout:
super(Bubble, self).add_widget(*l)
else:
content.add_widget(l[0])
def remove_widget(self, *l):
#.........这里部分代码省略.........
示例11: PickerScreen
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class PickerScreen(Screen):
""" A nice looking touch-enabled file browser
"""
large_preview_size = ListProperty()
small_preview_size = ListProperty()
grid_rows = NumericProperty()
images = ListProperty()
def __init__(self, *args, **kwargs):
super(PickerScreen, self).__init__(*args, **kwargs)
# these declarations are mainly to keep pycharm from annoying me with
# notifications that these attributes are not declared in __init__
self.arduino_handler = None
self.preview_handler = None
self.preview_widget = None
self.preview_label = None
self.preview_exit = None
self.preview_button = None
self.focus_widget = None
self.background = None
self.scrollview = None
self.layout = None
self.grid = None
self.locked = None
self.loaded = None
self.controls = None
self.state = 'normal'
self.tilt = 90
def on_pre_enter(self):
# set up the 'normal' state
screen_width = Config.getint('graphics', 'width')
# these are pulled from the .kv format file
self.slider = search(self, 'slider')
self.layout = search(self, 'layout')
self.background = search(self, 'background')
self.scrollview = search(self, 'scrollview')
self.grid = search(self, 'grid')
self.background.source = image_path('galaxy.jpg')
# the grid will expand horizontally as items are added
self.grid.bind(minimum_width=self.grid.setter('width'))
# TODO: eventually make this related to the screen width, maybe
self.grid.spacing = (64, 64)
# slider / scrollview binding
def f(widget, value):
self.scrollview.effect_x.value = value
self.scrollview.update_from_scroll()
self.slider.bind(value_normalized=f)
# tweak the loading so it is quick
Loader.loading_image = CoreImage(image_path('loading.gif'))
Loader.num_workers = pkConfig.getint('kiosk', 'loaders')
Loader.max_upload_per_frame = pkConfig.getint('kiosk',
'max-upload-per-frame')
self.scrollview_hidden = False
self._scrollview_pos_hint = self.scrollview.pos_hint
self._scrollview_pos = self.scrollview.pos
# the center of the preview image
center_x = screen_width - (self.large_preview_size[0] / 2) - 16
# stuff for the arduino/tilt
self.arduino_handler = ArduinoHandler()
# queueing them and updaing the widget's texture
self.preview_handler = PreviewHandler()
self.preview_handler.start()
# F O C U S W I D G E T
# the focus widget is the large preview image
self.focus_widget = Factory.FocusWidget(
source=image_path('loading.gif'))
self.focus_widget.allow_stretch = True
self.focus_widget.x = center_x - OFFSET
self.focus_widget.y = -1000
self.focus_widget.size_hint = None, None
self.focus_widget.size = self.small_preview_size
#self.focus_widget.bind(on_touch_down=self.on_image_touch)
self.layout.add_widget(self.focus_widget)
# E X I T B U T T O N
# this button is used to exit the large camera preview window
def exit_preview(widget, touch):
if widget.collide_point(touch.x, touch.y):
self.change_state('normal')
self.preview_exit = Factory.ExitButton(
source=image_path('chevron-right.gif'))
#self.preview_exit.bind(on_touch_down=exit_preview)
self.preview_exit.size_hint = None, None
self.preview_exit.width = 64
self.preview_exit.height = 175
self.preview_exit.x = 1280
#.........这里部分代码省略.........
示例12: PickerScreen
# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import bind [as 别名]
class PickerScreen(Screen):
def on_pre_enter(self):
self.layout = search(self, 'layout')
self.background = search(self, 'background')
self.scrollview = search(self, 'scrollview')
self.focus = None
# set the background to the correct position
self.on_picker_scroll(None, None)
self.scrollview.bind(scroll_x=self.on_picker_scroll)
self.scrollview.bind(pos=self.on_picker_move)
images = get_images()
width = math.ceil((len(images) / 2.0 * 312) / 1280.0)
self.max_width = width * 1280
# set the width to be much great than the screen
# somewhat proportionally to the number of images
rellayout = search(self, 'rellayout')
rellayout.size_hint = (width,1)
grid = search(self, 'grid')
Loader.loading_image = CoreImage('images/loading.gif')
Loader.num_workers = 4
Loader.max_upload_per_frame = 4
for image in get_images():
widget = Factory.AsyncImage(source=image, allow_stretch=True)
widget.bind(on_touch_down=self.on_image_touch)
grid.add_widget(widget)
self.scrollview_hidden = False
self._scrollview_pos_hint = self.scrollview.pos_hint
self._scrollview_pos = self.scrollview.pos
self._sv_hide_ani = None
self._sv_show_ani = None
self._focus_hide_ani = None
self._focus_show_ani = None
self._focus_widget = Image(source='images/loading.gif')
self._focus_widget.allow_stretch = True
self._focus_widget.pos_hint = {'center_x': .5}
self._focus_widget.y = 1024
self._focus_widget.size_hint = None, None
self._focus_widget.size = (600, 600)
self._focus_widget.bind(on_touch_down=self.on_image_touch)
self.layout.add_widget(self._focus_widget)
def on_image_touch(self, widget, mouse_point):
if widget.collide_point(mouse_point.x, mouse_point.y):
# show the focus widget
if self.scrollview_hidden:
self.scrollview_hidden = False
# cancel scrollview hiding animation
try:
self._sv_hide_ani.cancel(self.scrollview)
except AttributeError:
pass
# show the scrollview
x, y = self._scrollview_pos
self._sv_show_ani = Animation(x=x, y=y, t='in_out_quad', duration=.5)
self._sv_show_ani.start(self.scrollview)
# cancel the focus widget show animation
try:
self._focus_show_ani.cancel(self._focus_widget)
except AttributeError:
pass
# hide the focus widget
self._focus_hide_ani = Animation(y=1024,
size=(600,600),
t='in_out_quad',
duration=.5)
self._focus_hide_ani.start(self._focus_widget)
# hide the focus widget
elif self._focus_widget is not widget:
self.scrollview_hidden = True
# cancel the scrollview show animation
try:
self._sv_show_ani.cancel(self.scrollview)
except AttributeError:
pass
# hide the scrollview
self.sv_hide_ani = Animation(x=0, y=-450, t='in_out_quad', duration=.5)
self.sv_hide_ani.start(self.scrollview)
#.........这里部分代码省略.........