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
    18049
    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.
    • Karina
      Karina last edited by Karina

      Hello everyone
      I'm new to pythonista and programming, trying to write tetris
      For now i have buttons⬅️⬆️⬇️➡️ and a frame. But yhe frame is to much in the corner and i can't move it
      Here's the code

      import arrows
      from scene import *
      
      colors = ['purple', 'red', 'blue', 'orange', 'yellow', 'green',
      'lightblue']
      sw = get_screen_size()[0]
      sh = get_screen_size()[1]
      
      class Board(ShapeNode):
           def __init__(self, parent=None, *args, **kwargs):
                self.rect_w = sw/2
                self.rect_h = sh-100
                path = ui.Path.rect(0, 0, self.rect_w, self.rect_h)
                path.line_width = 10
                super().__init__(path,
                                 fill_color='white',
                                 stroke_color='purple',
                                 parent=parent,
                                 *args, **kwargs)
      
           def draw_lines(self):
                stroke(0, 0, 0)
                stroke_weight(2)
                line(l*30+50, self.rect_h+50, l*30+50, 50)
      
      class Game(Scene):
           def setup(self):
                self.background_color = 'white'
                Board(parent=self)
                self.add_buttons()
      
           def add_buttons(self):
                ars = arrows.Main()
                self.present_modal_scene(ars)
      
      if __name__ == '__main__':
           run(Game())
      

      In the line path = ui.Path.rect(0, 0, self.rect_w, self.rect_h) if i change first two args from zero, nothing changes. So what they do? And how i can change pos of the frame?

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

        @Karina try this

                  Board(position=(sw/2,sh/2), parent=self) 
        
        Karina 1 Reply Last reply Reply Quote 0
        • Karina
          Karina @cvp last edited by

          @cvp 👍 and what 2 first args do in ui.Path.rect()?
          Thanks for help🤗

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

            @Karina I think that as used here in ShapeNode path, x and y are not used, only width and height. If you draw an ui.path in general, x and y set path position, but not here.

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

              @cvp Thank you now the frame where it needs to be.
              Then I need to draw vertical lines in the frame, but it doesn’t work. And if change z_position - nothing.

              import arrows
              from scene import *
              
              
              colors = ['purple', 'red', 'blue', 'orange', 'yellow', 'green', 'lightblue']
              sw = get_screen_size()[0]
              sh = get_screen_size()[1]
              
              
              class Board(ShapeNode):
              	def __init__(self, parent=None, *args, **kwargs):
              		self.rect_w = sw/2
              		self.rect_h = sh-100
              		path = ui.Path.rect(0, 0, self.rect_w, self.rect_h)
              		path.line_width = 10
              		super().__init__(path, 
              						 z_position=-1,
              						 fill_color='white',
              						 stroke_color='purple',
              						 parent=parent,
              						 *args, **kwargs)
              	
              	
              	
              	def draw_lines(self):
              		fill(0, 0, 0)
              		stroke_weight(2)
              		rect(sw-200, sh/2, 100, 100)
              		for l in range(int(self.rect_w/30)):
              			line_path = ui.Path.rect(sw/3 - self.rect_w/2 + 30*l, sh/2 + self.rect_h/2, 
              									 self.rect_w, self.rect_h)
              			
              		
              			
              
              class Game(Scene):
              	def setup(self):
              		self.background_color = 'white'
              		self.board = Board(position=(sw/3, sh/2), parent=self)
              		self.add_buttons()
              		
              	
              	
              	def draw(self):
              		self.board.draw_lines()
              		
              		
              	def add_buttons(self):
              		ars = arrows.Main()
              		self.present_modal_scene(ars)
              
              
              
              if __name__ == '__main__':	
              	run(Game()) 
              

              But beyond the purple frame I can draw😐

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

                @Karina sincerely, not sure this is what you want. If not, sorry and forget quickly this post

                class Board(ShapeNode):
                    def __init__(self, parent=None, *args, **kwargs):
                        self.rect_w = sw/2
                        self.rect_h = sh-100
                        path = ui.Path.rect(0, 0, self.rect_w, self.rect_h)
                        path.line_width = 2
                        d = int(self.rect_w/30)
                        for l in range(int(self.rect_w/d)):
                            x = l*d
                            path.move_to(x,0)
                            path.line_to(x,self.rect_h) 
                .
                .
                .
                

                Comment temporarily your draw_lines process, to watch the result

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

                  @cvp It’s nearly what I need, I just want it in grey color. But when I put it into the draw_lines and not Board’s init, it doesn’t work. And I don’t want to overload init

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

                    @Karina it does not work because you pass the path to super.init and thus when you draw the lines, the path is already built

                    This is not really an overload

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

                      @Karina please read some @jonB explanations in this topic

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

                        @Karina said:

                        colors = ['purple', 'red', 'blue', 'orange', 'yellow', 'green', 'lightblue']
                        sw = get_screen_size()[0]
                        sh = get_screen_size()[1]

                        colors = ‘purple red blue orange yellow green lightblue'.split()
                        sw, sh = get_screen_size()

                        1 Reply Last reply Reply Quote 1
                        • Mosa14177
                          Mosa14177 last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • Karina
                            Karina last edited by

                            @ccc with sw sh okay, but what this colors = ‘purple red blue orange yellow green lightblue'.split() gives?

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

                              @ccc said:

                              colors = ‘purple red blue orange yellow green lightblue'.split()

                              @Karina Try and print colors, you will see

                              ['purple', 'red', 'blue', 'orange', 'yellow', 'green', 'lightblue'] 
                              

                              Thus what you want 😀

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

                                @Karina, just to be clear, there is nothing wrong with colors = ['purple', 'red', 'blue', 'orange', 'yellow', 'green', 'lightblue'] – for all-string arrays of this size, the str.split() version may just be more convenient to type.

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

                                  @ccc @cvp @mikael I got it with the colors, but to me it’s the same amount of writing
                                  And what means the error ‘ ‘ object has no attr _suspend_updates? When it appears?

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

                                    @Karina said:

                                    same amount of writing

                                    Not really, with @ccc advice, you don't need to type quotes and comma's

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

                                      object has no attr _suspend_updates

                                      https://docs.python.org/3/library/functions.html are cool things to study as you learn Python. One of those is dir(object) which lists all the variables and methods of object. The message above means that dir(object) does not contain _suspend_updates but some code is assuming that it does. Practice a lot with dir(object) because it will help you to anticipate bugs.

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

                                        @Karina, _suspend_updates is new to me, but it sounds like it is a scene-internal attribute. In addition to the detective work with dir as @ccc suggested, it is a good idea to look at/share the full traceback.

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

                                          @ccc @mikael I thought maybe you have met it then I’ll know what to do. And in google I also didn’t found about this error.
                                          And if I see in dir that there is no _suspend_updates how it will help me? I just don’t understand what to do to avoid this bug

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

                                            1. Give us some code that generates this error --and/or--
                                            2. Give us the full multiline error message (stack trace) so we can understand the context of the error.

                                            We do not even know the datatype of object.

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