daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Apr 15th, 2019 68 in 20 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Extra code to simplify test code
  2. #=================================
  3. class pygame:
  4.     class Rect:
  5.         def __init__(self, x, y, w, h):
  6.             self.x = x
  7.             self.y = y
  8.             self.w = w
  9.             self.h = h
  10.  
  11.  
  12. # Classes
  13. #========
  14. class GfxObject(object):
  15.     """
  16.    Generic Graphical Object which is the parent class of all the sub-classes below.
  17.    """
  18.     def __init__(self):
  19.         self.i_x = 0
  20.         self.i_y = 0
  21.         self.s_grab = 'nw'
  22.  
  23.  
  24. class GfxRect(GfxObject):
  25.     """
  26.    Class to draw a rectangle.
  27.    """
  28.     def __init__(self):
  29.         print '--- START GfxObject initialisation'
  30.         super(GfxRect, self).__init__()
  31.         print '+++ END GfxObject initialisation'
  32.  
  33.         self._i_x = 0
  34.         self._s_grab = 'nw'
  35.         self._o_rect = None
  36.  
  37.         print self
  38.  
  39.         self._update_rect()
  40.  
  41.     def __str__(self):
  42.         return unicode(self).encode('utf8')
  43.  
  44.     def __unicode__(self):
  45.         u_out = u'<GfxRect>\n'
  46.         u_out += u'  .i_x:     %s\n' % self.i_x
  47.         u_out += u'  ._i_x:    %s\n' % self._i_x
  48.         u_out += u'  .s_grab:  %s\n' % self.s_grab
  49.         u_out += u'  ._s_grab: %s\n' % self._s_grab
  50.         return u_out
  51.  
  52.     def _get_grab(self):
  53.         return self._s_grab
  54.  
  55.     def _get_x(self):
  56.         return self._i_x
  57.  
  58.     def _set_grab(self, ps_value):
  59.         self._s_grab = ps_value
  60.         #self._update_rect()
  61.         self._b_redraw = True
  62.  
  63.     def _set_x(self, i_value):
  64.         self._i_x = i_value
  65.         self._update_rect()
  66.         self._b_redraw = True
  67.  
  68.     def _update_rect(self):
  69.         """
  70.        Method to update the pygame rectangle object.
  71.        :return:
  72.        """
  73.  
  74.         # [1/?] Calculating the deltas for (x,y) based on the grab position
  75.         #------------------------------------------------------------------
  76.         if self._s_grab == 'nw':
  77.             i_dx = 0
  78.         elif self._s_grab == 'n':
  79.             i_dx = -800 / 2
  80.         else:
  81.             raise ValueError('Invalid grab value "%s"' % self._s_grab)
  82.  
  83.         # [2/?] Applying the deltas
  84.         #--------------------------
  85.         i_x = self._i_x + i_dx
  86.  
  87.         self._o_rect = pygame.Rect(i_x, 0, 800, 600)
  88.  
  89.     i_x = property(fget=_get_x, fset=_set_x)
  90.     s_grab = property(fget=_get_grab, fset=_set_grab)
  91.  
  92.  
  93. # Main code
  94. #==========
  95. if __name__ == '__main__':
  96.     o_progbar = GfxRect()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top