On Sep 2, 2023, at 6:34 PM, Dan Moormann <dan...@gmail.com> wrote:
1) Is there any way to remove the red dot used in scatter after it has been used, so that it can be used multiple times?
--
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/86133abf-e2e1-41bd-9966-3c8360cd8d3an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4180ED21-BEEA-4E57-ADD4-ACE3E1FE0C5C%40cox.net.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4180ED21-BEEA-4E57-ADD4-ACE3E1FE0C5C%40cox.net.
This works on Windows and Mac to disable the red dot. The red dot is multi-touch emulation.
from kivy.config import Config
Config.set('input', 'mouse', 'mouse,disable_multitouch')
Let me know this is sufficient.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4B4wGd7DDdcbqDwAjXr_Y2pKcwpkoyZOR8dvcRpvSqVgg%40mail.gmail.com.
You would just create Labels to put text on the screen. What are you trying to accomplish?
From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> On Behalf Of Dan Moormann
Sent: Monday, September 4, 2023 4:42 PM
To: kivy-...@googlegroups.com
Subject: Re: [kivy-users] Some Questions (unrelated)
I'm already using both rectangles and line(rectangle() and turtle to do some simple graphics. Besides turtle (or creating many many label widgets) Is there a way to put text directly to the screen?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4CuWBgDwmaowamJ7_NXW774v%3DsO%3DLDDv4FxMr5mpSpDzQ%40mail.gmail.com.
For the config.set, make sure you put this at the very top of your file. You want to execute the Config.set before kivy.app is imported.
You can use a Label to put the text where you want. Set the size, put it in a FloatLayout or RelativeLayout and use pos or pos_hint to position the text.
I’ll put together a small popup example. What do you want to do with the Popup?
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/752c9f57-3711-44c3-90f7-e639a69a8171n%40googlegroups.com.
Here is a popup example that uses Factory to instance the popup in kv.
from kivy.app import App
from kivy.lang import Builder
kv = """
#:import Factory kivy.factory.Factory
<MyPopUp@Popup>:
size_hint: .7, .7
title: 'hello'
id: popup
BoxLayout:
orientation: 'vertical'
Label:
text: 'Hello, I am a PopUp!'
Button:
text: 'Dismiss'
size_hint_y: None
height: dp(48)
on_release: root.dismiss()
BoxLayout:
orientation: 'vertical'
padding: 10
Label:
text: 'Use Factory to Instance a PopUp in KV'
Button:
text: 'Push to create MyPopUp'
size_hint_y: None
height: dp(48)
on_release: Factory.MyPopUp().open()
"""
class PopApp(App):
def build(self):
return Builder.load_string(kv)
PopApp().run()
From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> On Behalf Of Dan Moormann
Sent: Monday, September 4, 2023 7:06 PM
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/752c9f57-3711-44c3-90f7-e639a69a8171n%40googlegroups.com.
Here is another small popup example – perhaps a little more useful. I added a text input. I instanced the popup in app, just to show a different way of doing it – rather than using the Factory.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
kv = """
<MessagePop>:
title: 'Update Message'
size_hint: .7, .7
BoxLayout:
orientation: 'vertical'
AnchorLayout:
TextInput:
id: input
size_hint: None, None
size: 200, 40
hint_text: 'Enter Message'
on_text_validate: app.root.text = self.text
Button:
size_hint_y: None
height: dp(48)
text: 'Update Message'
on_release:
app.root.text = input.text
root.dismiss()
input.text = ''
RootBoxLayout:
orientation: 'vertical'
Label:
id: msg
text: root.text
Button:
size_hint_y: None
height: dp(48)
text: 'Update Message'
on_release: app.pop.open()
"""
class MessagePop(Popup):
pass
class RootBoxLayout(BoxLayout):
text = StringProperty('Your message goes here')
class PopApp(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.pop = None # used to hold the popup
def build(self):
return Builder.load_string(kv)
def on_start(self):
self.pop = MessagePop() # instance the popup after the kv has been processed
PopApp().run()
From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> On Behalf Of Dan Moormann
Sent: Monday, September 4, 2023 7:06 PM
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/752c9f57-3711-44c3-90f7-e639a69a8171n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/008501d9dfa7%243b561510%24b2023f30%24%40cox.net.
On Sep 5, 2023, at 9:25 AM, Dan Moormann <dan...@gmail.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4AJt9bNBxJdx46oCh2dnEsxiC7%2B5r0P35f3_JYqkdx9oA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4c8ca422-ac80-438e-a428-2ea0c33ef9ben%40googlegroups.com.
Looking at the example I wrote.
In on_start():
The Popup, MessagePop() is instanced and assigned to the instance variable self.pop
In the kv code:
RootBoxLayout:
orientation: 'vertical'
Label:
id: msg
text: root.text
Button:
size_hint_y: None
height: dp(48)
text: 'Update Message'
on_release: app.pop.open()
app.pop is the instance variable pop that was assigned the instance of MessagePop(), the open() method opens the Popup.
If this is not sufficient to get things working, share your code.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4Ao%3DkB8yC5CiMvqH2oD-jLg6-YxBdzU27zFW1ia5G0Ybg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/032e01d9e042%24e9a02430%24bce06c90%24%40cox.net.
You have 2 app classes; you can only have one. You are only instancing TutorialApp.
In the kv file you have a root widget, RootBoxLayout. But in TutorialApp you are instancing ScatterTextWidget as the root widget.
In MessagePop there is an error. You have an on_release statement in the multiline on_release.
The color attributes in Color, need to be between 0 and 1, you have 255. You can divide the color attributes you have by 255, to get them between 0 and 1 if you currently have them represented from 0-255. Or you can use kivy.utils.rgba. https://kivy.org/doc/stable/api-kivy.utils.html#kivy.utils.rgba
There is a dict in kivy.utils called colormap, that maps the names of colors to their value. It is not documented – but it is in there. It is also used by the ColorProperty. Take a look at the source code if you are interested.
<MessagePop>
title: 'Pop goes the weasel'
size_hint: .7, .7
on_open: input.focus = True
BoxLayout:
orientation: 'vertical'
AnchorLayout:
TextInput:
id: input
size_hint: None, None
size: 200, 40
hint_text: 'Please respond'
on_text_validate: app.root.text = self.text
Button:
size_hint_y: None
height: dp(48)
text: 'Press when finished'
on_release:
app.root.text = input.text
root.dismiss()
input.text = ''
on_release: app.open()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4An19uNgeSZny6vpKOz-7QUgN2suWoY90%3DaLgbvktRK7A%40mail.gmail.com.
If you want to open the popup in xtest, you could use Factory…
#:import Factory kivy.factory.Factory
Button: #xtest
id: test
name: 'test'
# on_press: root.xtest()
on_press: Factory.MessagePop().open()
text: 'xtest'
background_color: 128,128,128,1 #grey
color: 'black'
Or to use the xtest method, instance the MesagePop, and then use the open method.
def xtest(self):
# popup
print('xtext pop')
# RootBoxLayout()
MessagePop().open()
return
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4An19uNgeSZny6vpKOz-7QUgN2suWoY90%3DaLgbvktRK7A%40mail.gmail.com.
Another issue:
with self.canvas:
print(f'{xxc[i-1]=} {type(xxc[i-1])=}')
Color(xxc[i - 1])
Line(rectangle=(xx1, xy1, xx2, xy2))
print(i + 1, xxx[i], xxc[i + 1])
Color(1, 0, 0)
Rectangle(pos=(10, 100), size=(50, 50))
Color(0, 1, 0)
Rectangle(pos=(100, 100), size=(50, 50))
xcc is a string, not a tuple.
xxc[i-1]='(0, .5, .5)' type(xxc[i-1])=<class 'str'>
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4An19uNgeSZny6vpKOz-7QUgN2suWoY90%3DaLgbvktRK7A%40mail.gmail.com.
I see this is from colorcodes.txt file. I’d recommend storing the data as json, use the json module to parse and convert back to python data types. Or better yet use the kivy colormap in utils.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/00a401d9e07e%244dea1d70%24e9be5850%24%40cox.net.
Here is how I would do it – I would use kv to use the canvas so the bind is taken care of by kv. You may have an issue where you need to bind on size or pos change. Or simply move this to kv.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ColorProperty
kv = """
<ColorBox>:
canvas:
Color:
rgb: root.color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 5
rows: 3
"""
xb = [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], \
[.5, 0, .5], [1, 1, 0], [0, 1, 0], [0, .5, .5], [0, 1, 0, 1], \
[.5, .5, .5], [.5, 0, 0], [0, 0, .5], [.5, .5, 0], [.75, .75, .75]
class ColorBox(BoxLayout):
color = ColorProperty()
class ColorBoxes(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
for color in xb:
box = ColorBox(color=color)
self.root.add_widget(box)
ColorBoxes().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f731849f-d5f3-4a18-8a1f-411be47fb15dn%40googlegroups.com.
Here is the same code but using the canvas in python instead of kv.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ColorProperty
from kivy.graphics import Color, Rectangle
kv = """
# <ColorBox>:
# canvas:
# Color:
# rgb: root.color
# Rectangle:
# size: self.size
# pos: self.pos
GridLayout:
cols: 5
rows: 3
"""
xb = [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], \
[.5, 0, .5], [1, 1, 0], [0, 1, 0], [0, .5, .5], [0, 1, 0, 1], \
[.5, .5, .5], [.5, 0, 0], [0, 0, .5], [.5, .5, 0], [.75, .75, .75]
class ColorBox(BoxLayout):
color = ColorProperty()
def __init__(self, **kwargs):
super().__init__(**kwargs)
with self.canvas:
self.c = Color(self.color)
self.rect = Rectangle(pos=self.pos, size=self.size)
self.bind(size=self.set_colors)
self.bind(pos=self.set_colors)
def set_colors(self, *args):
self.rect.pos = self.pos
self.rect.size = self.size
self.c.rgba = self.color
class ColorBoxes(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
for color in xb:
box = ColorBox(color=color)
self.root.add_widget(box)
ColorBoxes().run()
From: elli...@cox.net <elli...@cox.net>
Sent: Thursday, September 7, 2023 9:10 PM
To: 'kivy-...@googlegroups.com' <kivy-...@googlegroups.com>
Subject: RE: [kivy-users] Some Questions (unrelated)
Here is how I would do it – I would use kv to use the canvas so the bind is taken care of by kv. You may have an issue where you need to bind on size or pos change. Or simply move this to kv.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ColorProperty
kv = """
<ColorBox>:
canvas:
Color:
rgb: root.color
Rectangle:
size: self.size
pos: self.pos
GridLayout:
cols: 5
rows: 3
"""
xb = [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], \
[.5, 0, .5], [1, 1, 0], [0, 1, 0], [0, .5, .5], [0, 1, 0, 1], \
[.5, .5, .5], [.5, 0, 0], [0, 0, .5], [.5, .5, 0], [.75, .75, .75]
class ColorBox(BoxLayout):
color = ColorProperty()
class
ColorBoxes(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
for color in xb:
box = ColorBox(color=color)
self.root.add_widget(box)
ColorBoxes().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f731849f-d5f3-4a18-8a1f-411be47fb15dn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/01bc01d9e20c%24fac15740%24f04405c0%24%40cox.net.
Like this?
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ColorProperty
from kivy.uix.label import Label
kv = """
<ColorBox>:
canvas:
Color:
rgb: root.color
Line:
rectangle: (*self.pos, *self.size)
FloatLayout:
"""
xb = [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], \
[.5, 0, .5], [1, 1, 0], [0, 1, 0], [0, .5, .5], [0, 1, 0, 1], \
[.5, .5, .5], [.5, 0, 0], [0, 0, .5], [.5, .5, 0], [.75, .75, .75]
class ColorBox(FloatLayout):
color = ColorProperty()
class ColorBoxes(App):
def build(self):
return Builder.load_string(kv)
def on_start(self
):
x = 0;
y = 0;
i = 0
for color in xb:
box = ColorBox(color=color, pos=(x, y), size_hint=(None, None), size=(125, 50))
self.root.add_widget(box)
self.root.add_widget(Label(text=str(xb[i]), pos=(x, y), size_hint=(None, None), size=(125, 50)))
x = x + 50;
y = y + 50
print(xb[i], x, y)
i = i + 1
ColorBoxes().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4CXJcvhREXiYVZNXzWT%2BrnUQhcXSQ2x6OH0jZSkWRuQtg%40mail.gmail.com.
Or you could use the canvas from the Label…
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import ColorProperty
from kivy.uix.label import Label
kv =
"""
<ColorBox>:
canvas.before:
Color:
rgb: root.box_color
Line:
rectangle: (*self.pos, *self.size)
FloatLayout:
"""
xb = [1, 1, 1], [0, 1, 1], [1, 0, 0], [0, 1, 0], [0, 0, 1], \
[.5, 0, .5], [1, 1, 0], [0, 1, 0], [0, .5, .5], [0, 1, 0, 1], \
[.5, .5, .5], [.5, 0, 0], [0, 0, .5], [.5, .5, 0], [.75, .75, .75]
class ColorBox(Label):
box_color = ColorProperty()
class ColorBoxes(App):
def build(self):
return Builder.load_string(kv)
def on_start(self
):
x = 0;
y = 0;
i = 0
for color in xb:
box = ColorBox(text=str(xb[i]), box_color=color, pos=(x, y), size_hint=(None, None), size=(125, 50))
self.root.add_widget(box)
x = x + 50;
y = y + 50
print(xb[i], x, y)
i = i + 1
ColorBoxes().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAHHXr4CXJcvhREXiYVZNXzWT%2BrnUQhcXSQ2x6OH0jZSkWRuQtg%40mail.gmail.com.