code: def img2code(self, key, img):
          
  
          code_template = \
              "wx.ImageFromData({width}, {height}, " + \
              "bz2.decompress(base64.b64decode('{data}'))).ConvertToBitmap()"
  
          code_alpha_template = \
              "wx.ImageFromDataWithAlpha({width}, {height}, " + \
              "bz2.decompress(base64.b64decode('{data}')), " + \
              "bz2.decompress(base64.b64decode('{alpha}'))).ConvertToBitmap()"
  
          data = base64.b64encode(bz2.compress(img.GetData(), 9))
  
          if img.HasAlpha():
              alpha = base64.b64encode(bz2.compress(img.GetAlphaData(), 9))
              code_str = code_alpha_template.format(
                  width=img.GetWidth(), height=img.GetHeight(),
                  data=data, alpha=alpha)
          else:
              code_str = code_template.format(width=img.GetWidth(),
                                              height=img.GetHeight(), data=data)
  
          return code_str
docs: Pastes wx.Image into single cell