https://kivy.org/doc/stable/api-kivy.graphics.html#kivy.graphics.Line
If the line width is 1, the dash parameters work to create a dashed line. For width greater than 1, you would need to create your own line segments.
from kivy.app import App
from kivy.lang import Builder
kv = """
<DashedLabel@Label>:
canvas:
Color:
rgb: 1, 1, 1
Line:
dash_offset: 2
dash_length: 10
rectangle: (*self.pos, *self.size)
BoxLayout:
padding: 20
spacing: 20
DashedLabel:
text: 'One'
DashedLabel:
text: 'Two'
"""
class DashedApp(App):
def build(self):
return Builder.load_string(kv)
DashedApp().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/378c3985-6e3a-4198-baab-d16fa0ed5201n%40googlegroups.com.
From the docs:
dash_length: int
Length of a segment (if dashed), defaults to 1.
dash_offset: int
Offset between the end of a segment and the beginning of the next one, defaults to 0. Changing this makes it dashed.
dashes: list of ints
List of [ON length, offset, ON length, offset, …]. E.g. [2,4,1,6,8,2] would create a line with the first dash length 2 then an offset of 4 then a dash lenght of 1 then an offset of 6 and so on. Defaults to []. Changing this makes it dashed and overrides dash_length and dash_offset.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/afd1cf93-e851-4995-987c-82c440ee47cdn%40googlegroups.com.
360 – 315 = 45, not 90
The ellipse you are drawing is not a circle if that matters. The size and height would need to be that same to draw a circle.
Rounded rectangle:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6f59e56a-1a9c-4667-9c84-ba67ccdc5f9en%40googlegroups.com.
I’ve updated the example:
from kivy.app import App
from kivy.lang import Builder
from kivy.animation import Animation
from kivy.uix.label import Label
from kivy.properties import NumericProperty
kv = """
<RRLabel>:
canvas:
Color:
rgb: 1, 1, 1
Line:
width: 1.2
rounded_rectangle: (self.center_x - 50, self.center_y - 50, 100, 100, 0, 20, 0, 0)
canvas.before:
PushMatrix
Rotate:
angle: root.angle
origin: self.center
canvas.after:
PopMatrix
BoxLayout:
orientation: 'vertical'
BoxLayout:
padding: 100
spacing: 75
RRLabel:
id: rr1
text: 'One'
RRLabel:
id: rr2
text: 'Two'
Button:
size_hint_y: None
height: 48
text: 'Spin'
on_release:
rr1.spin()
rr2.spin()
"""
class RRLabel(Label):
angle = NumericProperty(0)
def spin(self):
self.angle = 0
anim = Animation(angle=360)
anim.start(self)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1144667b-3eb2-403a-b85a-d569fc9930b0n%40googlegroups.com.
how can I reference the canvas in __init__ function
self.canvas
You may want to use it with a context manager: with self.canvas:
See: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=canvas#basic-drawing
I’d need to see more code to help with your other questions.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5c09cdb4-2350-4a9a-8ca6-fa50900015a6n%40googlegroups.com.
Sorted is a python built in: https://docs.python.org/3/library/functions.html#sorted
It returns a sorted list. In the context below it can be used as a clamp, to return a value no higher that max and no lower that min
value = sorted(min, v, max)[1]
sorted returns a sorted list, if v is less that min: [v, min, max]
and [v, min, max][1] is min
if v is between min and max… [min, v, max][1] is v
and if v is over max… [min, max, v][1] is max.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5ebfbe46-4ae2-410f-825b-557aaf76de90n%40googlegroups.com.
I would need more context.
collide_widget takes x,y as parameters. I don’t know what Line_left is.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4f45fba2-e3fd-4b8a-a313-01bb55741b44n%40googlegroups.com.
Line left is one of the lines I have drawn using canvas,,
So I believe the only way is to make a class inside a line drawn in this class and add this class to the main class in order to make a line act as a widget
"""
:
:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6019ac6f.1c69fb81.a102a.9aaaSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
The collide_widget method is a widget method and takes a widget as an argument. You would need to have the widget be the same size at the line (and assuming the line is a rectangle) for this to work. You could also create your own collide test for the line.
Here is the code for collide_widget:
def collide_widget(self, wid):
'''
Check if another widget collides with this widget. This function
performs an axis-aligned bounding box intersection test by default.
:Parameters:
`wid`: :class:`Widget` class
Widget to test collision with.
:Returns:
bool. True if the other widget collides with this widget, False
otherwise.
.. code-block:: python
>>> wid = Widget(size=(50, 50))
>>> wid2 = Widget(size=(50, 50), pos=(25, 25))
>>> wid.collide_widget(wid2)
True
>>> wid2.pos = (55, 55)
>>> wid.collide_widget(wid2)
False
'''
if self.right < wid.x:
return False
if self.x > wid.right:
return False
if self.top < wid.y:
return False
if self.y > wid.top:
return False
return True
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/DBBPR09MB4699F7B0D0A67E0CE1E190E994B59%40DBBPR09MB4699.eurprd09.prod.outlook.com.
This is just a code snippet. Please attach an executable program.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c111f2a7-7a51-403e-8b6a-d4c033693e65n%40googlegroups.com.
Looking at your code I got a sense of what you are trying to do – but I don’t full understand it. I thought this approach might be a simpler way to get to same outcome. This code creates a dynamically sized widget, that gets size by touch movement.
This code creates a float widget, and draw a resizable rectangle the move action is changed based on the original on_touch_down position. This is not intended to do exactly what you want – but to illustrate an approach.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ColorProperty
kv = """
<ResizeSelect>:
canvas:
Color:
rgba: root.color
Line:
rectangle: (*self.pos, *self.size)
FloatLayout:
ResizeSelect:
size_hint: None, None
size: 100,100
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
"""
class ResizeSelect(FloatLayout):
color = ColorProperty('white')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.quadrant = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
# which corner is closest NE, NW, SE, SW?
x, y = self.to_widget(*touch.pos)
self.quadrant = 'N' if y > self.center[1] else 'S'
self.quadrant += 'W' if x > self.center[0] else 'E'
print(self.quadrant)
return True
return super().on_touch_down(touch)
def on_touch_move(self, touch):
if touch.grab_current is self:
if self.quadrant == 'NW':
self.height += 2 * touch.dy
self.width += 2 * touch.dx
return True
if self.quadrant == 'NE':
self.height += 2 * touch.dy
self.width += 2 * -touch.dx
return True
if self.quadrant == 'SW':
self.height += 2 * -touch.dy
self.width += 2 * touch.dx
return True
if self.quadrant == 'SE':
self.height += 2 * -touch.dy
self.width += 2 * -touch.dx
return True
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
return True
return super().on_touch_up(touch)
class ResizeWidgetApp(App):
def build(self):
return Builder.load_string(kv)
ResizeWidgetApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c111f2a7-7a51-403e-8b6a-d4c033693e65n%40googlegroups.com.
Read: https://kivy.org/doc/stable/api-kivy.input.motionevent.html?highlight=touch
touch.x, touch.y is the position of the mouse in windows coordinates.
dx and dy are the change from the previous position to the current position.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6374a222-f5bd-4432-b186-988b1f0b62e8n%40googlegroups.com.
On Feb 4, 2021, at 3:22 PM, Sadaka Technology <sersa...@outlook.com> wrote:
I tried you example, when clicking on bottom left and top left corners I am getting SE , when clicking on bottom and top right I am getting SW o.o
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b544e148-7a05-48c8-b37d-063e290c02ddn%40googlegroups.com.
On Feb 4, 2021, at 3:42 PM, Elliot Garbus <elli...@cox.net> wrote:
That does not sound right the example was working for me.
On Feb 4, 2021, at 3:20 PM, Sadaka Technology <sersa...@outlook.com> wrote:
so if I use x,y self.to_widget I get dx and dy ?!
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4a4514b1-3ca5-48cd-bdd0-03ea00aed4e0n%40googlegroups.com.
Seems unlikely. Are you running the example unmodified?
I just confirmed, it works as expected on Kivy 2.0.0, python 3.9.1
I modified the app to change the color property to a ListProperty, and It works as expect on kivy 1.11.1 and Python 3.7.4
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/e6b992f9-4a39-463a-a6cf-441369445fb8n%40googlegroups.com.
Double check that the code is all there - that is strange that it is not running.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/65743c68-320a-43b7-8396-048ba346c5b1n%40googlegroups.com.
As I have put it together I am looking for a touch in a quadrant and sizing the entire box. If you want to maintain that behavior, add some new cases to the on_touch_down(), if the press is near the center of a side give that a ‘name’ NN, SS, EE, WW… and create the appropriate action in on_touch_move.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/73fa5346-fe7e-4e47-9707-19d581c49ac6n%40googlegroups.com.
Do you want to only resize a side, or sides and corners?
If you want to have a min size, set that up in the on_touch_move so the size can be no smaller than the min.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/dea98af4-50b0-4cb6-879f-7e6a20875b2cn%40googlegroups.com.
I would not use size hints or pos hints if you need to change the size and pos of the widget.
I suggest you start with the example I posted. Make small changes. If you have questions – ask and post the code.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4ca6fb15-6d9d-4e5f-ab2a-0a75ef4cf14an%40googlegroups.com.
To change the size from the right. I would not touch the position, but reduce the size (or perhaps just setting self.right ?). To change the size on the left, I would change the position and the size.
I would really like to know, the differences betweeen x,y = self.to_widget(*touch.pos) and touch.pos how it will differ and when it is equal. Only different if the widget is in a RelativeLayout. Read: https://kivy.org/doc/stable/api-kivy.uix.relativelayout.html#coordinate-systems
difference between touch.dx/touch.dy and touch.x/touch.y. I had described this previously. I’ll try again.
Read: https://kivy.org/doc/stable/api-kivy.input.html
Using x as an example:
x is the position x, in windows coordinates
px is the previous position of x
dx = x – px
If the pointer was a x = 100, and you moved 5 pixels, dx would be 5. The best way to understand this is to put together a simple example and print out the values.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/1f66a9c5-3a87-4df7-a1e2-33c173df9b3en%40googlegroups.com.
I extended the example… I did not have time to get all of the size limits in place… Let me know if this is in the right direction…
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ColorProperty
import math
kv = """
<ResizeSelect>:
canvas:
Color:
rgba: root.top_color
Line:
width: 1.2
points: (self.x, self.top, self.right, self.top) # Top
Color:
rgba: root.bottom_color
Line:
width: 1.2
points: (*self.pos, self.right, self.y) # Bottom
Color:
rgba: root.left_color
Line:
width: 1.2
points: (*self.pos, self.x, self.top) # Left
Color:
rgba: root.right_color
Line:
width: 1.2
points: (self.right, self.y, self.right, self.top) # Right
FloatLayout:
ResizeSelect:
size_hint: None, None
size: 100,100
pos: 200, 200
"""
class ResizeSelect(FloatLayout):
top_color = ColorProperty('white')
bottom_color = ColorProperty('white')
left_color = ColorProperty('white')
right_color = ColorProperty('white')
highlight_color = ColorProperty('red')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.selected_side = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
# use the distance formula to find the shortest distance to a line center
# d = sqrt((x1-x2)^2 - (y1-y2)^2)
x, y = self.to_widget(*touch.pos)
d_b = math.sqrt(((x - self.center_x) ** 2) + ((y - self.y) ** 2)) # bottom
d_t = math.sqrt(((x - self.center_x) ** 2) + ((y - self.top) ** 2)) # top
d_l = math.sqrt(((x - self.x) ** 2) + ((y - self.center_y) ** 2)) # left
d_r = math.sqrt(((x - self.right) ** 2) + ((y - self.center_y) ** 2)) # right
print(f'{d_b=}, {d_t=}, {d_l=}, {d_r=}')
# create tuples
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
distances.sort(key=lambda dist: dist[1])
self.selected_side = side = distances[0][0]
if side == 'top':
self.top_color = self.highlight_color
elif side == 'bottom':
self.bottom_color = self.highlight_color
elif side == 'left':
self.left_color = self.highlight_color
elif side == 'right':
self.right_color = self.highlight_color
return True
return super().on_touch_down(touch)
def on_touch_move(self, touch):
min_size = 15.0
if touch.grab_current is self:
if self.selected_side == 'top':
self.height = max(self.height + touch.dy, min_size)
elif self.selected_side == 'bottom': # TODO: Add limits to other dimensions...
self.height -= touch.dy
self.y += touch.dy
elif self.selected_side == 'left':
self.x += touch.dx
self.width -= touch.dx
elif self.selected_side == 'right':
self.width += touch.dx
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.bottom_color = self.top_color = self.left_color = self.right_color = 'white'
return True
return super().on_touch_up(touch)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2fc8a95d-45a2-49a5-9d74-25123933c13en%40googlegroups.com.
The distances of the current touch are calculated to the middle of each of the sides. The app then determines the slide that is closest to the touch.
# a list of tuples that associates a name with each of the measurements.
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
# to find the smallest tuple the app sorts the values. The values need to be sorted by the distance value, not the name.
# sort uses key to indicate the value to be used for sort. Key take a function that is passed a list element and returns the sort key
# this is the typical use of a lambda. A lambda is an anonymous function. Passed a tuple from the list “dist” it returns dist[1], a distance value
distances.sort(key=lambda dist: dist[1])
# distances is now sorted, the smallest element is in distances[0]. The name is in distances[0][0]
self.selected_side = side = distances[0][0]
Answering your question I realize this could be written with the built-in min() function. The logic is the same, the code is even shorter:
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
self.selected_side = side = min(distances, key=lambda dist: dist[1])[0]
From: Sadaka Technology
Sent: Sunday, February 7, 2021 3:30 AM
To: Kivy users support
Subject: Re: RE: [kivy-users] simple dashed line
here comes the questions if ok for you:
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
distances.sort(key=lambda dist: dist[1])
self.selected_side = side = distances[0][0]
these 3 lines, what is the use of .sort and lambda, what is dist : dist[1], and tuples inside list
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2e937e10-193f-4cb8-bcfa-bf9086d1e1fbn%40googlegroups.com.
Draw the lines 10 pixels inside their current positions. Then all of the other logic remains the same, and you are sure you are clicking on this widget, and not one next to it.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7ba12b79-8409-4cb1-8ae8-562191ffdd63n%40googlegroups.com.
I put the ResizeSelect widget in a RelativeLayout. You can see there are now different values for the to_widget(), but I realize the conversion is not required because the ResizeSelect widget is a FloatLayout.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.relativelayout import RelativeLayout
"""GridLayout:
cols:2
rows: 2
Button:
text: 'One'
Button:
text: 'Two'
Button:
text:'Three'
BoxLayout:
RelativeLayout:
Button:
text: 'RB'
pos_hint: {'top': 1, 'right': 1}
size_hint: None, None
size: 100, 100
ResizeSelect:
size_hint: None, None
size: 100,100
pos: 20, 20
"""
class ResizeSelect(FloatLayout):
top_color = ColorProperty('white')
bottom_color = ColorProperty('white')
left_color = ColorProperty('white')
right_color = ColorProperty('white')
highlight_color = ColorProperty('red')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.selected_side = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
# use the distance formula to find the shortest distance to a line center
# d = sqrt((x1-x2)^2 - (y1-y2)^2)
x, y = touch.pos[0], touch.pos[1]
print(f'{touch.pos=}, {self.to_widget(*touch.pos)=}, {self.center=}')
d_b = math.sqrt(((x - self.center_x) ** 2) + ((y - self.y) ** 2)) # bottom
d_t = math.sqrt(((x - self.center_x) ** 2) + ((y - self.top) ** 2)) # top
d_l = math.sqrt(((x - self.x) ** 2) + ((y - self.center_y) ** 2)) # left
d_r = math.sqrt(((x - self.right) ** 2) + ((y - self.center_y) ** 2)) # right
print(f'{d_b=}, {d_t=}, {d_l=}, {d_r=}')
# create tuples
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
self.selected_side = side = min(distances, key=lambda dist: dist[1])[0]
if side == 'top':
self.top_color = self.highlight_color
elif side == 'bottom':
self.bottom_color = self.highlight_color
elif side == 'left':
self.left_color = self.highlight_color
elif side == 'right':
self.right_color = self.highlight_color
return True
return super().on_touch_down(touch)
def on_touch_move(self, touch):
min_size = 15.0
if touch.grab_current is self:
if self.selected_side == 'top':
self.height = max(self.height + touch.dy, min_size)
elif self.selected_side == 'bottom': # TODO: Add limits to other dimensions...
self.height -= touch.dy
self.y += touch.dy
elif self.selected_side == 'left':
self.x += touch.dx
self.width -= touch.dx
elif self.selected_side == 'right':
self.width = max(self.width + touch.dx, min_size)
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.bottom_color = self.top_color = self.left_color = self.right_color = 'white'
return True
return super().on_touch_up(touch)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f2459b7b-3203-4afd-a01d-5209f8a9a4d4n%40googlegroups.com.
I got started on putting together the layout to update on_touch_move() to restrict the max sizes… I’m not sure where I left this earlier today – I won’t get a chance to get back to this till tomorrow… I’m sharing this WIP in case you do any work on it…
""" cols:3
rows: 3
Button:
text: 'One'
Button:
text: 'Two'
Button:
text:'Three'
Button:
text: 'Four'
BoxLayout:
RelativeLayout:
Button:
text: 'RB'
pos_hint: {'top': 1, 'right': 1}
size_hint: None, None
size: 50, 50
ResizeSelect:
size_hint: None, None
size: 50,50
pos: 20, 20
Button:
text: 'Six'
Button:
text: 'Seven'
Button:
text: 'Eight'
Button:
text:'Nine'
"""
class ResizeSelect(FloatLayout):
top_color = ColorProperty('white')
bottom_color = ColorProperty('white')
left_color = ColorProperty('white')
right_color = ColorProperty('white')
highlight_color = ColorProperty('red')
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.selected_side = None
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
touch.grab(self)
# use the distance formula to find the shortest distance to a line center
# d = sqrt((x1-x2)^2 - (y1-y2)^2)
x, y = touch.pos[0], touch.pos[1
]
# print(f'{touch.pos=}, {self.to_widget(*touch.pos)=}, {self.center=}')
d_b = math.sqrt(((x - self.center_x) ** 2) + ((y - self.y) ** 2)) # bottom
d_t = math.sqrt(((x - self.center_x) ** 2) + ((y - self.top) ** 2)) # top
d_l = math.sqrt(((x - self.x) ** 2) + ((y - self.center_y) ** 2)) # left
d_r = math.sqrt(((x - self.right) ** 2) + ((y - self.center_y) ** 2)) # right
# print(f'{d_b=}, {d_t=}, {d_l=}, {d_r=}')
# create tuples
distances = [('bottom', d_b), ('top', d_t), ('left', d_l), ('right', d_r)]
self.selected_side = side = min(distances, key=lambda dist: dist[1])[0]
if side == 'top':
self.top_color = self.highlight_color
elif side == 'bottom':
self.bottom_color = self.highlight_color
elif side == 'left':
self.left_color = self.highlight_color
elif side == 'right':
self.right_color = self.highlight_color
return True
return super().on_touch_down(touch)
def on_touch_move(self, touch):
min_size = 15.0
if touch.grab_current is self:
print(f'{self.parent.pos=}, {self.pos=}, {touch.pos=}, {self.to_window(*touch.pos)=} {self.parent.right=} ')
x,y = self.to_window(*self.pos)
top = y + self.height
right = x + self.width
if x < self.parent.x or right > self.parent.right:
print('X out of bounds')
if y < self.parent.y or top > self.parent.top:
print('y out of bounds')
if self.selected_side == 'top':
self.height = max(self.height + touch.dy, min_size)
elif self.selected_side == 'bottom': # TODO: Add limits to other dimensions...
self.height -= touch.dy
self.y += touch.dy
self.y = max(self.to_widget(*self.parent.pos)[1], self.y)
elif self.selected_side == 'left':
self.x += touch.dx
self.width -= touch.dx
# self.x = min(self.parent.x, self.x)
elif self.selected_side == 'right':
self.width = max(self.width + touch.dx, min_size)
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.bottom_color = self.top_color = self.left_color = self.right_color = 'white'
return True
return super().on_touch_up(touch)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/60206121.1c69fb81.5bb49.73fbSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
I have updated the test case to look at the widget in both a relative layout and a floatlayout.
The size limit and top position limit (top can not go past parent top) are working. I’ll share more as I update.
""" pos: 20, 40
Label:
text: 'RelativeLayout'
size_hint: None, None
size: self.texture_size
pos_hint: {'center_x': .5, 'y': .05}
Button:
text: 'Six'
FloatLayout:
ResizeSelect:
size_hint: None, None
size: 50,50
pos: 20, 40
Label:
text: 'FloatLayout'
size_hint: None, None
size: self.texture_size
pos_hint: {'center_x': .5, 'y': .05})
x, y = self.to_window(*self.pos)
top = y + self.height
right = x + self.width
if x < self.parent.x or right > self.parent.right:
print('X out of bounds')
if y < self.parent.y or top > self.parent.top:
print('y out of bounds')
if self.selected_side == 'top':
self.height = max(self.height + touch.dy, min_size) # todo: Simplify to include top limit?
if top > self.parent.top:
self.height = self.parent.height - (y - self.parent.y)
elif self.selected_side == 'bottom': # TODO: Add limits to other dimensions...
self.height -= touch.dy
self.y += touch.dy
self.y = max(self.to_widget(*self.parent.pos)[1], self.y)
elif self.selected_side == 'left':
self.x += touch.dx
self.width -= touch.dx
# self.x = min(self.parent.x, self.x)
elif self.selected_side == 'right':
self.width = max(self.width + touch.dx, min_size)
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.bottom_color = self.top_color = self.left_color = self.right_color = 'white'
return True
return super().on_touch_up(touch)
class ResizeWidgetApp(App):
def build(self):
return Builder.load_string(kv)
ResizeWidgetApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ebec8bf1-7ce3-4fc3-af57-fefdc7563081n%40googlegroups.com.
Are you using my most recent example? I don’t see that issue.
Here is an update top and right now limited to parent size.
:
self.height = sorted([min_size, self.height + touch.dy, self.parent.height - (y - self.parent.y)])[1]
elif self.selected_side == 'bottom':
self.height -= touch.dy
self.y += touch.dy
self.y = max(self.to_widget(*self.parent.pos)[1], self.y)
elif self.selected_side == 'left':
self.x += touch.dx
self.width -= touch.dx
# self.x = min(self.parent.x, self.x)
elif self.selected_side == 'right':
self.width = sorted([min_size, self.width + touch.dx, self.parent.width - (x - self.parent.x)])[1]
return super().on_touch_move(touch)
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.bottom_color = self.top_color = self.left_color = self.right_color = 'white'
return True
return super().on_touch_up(touch)
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b4f0ab99-d2c2-476d-9948-abb08cc1203bn%40googlegroups.com.
If you’d like more of my help – start with the example I sent and modify as little as possible to better reflect your use case. I’m suggesting a way to create a minimal runnable example. If you want to start with your code – that will work also.
The scrollview is a complex widget – it is quite possible there are touch interactions going on with the widget and the scrollview.
You can paste code into the google groups by right clicking and selecting paste as text.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/9ab61a19-fecb-4281-aebc-ba90dcbe04b8n%40googlegroups.com.
That aint working bro, I tried all methods everythinf, this scrollview is disturbing all, it is applying multiple on touch down methods, we have to trick it in a way that on touch down can only be called once and released on touch up, I will try the variable method
Tuesday, 09 February 2021, 03:16AM +04:00 from Elliot Garbus elli...@cox.net:If you’d like more of my help – start with the example I sent and modify as little as possible to better reflect your use case. I’m suggesting a way to create a minimal runnable example. If you want to start with your code – that will work also.
The scrollview is a complex widget – it is quite possible there are touch interactions going on with the widget and the scrollview.
You can paste code into the google groups by right clicking and selecting paste as text.
From: Sadaka Technology
Sent: Monday, February 8, 2021 3:08 PM
To: Kivy users support
Subject: Re: RE: [kivy-users] simple dashed line
I am sorry I couldn't make the code for my total example cuz it is very big, but this python file will explain all what I am doing.: another thing I dont know how to write code in google groups :D
On Tuesday, February 9, 2021 at 1:52:29 AM UTC+4 Sadaka Technology wrote:
look your example is gridLayout with cols and rows, mine is diff due to maybe scrollview, I am ofcourse freezing the scrollview during resize , I will show you a pick of how it looks like, these are 2 windows inside scrollview, rows=1 , and more windows I can add, you can see the blue rectangle which is a widget, in this blue rectangle I added the resize widget, with size equals to the size of the resize widget, I also tried to add the resize widget inside the bigger FloatLayout, same issue is following
On Tuesday, February 9, 2021 at 1:44:16 AM UTC+4 Sadaka Technology wrote:
ofcourse I used your recent example
On Tuesday, February 9, 2021 at 1:24:00 AM UTC+4 ElliotG wrote:
Are you using my most recent example? I don’t see that issue.
Here is an update top and right now limited to parent size.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ColorProperty
import math
kv =
"""
"""
import math
kv = """
"""
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6021c62c.1c69fb81.64a30.f02bSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
Touches get bubbled down to children, and across children. I suspect the Scrollview is consuming touches. You may want to consider an implementation that does not rely on this widget in a ScrollView. You can try overloading the ScrollView on_touch methods to see if ScrollView is consuming the touches.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/DBBPR09MB46993DB9610ECE7370CB9925948D9%40DBBPR09MB4699.eurprd09.prod.outlook.com.
I would look at binding to the Window size event.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3d58a346-137f-43b1-af78-099801a0d446n%40googlegroups.com.