omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Frame for tetris

    Pythonista
    6
    60
    19404
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp last edited by cvp

      @Karina said:

      _suspend_updates

      1 Reply Last reply Reply Quote 2
      • Karina
        Karina last edited by

        Here's the code

        from scene import *
        
        sw, sh = get_screen_size()
        rect_w = sw/3
        rect_h = sh-100
        
        class Board(ShapeNode):
             def __init__(self, stroke_color, line_width, parent, *args, **kwargs):
        
                  self.stroke_color = stroke_color
                  path=ui.Path.rect(0, 0, rect_w, rect_h)
                  path.line_width = line_width
                  self.parent = parent
        
        super.__init__(path,
                                 fill_color='white',
                                 stroke_color=self.stroke_color,
                                 parent=parent,
                                *args, **kwargs)
        
        
        class Game(Scene):
             def setup(self):
                  self.background_color = 'white'
                  grey_rect = Board(stroke_color='grey', line_width=2, parent=self)
                  rect.line_width = 10
                  board = Board(position=(sw/2, sh/2), stroke_color='purple', path=rect, parent=self)
        
        
        run(Game())
        

        The idea is to create a rect in grey color line_width 2, and draw with it grey lines. Then draw above a purple rect above. I would draw that on paper, but i don't know how to add photos here
        And the error - TypeError, 'Board' object has no attribute '_suspend_updates'

        cvp 2 Replies Last reply Reply Quote 0
        • cvp
          cvp @Karina last edited by cvp

          @Karina some small errors:

          • super without parenthesis
          • rect.line_width but rect is not yet defined
          • mix of positional and keyword parameters
          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @Karina last edited by cvp

            @Karina not yet fully solved but this (incomplete) script works

            
            from scene import *
            
            sw, sh = get_screen_size()
            rect_w = sw/3
            rect_h = sh-100
            
            class Board(ShapeNode):
                 def __init__(self, stroke_color='grey', line_width=1, parent=None, *args, **kwargs):
                      #self.stroke_color = stroke_color
                      path=ui.Path.rect(0, 0, rect_w, rect_h)
                      path.line_width = line_width
                      #self.parent = parent
                      super().__init__(path,
                                     fill_color='white',
                                     stroke_color=stroke_color,
                                     parent=parent,
                                    *args, **kwargs)
            
            
            class Game(Scene):
                 def setup(self):
                      self.background_color = 'white'
                      grey_rect = Board(stroke_color='grey', line_width=2, parent=self)
                      #rect.line_width = 10
                      board = Board(stroke_color='purple', line_width=10, parent=self, position=(sw/2, sh/2))
            
            
            run(Game()) 
            
            1 Reply Last reply Reply Quote 0
            • Karina
              Karina last edited by Karina

              @cvp what do you mean super without parenthesis?
              About rect - I tried different ways to initiate board and forgot to delete rect.line_width

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Karina last edited by

                @Karina you wrote

                super.__init__ 
                

                instead of

                super().__init__ 
                
                1 Reply Last reply Reply Quote 0
                • Karina
                  Karina last edited by

                  @cvp what did you change that it works now?

                  cvp 1 Reply Last reply Reply Quote 0
                  • Karina
                    Karina last edited by

                    For now it’s like this

                    from scene import *
                    import arrows
                    
                    sw, sh = get_screen_size()
                    rect_w = sw/3
                    rect_h = sh-100
                    
                    class Board(ShapeNode):
                    	def __init__(self, stroke_color='grey', line_width=1, parent=None, *args, **kwargs):
                    			path = ui.Path.rect(0, 0, rect_w, rect_h)
                    			path.line_width = line_width
                    			super().__init__(path,
                    							 fill_color='white',
                    							 stroke_color=stroke_color,
                    							 parent=parent,
                    							 *args, **kwargs)
                    			
                    			if stroke_color == 'grey':
                    				print(stroke_color)
                    				d = int(rect_w/30)
                    				for l in range(int(rect_w/d)):
                    					x = l*d
                    					path.move_to(x, 0)
                    					path.line_to(x, rect_h)
                    
                    
                    class Game(Scene):
                    	def setup(self):
                    		self.background_color = 'white'
                    		grey_rect = Board(line_width=2, parent=self, position=(sw/2, sh/2))
                    		board = Board(stroke_color='purple', line_width=10, parent=self, position=(sw/3, sh/2))
                    		self.add_buttons()
                    		
                    	def add_buttons(self):
                    		ars = arrows.Main()
                    		self.present_modal_scene(ars)
                    
                    
                    run(Game())  
                    

                    I use another pos in grey_rect to see that both are drawn, it shouldn’t be in the end like that
                    But here there’s no vertical grey lines, though they in init. And it prints ‘grey’, so he gets in that for

                    cvp 2 Replies Last reply Reply Quote 0
                    • cvp
                      cvp @Karina last edited by

                      @Karina said:

                      what did you change that it works now?

                      Check the differences in positional/keyword parameters in

                      def __init__(...
                      
                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @Karina last edited by cvp

                        @Karina said:

                        But here there’s no vertical grey lines, though they in init.

                        Put the draw lines before the super().init....

                                    if stroke_color == 'grey':
                                        print(stroke_color)
                                        d = int(rect_w/30)
                                        for l in range(int(rect_w/d)):
                                            x = l*d
                                            path.move_to(x, 0)
                                            path.line_to(x, rect_h)
                           
                                    super().__init__(path,
                                                     fill_color='white',
                                                     stroke_color=stroke_color,
                                                     parent=parent,
                                                     *args, **kwargs) 
                        

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @Karina last edited by cvp

                          @Karina 😥 and a small correction

                                  #grey_rect = Board(line_width=2, parent=self, position=(sw/2, sh/2))
                                  board = Board(stroke_color='purple', line_width=10, parent=self, position=(sw/3, sh/2))
                                  grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2)) 
                          

                          Karina 1 Reply Last reply Reply Quote 0
                          • Karina
                            Karina @cvp last edited by Karina

                            @cvp that correction I can do 😅
                            It was at the beginning before super, but somehow didn’t work. So I put after. And what changes if it’s after super?

                            cvp 1 Reply Last reply Reply Quote 0
                            • Karina
                              Karina last edited by

                              @cvp By the way do you know how to allow multi_touch? This for another thing that is nearly ready

                              cvp mikael 2 Replies Last reply Reply Quote 0
                              • cvp
                                cvp @Karina last edited by

                                @Karina said:

                                And what changes if it’s after super?

                                If you do "after super().init..", you already have passed the path to node creation and all lines are added to the object path but not to the path of the node it-self

                                1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @Karina last edited by cvp

                                  @Karina said:

                                  how to allow multi_touch?

                                  A "must have" of @mikael : gestures

                                  1 Reply Last reply Reply Quote 0
                                  • mikael
                                    mikael @Karina last edited by

                                    @Karina, is this recent thread relevant to your multi-touch question?

                                    Karina 1 Reply Last reply Reply Quote 0
                                    • Karina
                                      Karina @mikael last edited by

                                      @mikael yes, I want to do smth like that. I’ll also look in github, but I didn’t use it before

                                      1 Reply Last reply Reply Quote 0
                                      • Karina
                                        Karina last edited by

                                        @cvp @mikael sorry, I have another problem. I still can’t writing smth by myself🙂

                                        I tried here to add a block on the board, but it doesn’t show it. But prints the position

                                        from scene import *
                                        import random
                                        import arrows
                                        
                                        sw, sh = get_screen_size()
                                        rect_w = sw/3  #343.33
                                        rect_h = sh-100  #668
                                        side = int(rect_w/10)
                                        colors = ['red']
                                        
                                        class Board(ShapeNode):
                                        	def __init__(self, stroke_color='lightgrey', line_width=1, parent=None, *args, **kwargs):
                                        			path = ui.Path.rect(0, 0, rect_w, rect_h)
                                        			path.line_width = line_width
                                        			
                                        			if stroke_color == 'lightgrey':
                                        				d = int(rect_w/10)
                                        				for l in range(int(rect_w/d)):
                                        					x = l*d
                                        					path.move_to(x, 0)
                                        					path.line_to(x, rect_h)
                                        			
                                        			super().__init__(path,
                                        							 fill_color='white',
                                        							 stroke_color=stroke_color,
                                        							 parent=parent,
                                        							 *args, **kwargs)
                                        		
                                        
                                        
                                        class Game(Scene):
                                        	def setup(self):
                                        		self.background_color = 'white'
                                        		grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2), z_position=0)
                                        		self.board = Board(stroke_color='purple', line_width=15, parent=self, position=(sw/3, sh/2), 	z_position=-1)
                                        		self.add_buttons()
                                        		self.add_figure()
                                        		
                                        	def add_buttons(self):
                                        		ars = arrows.Main()
                                        		self.present_modal_scene(ars)
                                        		
                                        	def add_figure(self):
                                        		x = random.choice(range(10)) * side
                                        		y = rect_h
                                        		block = SpriteNode('pzl:Yellow7', (x, y), z_position=1, size=Size(side, side), parent=self.board)
                                        		print(block.position)
                                        
                                        
                                        run(Game())  ```
                                        cvp 2 Replies Last reply Reply Quote 0
                                        • cvp
                                          cvp @Karina last edited by cvp

                                          @Karina try the gray_rect as parent for yours blocks because it is above the board

                                                  self.grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2), z_position=0) 
                                          

                                          and don't forget child position is versus the center of the parent node

                                              def add_figure(self):
                                                  r = random.choice(range(10)) 
                                                  x = r * side - rect_w/2 + side/2
                                                  y = rect_h/2 - side/2
                                                  block = SpriteNode('pzl:Yellow7', position=(x, y), size=Size(side, side), parent=self.grey_rect)
                                                  
                                                  #print(block.position)
                                          

                                          1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @Karina last edited by

                                            @Karina Here, if you let self.board as parent and use r = 10, you can see that your block is partially hidden by the grid

                                                    r = 10
                                                    x = r * side - rect_w/2 + side/2
                                                    y = rect_h/2 - side/2
                                                    block = SpriteNode('pzl:Yellow7', position=(x, y), size=Size(side, side), parent=self.board)#self.grey_rect)
                                            

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors