Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
draw ui.Path within the coordinate system of a node
-
@mikeno said:
it doesn’t with several polygons
import ui class my(ui.View): def draw(self): w,h = ui.get_screen_size() path1 = ui.Path() path1.line_width = 3 ui.set_color('red') path1.move_to(100,100) path1.line_to(200,100) path1.line_to(100,200) path1.close() path1.fill() path2 = ui.Path()#.rect(0,0,w,h) path2.line_width = 3 ui.set_color('blue') path2.move_to(300,100) path2.line_to(400,100) path2.line_to(300,200) path2.close() path2.fill() v = my() v.present('fullscreen',hide_title_bar=True)
-
-
Thx to both of you, concerning the gestures, it seems to be a little bit complicated but I will try
-
My last issue is that the drawing doesn’t refresh even when I call explicitly drawTest() as you can see in the example below:
import ui class my(ui.View): def __init__(self, *args, **kwargs): self.factor = .5 def draw(self): print('draw()') self.drawTest() def drawTest(self): print('drawTest()') print('%.1f' % (self.factor)) w,h = ui.get_screen_size() path1 = ui.Path() path1.line_width = 3 ui.set_color('red') path1.move_to(100*self.factor,100*self.factor) path1.line_to(200*self.factor,100*self.factor) path1.line_to(100*self.factor,200*self.factor) path1.close() path1.fill() path2 = ui.Path()#.rect(0,0,w,h) path2.line_width = 3 ui.set_color('blue') path2.move_to(300*self.factor,100*self.factor) path2.line_to(400*self.factor,100*self.factor) path2.line_to(300*self.factor,200*self.factor) path2.close() path2.fill() def touch_began(self, touch): print('touch_began()') self.factor += .5 self.drawTest() def will_close(self): print('will_close()') v = my() v.present('fullscreen',hide_title_bar=True)
It redraws only when I turn the iPad, could you please tell me how I can force the refresh with the right zoom factor?
-
@mikeno start from
import ui class my(ui.View): def __init__(self, *args, **kwargs): self.w,self.h = ui.get_screen_size() iv = ui.ImageView(name='iv') iv.frame = (0,0,self.w,self.h) self.add_subview(iv) self.factor = .5 self.update_interval = 1 def update(self): with ui.ImageContext(self.w,self.h) as ctx: path1 = ui.Path() path1.line_width = 3 ui.set_color('red') path1.move_to(100*self.factor,100*self.factor) path1.line_to(200*self.factor,100*self.factor) path1.line_to(100*self.factor,200*self.factor) path1.close() path1.fill() path2 = ui.Path()#.rect(0,0,w,h) path2.line_width = 3 ui.set_color('blue') path2.move_to(300*self.factor,100*self.factor) path2.line_to(400*self.factor,100*self.factor) path2.line_to(300*self.factor,200*self.factor) path2.close() path2.fill() ui_image = ctx.get_image() self['iv'].image = ui_image def touch_began(self, touch): self.factor += .5 def will_close(self): print('will_close()') v = my() v.present('fullscreen',hide_title_bar=True)
-
Whao, I’m impressed, thank you!
But I don’t understand why it doesn’t work in my last example -
-
@mikeno just to show how it is easy to use @mikael 's gestures module, use two fingers to pinch
import ui from gestures import * class my(ui.View): def __init__(self, *args, **kwargs): self.w,self.h = ui.get_screen_size() iv = ui.ImageView(name='iv') iv.frame = (0,0,self.w,self.h) self.add_subview(iv) self.factor = .5 #self.update_interval = 1 self.pinch = pinch(iv,self.did_pinch) self.update() def update(self): with ui.ImageContext(self.w,self.h) as ctx: path1 = ui.Path() path1.line_width = 3 ui.set_color('red') path1.move_to(100*self.factor,100*self.factor) path1.line_to(200*self.factor,100*self.factor) path1.line_to(100*self.factor,200*self.factor) path1.close() path1.fill() path2 = ui.Path()#.rect(0,0,w,h) path2.line_width = 3 ui.set_color('blue') path2.move_to(300*self.factor,100*self.factor) path2.line_to(400*self.factor,100*self.factor) path2.line_to(300*self.factor,200*self.factor) path2.close() path2.fill() ui_image = ctx.get_image() self['iv'].image = ui_image def did_pinch(self, data): self.factor = data.scale self.update() def will_close(self): print('will_close()') def pinch_handler(data): print(data) v = my() v.present('fullscreen',hide_title_bar=True)
-
Thx cvp but I don’t know how to download a module into Pythonista
-
@mikeno use, and keep for the future, this script
import requests import os url = 'https://raw.githubusercontent.com/mikaelho/pythonista-gestures/master/gestures.py' response = requests.get(url) content = str(response.content.decode('utf-8')) file_path = os.path.expanduser('~/Documents/site-packages/gestures.py') with open(file_path,mode='wt',encoding='utf-8') as fil: fil.write(content)
-
Super, thank you
-
-
@ccc you're right here with a script but I'm sure that I had to use decode in the past for some web page containing special characters...But never mind, your code is better.
-
@mikeno, your script did not redraw on touch because your method did not get called with the drawing context that
draw
does. To make it work, trigger thedraw
withself.set_needs_display()
.For installing stuff, recommend taking the time to install stash, for
pip install
support.But keep @cvp’s install script around, most of the little things we build do not end up in pip/PyPI.
-
@mikael said:
To make it work, trigger the draw with self.set_needs_display().
Forgotten, halala this too old memory 😢
-
I do have a follow up question though. Is it possible to access the points of a path after it has been created? edit: and with access I mean read them. mx player
-
@rajputaman04, unfortunately no.