]> git.siccegge.de Git - ghextris.git/commitdiff
replace gtk.{TRUE,FALSE} by python's booleans
authorChristoph Egger <christoph@christoph-egger.org>
Sun, 5 Jul 2015 13:40:59 +0000 (15:40 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Sun, 5 Jul 2015 13:40:59 +0000 (15:40 +0200)
ghextris.py

index 81f3c691d22f755640a4f572838541ecc845bbaa..8b29920504310fc45794d37ab36852c1852e0da7 100755 (executable)
@@ -119,17 +119,17 @@ class Hextris:
         self.speed_orig = 400
         self.speed = 400
         self.speed_ratio = 0.99
-        self.speed_reset = gtk.FALSE
-        self.paused = gtk.FALSE
-        self.lost = gtk.TRUE
+        self.speed_reset = False
+        self.paused = False
+        self.lost = True
         self.score = 0
         self.hiscore = 0
         self.nextnum = 0
 
-        self.running = gtk.FALSE
+        self.running = False
 
-        self.nextpiece = gtk.FALSE
-        self.board = gtk.FALSE
+        self.nextpiece = False
+        self.board = False
         self.rowgroups = []
 
     def draw_hexagon(self, group, color):
@@ -196,12 +196,12 @@ class Hextris:
         self.speed = self.speed_orig
         self.score = 0
         self.attitude = 0
-        self.lost = gtk.FALSE
-        self.paused = gtk.FALSE
+        self.lost = False
+        self.paused = False
 
         self.update_appbar()
 
-        if self.board != gtk.FALSE:
+        if self.board != False:
             self.board.destroy()
         self.board = self.canvas.root().add("GnomeCanvasGroup", x = 0, y = 0)
 
@@ -219,29 +219,29 @@ class Hextris:
         self.nextnum = whrandom.randint(0, 9)
         self.next_piece()
 
-        if self.running == gtk.FALSE:
+        if self.running == False:
             gobject.timeout_add(self.speed, self.timer_handler)
-            self.running = gtk.TRUE
+            self.running = True
         else:
-            self.speed_reset = gtk.TRUE
+            self.speed_reset = True
 
-        return gtk.TRUE
+        return True
 
     def on_about_activate(self, event):
         aTree = gtk.glade.XML(self.glade, "about")
         about = aTree.get_widget("about")
         about.set_property("name", "Ghextris")
         about.set_property("version", VERSION)
-        return gtk.TRUE
+        return True
 
     def on_pause_game_activate(self, event):
-        if self.lost == gtk.TRUE:
-            return gtk.FALSE
-        if self.paused == gtk.TRUE:
-            self.paused = gtk.FALSE
+        if self.lost == True:
+            return False
+        if self.paused == True:
+            self.paused = False
         else:
-            self.paused = gtk.TRUE
-        return gtk.TRUE
+            self.paused = True
+        return True
 
     def on_quit_activate(self, event):
         gtk.main_quit()
@@ -293,7 +293,7 @@ class Hextris:
                                       self.colors[self.piecenum%(len(self.colors)+1)],
                                       self.piece_x, self.piece_y)
 
-        if self.nextpiece != gtk.FALSE:
+        if self.nextpiece != False:
             self.nextpiece.destroy()
         self.nextpiece = self.place_piece(self.preview,
                                           self.pieces[self.nextnum][0],
@@ -302,35 +302,35 @@ class Hextris:
                                           self.deltay[self.nextnum])
 
     def timer_handler(self):
-        if self.lost == gtk.TRUE:
-            self.running = gtk.FALSE
-            return gtk.FALSE
+        if self.lost == True:
+            self.running = False
+            return False
 
-        if self.paused == gtk.TRUE:
-            return gtk.TRUE
+        if self.paused == True:
+            return True
         self.piece_y += 1
         
-        if self.check_collisions() == gtk.TRUE:
+        if self.check_collisions() == True:
             self.piece_y -= 1
             self.update_field()
-            if self.top_occupied() != gtk.TRUE:
+            if self.top_occupied() != True:
                 self.next_piece()
             else:
-                self.lost = gtk.TRUE
+                self.lost = True
                 if self.hiscore < self.score:
                     self.hiscore = self.score
                 self.update_appbar()
-                self.running  = gtk.FALSE
-                return gtk.FALSE
+                self.running  = False
+                return False
         else:
             self.piece.move(0, self.pieceheight)
 
-        if self.speed_reset == gtk.TRUE:
-            self.speed_reset = gtk.FALSE
+        if self.speed_reset == True:
+            self.speed_reset = False
             gobject.timeout_add(int(self.speed), self.timer_handler)
-            return gtk.FALSE
+            return False
 
-        return gtk.TRUE
+        return True
 
     def update_appbar(self):
         self.appbar.set_text("%s: %d  |  %s: %d" % (_("Score"), self.score,
@@ -338,18 +338,18 @@ class Hextris:
                                                     self.hiscore))
 
     def key_handler(self, widget, event=None):
