Thank you very much!
I wasn't checking for a few days, now I have even someone writing code for me, wasn't intended by request - @abcabc thank you very much for your effort, you shouldn't have :)
also a big thank you @mikael! Made things clearer.
I think I get it from here. As I'm already thanking, some heartful of thankyous also to @omz for the great Pythonista app!
❤
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.
Posts made by sGiForceOne
-
RE: set_needs_display() explained
-
RE: set_needs_display() explained
I'm sorry the code I've pasted is not a working one: But the ui.View (Player) is already "visible", it takes place in the upper left corner of the board. The board can't detect touch event at this place, and the touch events it can, won't show up because these coordinates are out of Players area.
When I callwhite = Player((5,5) ,'white') v.add_subview(white)
it shows up, visible. The call with touch.location doesn't work, my bad. I know :( So here I am and need another way, exactly because of this - Players view covers Board's view and the latter can't detect touch events anymore ¯\_(ツ)_/¯ I don't see how .present() helps, I even tried and it produces an error (view already presented.). Thank you
-
set_needs_display() explained
Hello everybody
I try to get to know pythonistas ui-module. I would like to code the ui manually, so far I refuse editors, because I think I'd miss some learning. And I need some. Please :)
Anyway, my try is a "Merrills" -game. The board is the ui.View.
I'm struggling to put the players pieces on it. Following is the shortened code as it is now. A Player-class should paint the bricks.
I made it also ui.View because otherwise I couldn't make it shown.
But that brings other problems, like that the touch from the root ui.View Board doesn't work anymore where Player exist etc.
So, I should probably have another way. Because of this I'm asking generally how to use set_needs_display, I think there could be the trick.
Hoping anyone understands somthing of my request :P
Thank you very much in advance :)import ui class Player(ui.View): def __init__(self, pos, color): #self.bring_to_front() print(pos) self.xpos, self.ypos = pos self.color = color def draw(self): ui.set_color(self.color) self.piece = ui.Path.oval(self.xpos, self.ypos, 50, 50) self.piece.fill() class Board(ui.View): def __init__(self): self.height, self.width = 500, 500 self.background_color = 0.8, 0.7, 0.5 self.name = "Mill" self.positions = [] def draw(self): ui.set_color('black') upper = int(self.width//2-50) lower = int(self.width//4-25) for x, size in zip(range(upper, -1, -lower), range(lower, 501, upper)): if x == 0: x += 20 size -= 40 rect = ui.Path.rect(x, x, size, size) rect.line_width = 10 rect.stroke() def strokeLine(fx, fy, tx, ty): line = ui.Path() line.move_to(fx, fy) line.line_to(tx, ty) line.line_width = 5 line.stroke() strokeLine(self.width/2, 20, self.width/2, upper) strokeLine(self.width/2, self.height-20, self.width/2, upper+lower) strokeLine(20, self.height/2, upper, self.height/2) strokeLine(self.width-20, self.height/2, upper+lower, self.height/2) def touch_began(self, touch): black = Player(touch.location, 'black') self.add_subview(black) v = Board() v.present('sheet')