本文整理汇总了Python中kivy.uix.dropdown.DropDown.dismiss方法的典型用法代码示例。如果您正苦于以下问题:Python DropDown.dismiss方法的具体用法?Python DropDown.dismiss怎么用?Python DropDown.dismiss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.dropdown.DropDown
的用法示例。
在下文中一共展示了DropDown.dismiss方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NoteItem
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
class NoteItem(BoxLayout):
def __init__(self, **kwargs):
super(NoteItem, self).__init__(**kwargs)
self.dropdown = DropDown()
def addNoteItem(self, w):
"""
inventoryitem = Inventarios()
inventoryitem.Clave = w.parent.txt_clave.text
inventoryitem.Producto = w.parent.txt_producto.text
inventoryitem.Existencias = w.parent.txt_existencias.text
inventoryitem.Minimo = w.parent.txt_minimo.text
inventoryitem.Maximo = w.parent.txt_maximo.text
inventoryitem.Precio = w.parent.txt_precio.text
inventoryitem.save()
"""
newitem = NoteItem()
w.text = "X"
table = app.root.ventas.lst_note
table.add_widget(newitem, index=len(table.layout.children))
app.root.ventas.txt_total.text = str(float(app.root.ventas.txt_total.text) + float(w.parent.txt_total.text))
def on_completeproduct(self, w):
print w.text
if len(w.text) > 2:
self.dropdown.clear_widgets()
# for item in app.root.inventarios:
for item in app.root.inventarios:
if w.text.upper() in item.Producto.upper():
but = WhiteButton(text=item.Producto, size_hint_y=None, height=40)
but.bind(on_press=self.fillProduct)
but.Item = item
self.dropdown.add_widget(but)
self.dropdown.open(w)
def fillProduct(self, w):
self.txt_producto.text = w.text
self.txt_precio.text = w.Item.Precio
if self.txt_cant.text != "":
self.txt_total.text = str(float(self.txt_cant.text) * float(self.txt_precio.text))
self.dropdown.dismiss()
示例2: CompleteTextInput
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
class CompleteTextInput(TextInput):
options = ListProperty([])
dd = ObjectProperty(None)
def __init__(self, **kwargs):
super(CompleteTextInput, self).__init__(**kwargs)
self.dd = DropDown(auto_dismiss=False)
self.dd.bind(on_select=self.setter('text'))
self.bind(text=self.update_complete,
focus=self.update_complete)
def update_complete(self, *args):
if self.focus:
self.dd.clear_widgets()
for x in app.settings.get('settings', 'servers').split(','):
url = x.split(';')[1].strip()
if self.text in url:
b = Factory.DDButton(text=url)
b.bind(on_release=lambda btn: self.dd.select(btn.text))
self.dd.add_widget(b)
self.dd.open(self)
else:
self.dd.dismiss()
示例3: EventHandlerTextInput
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
#.........这里部分代码省略.........
eventwidget = ObjectProperty(None)
'''Current selected widget
:data:`eventwidget` is a :class:`~kivy.properties.ObjectProperty`
'''
eventname = StringProperty(None)
'''Name of current event
:data:`eventname` is a :class:`~kivy.properties.ObjectProperty`
'''
kv_code_input = ObjectProperty()
'''Reference to KVLangArea
:data:`kv_code_input` is a :class:`~kivy.properties.ObjectProperty`
'''
text_inserted = BooleanProperty(None)
'''Specifies whether text has been inserted or not
:data:`text_inserted` is a :class:`~kivy.properties.ObjectProperty`
'''
project_loader = ObjectProperty(None)
'''Reference to ProjectLoader
:data:`project_loader` is a :class:`~kivy.properties.ObjectProperty`
'''
info_message = StringProperty(None)
'''Message to be displayed by InfoBubble
:data:`info_message` is a :class:`~kivy.properties.StringProperty`
'''
dropdown = ObjectProperty(None)
'''DropDown which will be displayed to show possible
functions for that event
:data:`dropdown` is a :class:`~kivy.properties.ObjectProperty`
'''
def on_touch_down(self, touch):
'''Default handler for 'on_touch_down' event
'''
if self.collide_point(*touch.pos):
self.info_bubble = InfoBubble(message=self.info_message)
bubble_pos = list(self.to_window(*self.pos))
bubble_pos[1] += self.height
self.info_bubble.show(bubble_pos, 1.5)
return super(EventHandlerTextInput, self).on_touch_down(touch)
def show_drop_down_for_widget(self, widget):
'''Show all functions for a widget in a Dropdown.
'''
self.dropdown = DropDown()
list_funcs = dir(widget)
for func in list_funcs:
if '__' not in func and hasattr(getattr(widget, func), '__call__'):
btn = Button(text=func, size_hint=(None, None),
size=(100, 30), shorten=True)
self.dropdown.add_widget(btn)
btn.bind(on_release=lambda btn: self.dropdown.select(btn.text))
btn.text_size = [btn.size[0] - 4, btn.size[1]]
btn.valign = 'middle'
self.dropdown.open(self)
self.dropdown.pos = (self.x, self.y)
self.dropdown.bind(on_select=self._dropdown_select)
def _dropdown_select(self, instance, value):
'''Event handler for 'on_select' event of self.dropdown
'''
self.text += value
def on_text(self, instance, value):
'''Default event handler for 'on_text'
'''
if not self.kv_code_input:
return
self.kv_code_input.set_event_handler(self.eventwidget,
self.eventname,
self.text)
if self.text and self.text[-1] == '.':
if self.text == 'self.':
self.show_drop_down_for_widget(self.eventwidget)
elif self.text == 'root.':
self.show_drop_down_for_widget(
self.project_loader.root_rule.widget)
else:
_id = self.text.replace('.', '')
root = self.project_loader.root_rule.widget
widget = None
if _id in root.ids:
widget = root.ids[_id]
if widget:
self.show_drop_down_for_widget(widget)
elif self.dropdown:
self.dropdown.dismiss()
示例4: cWidgetDropDown
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
#.........这里部分代码省略.........
self.oDimmer = None
self.iFrameWidth = 0
self.uActionNames = u''
self.tFrameColor = []
def InitWidgetFromXml(self,oXMLNode,oParentScreenPage, uAnchor):
bRet=super(cWidgetDropDown, self).InitWidgetFromXml(oXMLNode,oParentScreenPage, uAnchor)
if bRet:
self.tFrameColor = GetColorFromHex(GetXMLTextAttribut(oXMLNode,u'framecolor',False,u'$var(dimmed)'))
self.iFrameWidth = GetXMLIntAttribut(oXMLNode,u'framewidth', False,self.oDef.iDefMaxX/self.fRationX)*0.02
if u':::' in self.uCaption:
uCaptions = self.uCaption.split(u':::')
self.uCaption = uCaptions[0]
#self.uOrgCaption = self.uCaption
self.uCaptions = uCaptions[1:]
self.uActionNames = ReplaceVars(self.uActionName).split(u':::')
self.uActionName = u''
else:
self.uCaptions = GetXMLTextAttribut(oXMLNode,u'captions', True,u'unknown').split(u',')
self.uActionNames = GetXMLTextAttribut(oXMLNode,u'actions', True,u'').split(u',')
if len(self.uActionNames)!=len(self.uCaptions):
LogError(u'cWidgetDropDown: Captions do not match Actions:'+self.uActionName)
bRet=False
else:
for num in range(len(self.uCaptions)):
oBtn = cWidgetButton()
# we cant use the touchbutton object, as Buttonbehaviour not work on buttons on scolllayout
#oBtn.ClassName = Button
oBtn.bIsDropButton = True
oBtn.InitWidgetFromXml(oXMLNode,oParentScreenPage, uAnchor)
oBtn.SetCaption(self.uCaptions[num])
oBtn.uActionName = self.uActionNames[num]
oBtn.iAnchorPosX = 0
oBtn.iAnchorPosY = 0
oBtn.iPosX = 0
oBtn.iPosY = 0
oBtn.uActionNameDoubleTap = u''
oBtn.uActionNameDownOnly = u''
oBtn.uActionNameUpOnly = u''
oBtn.uActionNameLongTap = u''
self.oDropDownButtons.append(oBtn)
return bRet
def Create(self,oParent,iWidgetIndex):
try:
if super(cWidgetDropDown, self).Create(oParent,iWidgetIndex):
self.oObjectDropDown=DropDown()
#self.dismiss_on_select=True
for oWidget in self.oDropDownButtons:
oWidget.Create(oParent,-1)
oWidget.uName = "*DROPDOWNBUTTON*"+oWidget.uName
oBtn = oWidget.oObject
oWidget.oParent.remove_widget(oBtn)
oBtn.size_hint_y = None
oBtn.unbind(on_q_release = oWidget.On_Button_Up)
oBtn.bind(on_q_release = self.DropDownSelect)
self.oObjectDropDown.add_widget(oBtn)
self.oObject.bind(on_q_release = self.OpenDropDown)
self.oObjectDropDown.bind(on_dismiss = self.CloseDropDown)
return True
return False
except Exception as e:
LogError("Can''t create Dropdown",e)
return False
def OpenDropDown(self,instance):
''' opens the dropdown '''
Object=self.oObjectDropDown
Object.open(self.oObject)
self.oDimmer=cTouchRectangle(pos=(Object.pos[0]-self.iFrameWidth,Object.pos[1]-self.iFrameWidth),width=Object.width+self.iFrameWidth*2,height=Object.height+self.iFrameWidth*2,background_color=self.tFrameColor)
self.oParent.add_widget(self.oDimmer)
def CloseDropDown(self,instance):
''' closes the dropdown '''
self.oParent.remove_widget(self.oDimmer)
def DropDownSelect(self,instance):
''' selects on item of dropdown '''
#self.SetCaption(instance.text)
self.oObjectDropDown.dismiss()
instance.oOrcaWidget.On_Button_Up(instance)
return
def UpdateWidget(self):
uCaption=ReplaceVars(self.uOrgCaption)
if u':::' in uCaption:
aCaptions = self.uCaption.split(u':::')
self.SetCaption2(aCaptions[0])
aCaptions = aCaptions[1:]
for i in range(len(self.oDropDownButtons)):
if i<len(aCaptions):
self.oDropDownButtons[i].UpdateWidget(aCaptions[i])
return True
return self.SetCaption2(self.uOrgCaption)
示例5: __init__
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
class UserInterface:
def __init__(self, client):
# TODO handle connection errors properly
self.client = client
self.layout = GridLayout(cols = 2, pos_hint={'x': 0, 'y': 0}, size_hint=(1, 0.1))
self.client.layout.add_widget(self.layout, index = 1000)
self.client.bind('connected', self.connected)
self.client.bind('loaded', self.loaded)
self.client.bind('registered', self.registered)
if self.client.config.get('connection', 'autoconnect') == 'yes':
self.auto = True
self.client.connect(self.client.config.get('connection', 'server'))
else:
self.auto = False
self.server_input = TextInput(text = self.client.config.get('connection', 'server'))
self.server_button = Button(text = 'Connect', size_hint = (0.25, 1))
self.server_button.bind(on_press = self.do_connect)
self.layout.add_widget(self.server_input)
self.layout.add_widget(self.server_button)
def do_connect(self, button):
self.client.connect(self.server_input.text)
self.layout.remove_widget(self.server_input)
self.layout.remove_widget(self.server_button)
del self.server_input, self.server_button
self.connecting_label = Label(text = 'connecting...')
self.layout.add_widget(self.connecting_label)
def connected(self, event):
if not self.auto:
self.client.config.set('connection', 'server', self.client.server)
self.connecting_label.text = 'loading...'
def loaded(self, event):
if self.auto:
self.client.register(self.client.config.get('connection', '_id'))
return
self.layout.remove_widget(self.connecting_label)
del self.connecting_label
self.dropdown = DropDown()
for stage in sorted(self.client.meteor.find('stages'), key=lambda x: x['title']):
self.dropdown.add_widget(Label(text = stage['title'], size_hint_y = None, height = 40))
seen = []
for minion in sorted(self.client.meteor.find('minions',
selector = {'stage': stage['_id'], 'type': 'media'}), key=lambda x: x['title']):
# workaround for python-meteor bug
if not minion['stage'] == stage['_id']: continue
if minion['_id'] in seen: continue
else: seen.append(minion['_id'])
button = Button(text = minion['title'], size_hint_y = None, height = 30)
button.minion_id = minion['_id']
button.bind(on_press = self.do_register)
self.dropdown.add_widget(button)
self.dropdown_button = Button(text = 'Select Minion')
self.dropdown_button.bind(on_release = self.dropdown.open)
self.layout.add_widget(self.dropdown_button)
self.auto_checkbox = CheckBox()
self.auto_label = Label(text = 'Connect automatically on start')
self.layout.add_widget(self.auto_checkbox)
self.layout.add_widget(self.auto_label)
def do_register(self, button):
self.client.config.set('connection', '_id', button.minion_id)
self.client.config.set('connection', 'autoconnect', 'yes' if self.auto_checkbox.active else 'no')
self.client.config.write()
self.client.register(button.minion_id)
self.dropdown.dismiss()
self.layout.remove_widget(self.dropdown_button)
self.layout.remove_widget(self.auto_checkbox)
self.layout.remove_widget(self.auto_label)
del self.dropdown_button, self.dropdown, self.auto_checkbox, self.auto_label
self.registering_label = Label(text = 'registering...')
self.layout.add_widget(self.registering_label)
def registered(self, event):
if not self.auto:
self.layout.remove_widget(self.registering_label)
del self.registering_label
示例6: Pos
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
class Pos(BoxLayout):
def __init__(self, **kwargs):
super(Pos, self).__init__(**kwargs)
self.cliente = None
def hacerNota(self):
if self.txt_client.text == "":
MessageBoxTime(
title="Ops", size_hint=(None, None), size=(350, 120), msg="Por favor especifica el cliente", duration=2
).open()
return
elif self.cliente == None:
MessageBoxTime(
title="Espere", size_hint=(None, None), size=(350, 120), msg="Guardando cliente", duration=2
).open()
print "Realizando nota"
nota = Notas()
nota.PUser = app.root.user
nota.Total = self.txt_total.text
nota.Cliente = self.cliente
products = []
for i in self.lst_note.layout.children:
print i.txt_producto.text
products.append(
{
"Cantidad": i.txt_cant.text,
"Product": i.txt_producto.text,
"Precio": i.txt_precio.text,
"Total": i.txt_total.text,
}
)
nota.Productos = products
nota.save()
# limpiar controles de nota
self.lst_note.clear()
self.lst_note.add_widget(NoteItem())
self.txt_client.text = ""
self.txt_total.text = "0"
self.img_button.source = "plus.png"
self.cliente = None
def on_completeclient(self, w):
if not hasattr(self, "dropdown"):
self.dropdown = DropDown()
if len(w.text) > 2:
self.dropdown.clear_widgets()
found = False
for item in Clientes.Query.filter(words__all=w.text.upper().split()):
but = WhiteButton(text=item.Name, size_hint_y=None, height=40)
but.bind(on_press=self.fillClient)
but.Cliente = item
self.dropdown.add_widget(but)
found = True
if found:
self.dropdown.open(w)
def fillClient(self, w):
self.txt_client.text = w.text
self.img_button.source = "ok.png"
self.cliente = w.Cliente
self.dropdown.dismiss()
def addClient(self):
print "Adding the client: " + self.txt_client.text
self.cliente = Clientes()
self.cliente.Name = self.txt_client.text
self.cliente.PUser = app.root.user
self.cliente.save()
self.img_button.source = "ok.png"
def fillNotas(self):
print "Llenado lista de notas"
for i in app.root.notas:
print i
notareg = NoteReg()
notareg.txt_fecha.text = str(i.createdAt)
#.........这里部分代码省略.........
示例7: LoungeScreen
# 需要导入模块: from kivy.uix.dropdown import DropDown [as 别名]
# 或者: from kivy.uix.dropdown.DropDown import dismiss [as 别名]
class LoungeScreen(BaseScreen):
current_player_slot = NumericProperty(0)
players = ListProperty([{}] * 4)
dropdown_player = ObjectProperty()
drag_start_id = NumericProperty(-1)
drag_stop_id = NumericProperty(-1)
dragging = BooleanProperty()
def __init__(self, **kwargs):
super(LoungeScreen, self).__init__(**kwargs)
self.set_title('Aufstellung')
self.ids.topbar.hasNext = True
self.is_dropdown_open = False
self.slot_touch = None
self.__reset()
def on_enter(self):
Clock.schedule_once(lambda dt: self.__setup_player_dropdown(), 0.2)
self.current_player_slot = 0
def on_leave(self):
self.close_dropdown()
def on_next(self):
self.manager.current = 'match'
def __reset(self):
self.players = [{}] * 4
self.current_player_slot = 0
def __setup_player_dropdown(self):
# only create if not existing
if not self.dropdown_player:
self.dropdown_player = DropDown(auto_dismiss=False)
self.dropdown_player.bind(on_select=self.on_player_select)
self.dropdown_player.bind(on_dismiss=self.on_dropdown_dismiss)
players = sorted(PlayerData.get_players(), key=lambda player: player['name'])
for player in players:
btn = PlayerButton(data=player)
btn.bind(on_release=lambda btn: self.dropdown_player.select(btn.data))
self.dropdown_player.add_widget(btn)
def on_dropdown_dismiss(self, instance):
self.is_dropdown_open = False
def open_dropdown(self, slot_id):
if not self.is_dropdown_open:
obj = self.ids['p' + str(slot_id)]
self.dropdown_player.open(obj)
self.is_dropdown_open = True
def close_dropdown(self):
if self.is_dropdown_open:
self.dropdown_player.dismiss()
def on_player_select(self, instance, data):
# player was selected from dropdown list
self.dropdown_player.dismiss()
self.set_player(data)
def on_players(self, instance, value):
GameData.set_players(value)
count_players = 0
for player in self.players:
count_players = count_players + (1 if player else 0)
self.ids.topbar.isNextEnabled = (count_players == 4)
def click_player_slot(self, player_slot):
pass
def __handle_rfid(self, rfid):
# RFID --> player ID
player_id = PlayerData.get_player_by_rfid(rfid)
# player ID --> player dict
player = PlayerData.get_player_by_id(player_id)
Logger.info('ScoreTracker: RFID: {0} - ID: {1} - Player: {2}'.format(rfid, player_id, player))
# player does not exist
if player == None:
self.denied()
# player does exist
else:
if self.dropdown_player:
self.dropdown_player.dismiss()
self.set_player(player)
def highlight_player(self, slot_id):
obj = self.ids['p' + str(slot_id)].ids.playerName
HighlightOverlay(orig_obj=obj, parent=self, active=True, bold=True).animate(font_size=80, color=(1, 1, 1, 0))
def switch_players(self, slot_id_1, slot_id_2):
self.players[slot_id_1], self.players[slot_id_2] = self.players[slot_id_2], self.players[slot_id_1]
for player_id in [slot_id_1, slot_id_2]:
self.highlight_player(player_id)
SoundManager.play(Trigger.PLAYERS_SWITCHED)
def get_slot_collision(self, event):
slot_id = None
#.........这里部分代码省略.........