-        if self.lost == gtk.TRUE:
-            return gtk.FALSE
+        if self.lost == True:
+            return False
 
-        if event.keyval == gtk.keysyms.p and self.lost == gtk.FALSE:
-            if self.paused == gtk.TRUE:
-                self.paused = gtk.FALSE
+        if event.keyval == gtk.keysyms.p and self.lost == False:
+            if self.paused == True:
+                self.paused = False
             else:
-                self.paused = gtk.TRUE
-            return gtk.TRUE
+                self.paused = True
+            return True
 
-        if self.paused == gtk.TRUE:
-            return gtk.FALSE
+        if self.paused == True:
+            return False
 
         if event.keyval == gtk.keysyms.Up or event.keyval == gtk.keysyms.Down:
             if event.keyval == gtk.keysyms.Up:
@@ -360,16 +360,16 @@ class Hextris:
             self.attitude = ((self.attitude + attitude_change +
                               len(self.pieces[self.piecenum])) %
                              len(self.pieces[self.piecenum]))
-            if self.check_collisions() == gtk.TRUE:
+            if self.check_collisions() == True:
                 self.attitude = old_attitude
-                return gtk.TRUE
+                return True
             
             self.piece.destroy()
             self.piece = self.place_piece(self.board,
                                           self.pieces[self.piecenum][self.attitude],
                                           self.colors[self.piecenum%(len(self.colors)+1)],
                                           self.piece_x, self.piece_y);
-            return gtk.TRUE
+            return True
 
         if event.keyval == gtk.keysyms.Left or event.keyval == gtk.keysyms.Right:
             if event.keyval == gtk.keysyms.Left:
@@ -384,23 +384,23 @@ class Hextris:
             else:
                 deltay -= self.pieceheight/2
 
-            if self.check_collisions() == gtk.TRUE:
+            if self.check_collisions() == True:
                 if deltay > 0:
                     self.piece_x -= deltax
-                    return gtk.TRUE
+                    return True
                 self.piece_y += 1
                 deltay += self.pieceheight
-                if self.check_collisions() == gtk.TRUE:
+                if self.check_collisions() == True:
                     self.piece_x -= deltax
                     self.piece_y -= 1
-                    return gtk.TRUE
+                    return True
 
             self.piece.move(deltax*(self.piecewidth+self.piecenarrow)/2, deltay)
-            return gtk.TRUE
+            return True
 
         if event.keyval == gtk.keysyms.space:
             orig_piece_y = self.piece_y
-            while self.check_collisions() == gtk.FALSE:
+            while self.check_collisions() == False:
                 self.piece_y += 1
             self.piece_y -= 1
             self.piece.move(0, self.pieceheight*(self.piece_y - orig_piece_y))
@@ -408,17 +408,17 @@ class Hextris:
             if self.score > self.hiscore:
                 self.hiscore = self.score
             self.update_field()
-            if self.top_occupied() != gtk.TRUE:
+            if self.top_occupied() != True:
                 self.next_piece()
             else:
-                self.lost = gtk.TRUE
+                self.lost = True
                 if self.hiscore < self.score:
                     self.hiscore = self.score
                 self.update_appbar()
 
-            return gtk.TRUE
+            return True
 
-        return gtk.FALSE
+        return False
 
     def check_collisions(self):
         for i in range(len(self.pieces[self.piecenum][self.attitude])):
@@ -429,12 +429,12 @@ class Hextris:
                     else:
                         deltay = 0
                     if j + self.piece_x < 0 or j + self.piece_x >= self.cols:
-                        return gtk.TRUE
+                        return True
                     if ((i + self.piece_y + deltay > 0) and
                         (i + self.piece_y + deltay >= self.rows or
                          self.field[i + self.piece_y + deltay][j + self.piece_x] != 0)):
-                        return gtk.TRUE
-        return gtk.FALSE
+                        return True
+        return False
 
     def update_field(self):
         for i in range(len(self.pieces[self.piecenum][self.attitude])):
@@ -456,16 +456,16 @@ class Hextris:
     def collapse_rows(self):
         row_points = 50
         for i in range(self.rows):
-            row_full = gtk.TRUE
+            row_full = True
             for j in range(self.cols):
                 if self.field[i][j] == 0:
-                    row_full = gtk.FALSE
+                    row_full = False
                     break
 
-            if row_full == gtk.TRUE:
+            if row_full == True:
                 row_points *= 2
                 self.speed *= self.speed_ratio
-                self.speed_reset = gtk.TRUE
+                self.speed_reset = True
                 self.rowgroups[i].destroy()
                 for j in range(i-1, -1, -1):
                     self.rowgroups[j].move(0, self.pieceheight)
@@ -485,8 +485,8 @@ class Hextris:
     def top_occupied(self):
         for i in range(self.cols):
             if self.field[0][i] != 0:
-                return gtk.TRUE
-        return gtk.FALSE
+                return True
+        return False
 
 if __name__ == '__main__':
     h = Hextris()