home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / imagedialog.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  3.2 KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from PIL.Image import BICUBIC, ANTIALIAS
  5. import wx
  6. from gui.toolbox.imagefx import wxb_to_pil_nocache, pil_to_wxb_nocache
  7.  
  8. class ImageDialog(wx.Dialog):
  9.     SuccessID = wx.ID_OK
  10.     
  11.     def __init__(self, parent, screenshot, pos, title, message, oklabel = _('OK'), cancellabel = _('Cancel')):
  12.         wx.Dialog.__init__(self, parent, -1, title)
  13.         self.screenshot = resize_image_for_dialog(screenshot)
  14.         p = self.panel = wx.Panel(self)
  15.         s = self.panel.Sizer = VSizer()
  16.         s.Add((self.screenshot.Width, self.screenshot.Height + 20))
  17.         p.Bind(wx.EVT_PAINT, self.paint)
  18.         s.Add(wx.StaticText(p, -1, message), 0, wx.EXPAND | wx.BOTTOM, 8)
  19.         send = wx.Button(p, self.SuccessID, oklabel)
  20.         send.SetDefault()
  21.         cancel = wx.Button(p, wx.ID_CANCEL, cancellabel)
  22.         h = HSizer()
  23.         h.AddStretchSpacer(1)
  24.         h.AddMany([
  25.             (send, 0, wx.EXPAND | wx.RIGHT, 10),
  26.             (cancel, 0)])
  27.         s.Add(h, 0, wx.EXPAND)
  28.         s = self.Sizer = VSizer()
  29.         s.Add(self.panel, 1, wx.EXPAND | wx.ALL, 8)
  30.         self.Fit()
  31.         self.SetPosition(pos)
  32.  
  33.     
  34.     def paint(self, e):
  35.         dc = wx.PaintDC(e.EventObject)
  36.         r = self.panel.ClientRect
  37.         dc.DrawBitmap(self.screenshot, r.HCenter(self.screenshot), 10, True)
  38.  
  39.  
  40.  
  41. def resize_image_for_dialog(screenshot, maxsize = 650):
  42.     if isinstance(screenshot, wx.Bitmap):
  43.         screenshot = wxb_to_pil_nocache(screenshot)
  44.     
  45.     (w, h) = screenshot.size
  46.     img = screenshot
  47.     if w > maxsize or h > maxsize:
  48.         if w > h:
  49.             new_height = int((h / float(w)) * maxsize)
  50.             img = None(img.resize, (maxsize, new_height) if maxsize > w else ANTIALIAS)
  51.         else:
  52.             new_width = int((w / float(h)) * maxsize)
  53.             img = None(img.resize, (new_width, maxsize) if maxsize > h else ANTIALIAS)
  54.     
  55.     return pil_to_wxb_nocache(img)
  56.  
  57.  
  58. HSizer = lambda : wx.BoxSizer(wx.HORIZONTAL)
  59.  
  60. VSizer = lambda : wx.BoxSizer(wx.VERTICAL)
  61.  
  62. def show_image_dialog(parent, message, bitmap, title = None):
  63.     ImageDialog = ImageDialog
  64.     import gui.imagedialog
  65.     if not title:
  66.         pass
  67.     diag = ImageDialog(parent, bitmap, wx.DefaultPosition, message = message, title = _('Send Image'), oklabel = _('&Send Image'), cancellabel = _("&Don't Send"))
  68.     diag.CenterOnParent()
  69.     
  70.     try:
  71.         return diag.ShowModal() == ImageDialog.SuccessID
  72.     finally:
  73.         if not wx.IsDestroyed(diag):
  74.             diag.Destroy()
  75.         
  76.  
  77.  
  78.