FloatLayout:
BoxLayout:
orientation: 'vertical'
Button:
size_hint_y: None
height: 48
text: 'paste'
on_press: app.root.ids.TextInput_id.paste()
TextInput:
height: self.minimum_height
width: self.height
halign: 'center'
id:TextInput_id
text: 'My unicode string'
on_selection_text: if self.focus: app.show_bubble()
<cut_copy_paste>
size_hint: (None, None)
size: (140, 60)
pos: app.root.ids.TextInput_id.cursor_pos
arrow_pos: 'bottom_left'
id: cut_copy_paste_id
BubbleButton:
text: 'Delete'
color: 1,0,0,1
on_press : app.root.ids.TextInput_id.delete_selection(from_undo=False)
on_press : app.remove_bubble()
BubbleButton:
text: 'Cut'
color: 0,1,0,1
on_press : app.root.ids.TextInput_id.cut()
BubbleButton:
text: 'Copy'
color: 0,0,1,1
on_press : app.root.ids.TextInput_id.copy(data=app.root.ids.TextInput_id.selection_text)
class cut_copy_paste(Bubble):
pass
def show_bubble(self):
self.root.add_widget(cut_copy_paste())
def remove_bubble(self):
self.root.remove_widget(cut_copy_paste())
Bubble opens on selection, closes when selection is ‘’
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.uix.bubble import Bubble
kv = '''
<CutCopyPaste>:
size_hint: (None, None)
size: (160, 120)
pos_hint: {'center_x': .5, 'y': .6}
BubbleButton:
text: 'Cut'
on_release:
print('Cut Selected')
app.root.ids.ti.focus = True
BubbleButton:
text: 'Copy'
on_release:
print('Copy Selected')
app.root.ids.ti.focus = True
BubbleButton:
text: 'Paste'
on_release:
print('Copy Selected')
app.root.ids.ti.focus = True
BubbleShowcase:
TextInput:
id: ti
on_selection_text:
if self.selection_text == '': app.root.dismiss_bubble()
if self.selection_text != '': app.root.show_bubble()
'''
class CutCopyPaste(Bubble):
pass
class BubbleShowcase(FloatLayout):
def __init__(self, **kwargs):
self.bubb = None
super().__init__(**kwargs)
def show_bubble(self, *l):
if not self.bubb:
self.bubb = CutCopyPaste()
self.add_widget(self.bubb)
self.bubb.arrow_pos = 'top_mid'
def dismiss_bubble(self):
if self.bubb:
self.remove_widget(self.bubb)
self.bubb = None
class TestBubbleApp(App):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
TestBubbleApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c0ff9eb7-85fa-4162-82b1-c3acb0f54333%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
def __init__(self, **kwargs):
self.bubb = None
super().__init__(**kwargs)
The code above creates an instance variable self.bubb. An instance variable will be created for every instance of the class. The call to super().__init__ is required by kivy. We are overloading the __init__() method of the parent class, in this case FloatLayout, so we need to call the parents __init__(), and pass along the arguments.
In:
def show_bubble(self, *l):
if not self.bubb: # only create the class if it doesn’t exist
self.bubb = CutCopyPaste()
self.add_widget(self.bubb)
self.bubb.arrow_pos = 'top_mid'
We instance the class, and save it into self.bubb. self.bubb now holds the CutCopyPaste instance we created.
def dismiss_bubble(self):
if self.bubb: # only remove the widget if it exsits.
self.remove_widget(self.bubb) # remove the widget
self.bubb = None # set self.bubb to None so the test in show_bubble will work.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/935c803b-8062-4cb3-bd3f-e388fd1bfc73%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/935c803b-8062-4cb3-bd3f-e388fd1bfc73%40googlegroups.com.
That’s a typo.
The code still works because it is the same as *args, meaning the method takes a variable number of positional arguments.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/519f0c05-f09e-4435-8145-5e4c32f4479d%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/519f0c05-f09e-4435-8145-5e4c32f4479d%40googlegroups.com.
The bubble is derived from GridLayout, you can try using some of the GridLayout Attributes. From the docs:
Post a small example if want some help sizing the text. Are you using sp() from metrics?
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4a4020aa-94cb-4c27-a982-9b83e8f6c6d1%40googlegroups.com.
I mean why I can't use this method to
font_size: self.width*.2
<cut_copy_paste>:
You can do that. That will scale the font size, based on the width.
This code will scale the font_size based on the width of the bubble.
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.uix.bubble import Bubble
from kivy.properties import NumericProperty
kv = '''
<CutCopyPaste>:
size_hint: (None, None)
size: (root.width, 120)
pos_hint: {'center_x': .5, 'y': .6}
BubbleButton:
id: cut
text: 'Cut'
font_size: root.font_size
on_release:
print('Cut Selected')
app.root.ids.ti.focus = True
BubbleButton:
id: copy
text: 'Copy'
font_size: root.font_size
on_release:
print('Copy Selected')
app.root.ids.ti.focus = True
BubbleButton:
id:paste
text: 'Paste'
font_size: root.font_size
on_release:
print('Copy Selected')
app.root.ids.ti.focus = True
BubbleShowcase:
TextInput:
id: ti
on_selection_text:
if self.selection_text == '': app.root.dismiss_bubble()
if self.selection_text != '': app.root.show_bubble()
'''
class CutCopyPaste(Bubble):
font_size = NumericProperty(12)
width = NumericProperty(160)
def on_kv_post(self, base_widget):
while self.ids.paste.texture_size[0] < self.width/3 - 5: # Scale up
self.font_size += 1
self.ids.paste.texture_update()
while self.ids.paste.texture_size[0] > self.width / 3 - 5: # Scale down
self.font_size -= 1
self.ids.paste.texture_update()
class BubbleShowcase(FloatLayout):
def __init__(self, **kwargs):
self.bubb = None
super().__init__(**kwargs)
def show_bubble(self, *l):
if not self.bubb:
self.bubb = CutCopyPaste()
self.add_widget(self.bubb)
self.bubb.arrow_pos = 'top_mid'
def dismiss_bubble(self):
if self.bubb:
self.remove_widget(self.bubb)
self.bubb = None
class TestBubbleApp(App):
def build(self):
return Builder.load_string(kv)
if __name__ == '__main__':
TestBubbleApp().run()
From: husam alkdary
Sent: Wednesday, May 20, 2020 9:46 AM
To: Kivy users support
Subject: Re: -- SPAM --[kivy-users] closing the bubble
I mean why I can't use this method to
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b8c577b3-753a-470d-9d08-3023261294d7%40googlegroups.com.