closing the bubble

102 views
Skip to first unread message

husam alkdary

unread,
May 15, 2020, 3:55:51 PM5/15/20
to Kivy users support
how I can close the bubble when I click one of the bubble buttons or when I end the highlight of the text if that's possible 

the kv file 

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)



and the python file 
contain 


class cut_copy_paste(Bubble):
 
pass


and the app class that contains this two function the show woks fine and open the bubble but the remove does not close it 

def show_bubble(self):
 
self.root.add_widget(cut_copy_paste())

def remove_bubble(self):
 
self.root.remove_widget(cut_copy_paste())

 

Elliot Garbus

unread,
May 15, 2020, 5:49:22 PM5/15/20
to kivy-...@googlegroups.com

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.

 

husam alkdary

unread,
May 18, 2020, 10:01:29 AM5/18/20
to Kivy users support
what's the use of this part from the code 

class BubbleShowcase(FloatLayout):
   
def __init__(self, **kwargs):
       
self.bubb =
None
        
super().__init__(**kwargs) when I remove it the bubble open but its not close

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
May 18, 2020, 10:30:46 AM5/18/20
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.

 

husam alkdary

unread,
May 18, 2020, 4:55:33 PM5/18/20
to Kivy users support
what's the use of *l here because I remove it and every thing works fine ??

Elliot Garbus

unread,
May 18, 2020, 5:19:11 PM5/18/20
to kivy-...@googlegroups.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.

https://realpython.com/python-kwargs-and-args/

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.

 

husam alkdary

unread,
May 20, 2020, 9:20:55 AM5/20/20
to Kivy users support
it's possible to size hint with bubble widget because when I use the fixed size I it's ok on the pc but in the phone the font size becomes much bigger the widget so it's possible to even to make font size relative to the bubble widget because I tried it but is not work for me  

Elliot Garbus

unread,
May 20, 2020, 9:36:08 AM5/20/20
to kivy-...@googlegroups.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?

https://kivy.org/doc/stable/api-kivy.metrics.html

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.

 

husam alkdary

unread,
May 20, 2020, 12:46:24 PM5/20/20
to Kivy users support

I mean why I can't use this method to

font_size: self.width*.2
 to determine the font size inside the 
<cut_copy_paste>:

class ?
 

 

Elliot Garbus

unread,
May 20, 2020, 4:59:25 PM5/20/20
to kivy-...@googlegroups.com

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.

Reply all
Reply to author
Forward
0 new messages