home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / bugreporter / bugreporterguiold.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  14.3 KB  |  339 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. from wx import TextCtrl, StaticText, ALIGN_CENTER, RadioButton, BoxSizer, HORIZONTAL, VERTICAL, StaticLine, EXPAND, Button, ALL, TOP, BOTTOM, LEFT, RIGHT, Point
  6. import wx
  7. from util import Storage as S, callsback, traceguard
  8. from traceback import print_exc
  9. from cgui import getScreenBitmap, GetTrayRect
  10. from gui import skin
  11. from gui.toolbox import Monitor
  12. from PIL import Image, ImageDraw
  13. from PIL.Image import BICUBIC, ANTIALIAS
  14. from cStringIO import StringIO
  15. SCREENSHOT_TIMER_SECS = 4
  16.  
  17. class BugReportPanel(wx.Panel):
  18.     
  19.     def __init__(self, parent, callback = None):
  20.         wx.Panel.__init__(self, parent)
  21.         self.screenshot = None
  22.         self.construct()
  23.         self.layout()
  24.         self.callback = callback
  25.         if callback is not None:
  26.             self.Bind(wx.EVT_BUTTON, self.OnButton)
  27.         
  28.  
  29.     
  30.     def OnButton(self, e):
  31.         e.Skip()
  32.         b = e.EventObject
  33.         if b is self.submit:
  34.             pass
  35.         submit = self.callback is not None
  36.         if submit and not (self.input.Value):
  37.             e.Skip(False)
  38.             wx.MessageBox(_('Please enter a description of the bug.\n\nInclude as much information as possible about\nwhat went wrong and how to reproduce the issue.'), _('Send Bug Report'))
  39.             return None
  40.         
  41.         
  42.         def after():
  43.             
  44.             try:
  45.                 if submit:
  46.                     self.callback(self.info())
  47.             finally:
  48.                 self.Destroy()
  49.  
  50.  
  51.         wx.CallAfter(after)
  52.  
  53.     
  54.     def construct(self):
  55.         
  56.         Text = lambda *a, **k: StaticText(self, -1, *a, **k)
  57.         
  58.         def BoldText(*a, **k):
  59.             t = Text(*a, **k)
  60.             t.SetBold()
  61.             return t
  62.  
  63.         self.header = BoldText(_('Use this tool to submit a diagnostic log right after you experience a bug'), style = ALIGN_CENTER)
  64.         self.subheader = Text(_('This diagnostic log file does not contain personal data such as the content of sent/received IMs,\nthe content of emails, and the content of social network newsfeeds except where it directly pertains to an error.'), style = ALIGN_CENTER)
  65.         self.line = StaticLine(self)
  66.         self.input_desc = BoldText(_('Please describe the bug in as much detail as possible.  Include information such as\nwhat you were doing when the bug occurred and exactly what goes wrong.'))
  67.         self.input = TextCtrl(self, -1, size = (400, 200), style = wx.TE_MULTILINE)
  68.         self.reproduce_text = Text(_('Can you consistently reproduce this bug?'))
  69.         self.radios = S(yes = RadioButton(self, -1, _('&Yes'), style = wx.RB_GROUP), no = RadioButton(self, -1, _('&No')), unknown = RadioButton(self, -1, _("&Don't Know")))
  70.         self.radios.unknown.SetValue(True)
  71.         self.screenshot_text = BoldText(_('If this is a visual bug, please attach a screenshot to this report.'))
  72.         self.screenshot_link = wx.HyperlinkCtrl(self, -1, _('Take Screenshot'), '#')
  73.         self.screenshot_link.Bind(wx.EVT_HYPERLINK, self.OnScreenshot)
  74.         self.screenshot_timer = ScreenshotTimer((SCREENSHOT_TIMER_SECS,), (lambda t: self.OnScreenshotLinkTimer(_('Taking Screenshot in ') + str(t))), self.OnScreenshotTimer)
  75.         self.submit = Button(self, wx.ID_OK, _('&Submit'))
  76.         self.submit.SetDefault()
  77.         self.cancel = Button(self, wx.ID_CANCEL, _('&Cancel'))
  78.  
  79.     
  80.     def OnScreenshotLinkTimer(self, l):
  81.         if wx.IsDestroyed(self):
  82.             self.screenshot_timer.Stop()
  83.             return None
  84.         
  85.         self.SetScreenshotLabel(l)
  86.  
  87.     
  88.     def SetScreenshotLabel(self, l):
  89.         self.screenshot_link.SetLabel(l)
  90.         self.Layout()
  91.         self.screenshot_link.Refresh()
  92.  
  93.     
  94.     def OnScreenshot(self, e):
  95.         if self.screenshot_timer.IsRunning() or self.screenshot is not None:
  96.             self.screenshot = None
  97.             self.screenshot_timer.Stop()
  98.             self.screenshot_link.Label = _('Take Screenshot')
  99.             return None
  100.         else:
  101.             self.screenshot_timer.Start()
  102.  
  103.     
  104.     def OnScreenshotTimer(self):
  105.         oldpos = self.Parent.Position
  106.         
  107.         try:
  108.             top = self.Top
  109.             top.Move((-(top.Size.width) - 50, -(top.Size.height) - 50))
  110.             wx.BeginBusyCursor()
  111.             wx.WakeUpIdle()
  112.             wx.MilliSleep(500)
  113.             (screen_full, screen) = app_windows_image()
  114.             diag = ScreenshotDialog(self, screen_full, screen, pos = oldpos + Point(40, 40))
  115.         except:
  116.             print_exc()
  117.             screen = None
  118.         finally:
  119.             wx.EndBusyCursor()
  120.             self.Top.Move(oldpos)
  121.  
  122.         if screen is None:
  123.             return None
  124.         
  125.         
  126.         try:
  127.             if diag.ShowModal() == wx.ID_OK:
  128.                 self.screenshot = diag.SelectedScreenshot
  129.                 self.screenshot_link.Label = _('Remove Screenshot')
  130.             else:
  131.                 self.screenshot_link.Label = _('Take Screenshot')
  132.         finally:
  133.             diag.Destroy()
  134.  
  135.         self.Layout()
  136.         self.Refresh()
  137.  
  138.     
  139.     def reproduce(self):
  140.         for name, radio in self.radios.iteritems():
  141.             if radio.Value:
  142.                 return name
  143.                 continue
  144.         
  145.  
  146.     reproduce = property(reproduce)
  147.     
  148.     def info(self):
  149.         shot = self.screenshot
  150.         if shot is not None:
  151.             f = StringIO()
  152.             shot.save(f, 'PNG')
  153.             shot = f.getvalue()
  154.         
  155.         return S(description = self.input.Value, reproducible = self.reproduce, screenshot = shot)
  156.  
  157.     
  158.     def layout(self):
  159.         reproduce_sizer = HSizer()
  160.         reproduce_sizer.AddMany([
  161.             (self.reproduce_text, 0),
  162.             (self.radios.yes, 1, LEFT, 20),
  163.             (self.radios.no, 1, LEFT, 20),
  164.             (self.radios.unknown, 1, LEFT, 20)])
  165.         visual_sizer = HSizer()
  166.         visual_sizer.AddMany([
  167.             (self.screenshot_text, 0, RIGHT, 15),
  168.             (self.screenshot_link, 0)])
  169.         button_sizer = HSizer()
  170.         button_sizer.AddStretchSpacer(1)
  171.         button_sizer.AddMany([
  172.             (self.submit, 0, EXPAND | RIGHT, 10),
  173.             (self.cancel, 0)])
  174.         self.Sizer = v = VSizer()
  175.         v.AddMany([
  176.             (self.header, 0, EXPAND | BOTTOM, 6),
  177.             (self.subheader, 0, EXPAND | BOTTOM, 6),
  178.             (self.line, 0, EXPAND | BOTTOM, 6),
  179.             (self.input_desc, 0, EXPAND | BOTTOM, 6),
  180.             (self.input, 1, EXPAND | BOTTOM, 6),
  181.             (reproduce_sizer, 0, EXPAND | BOTTOM, 6),
  182.             (visual_sizer, 0, EXPAND | BOTTOM, 10),
  183.             (button_sizer, 0, EXPAND)])
  184.  
  185.  
  186.  
  187. def show_dialog(callback = None):
  188.     diag = BugReportDialog(None, callback = callback)
  189.     diag.CenterOnScreen()
  190.     diag.Show()
  191.  
  192. show_dialog = callsback(show_dialog)
  193.  
  194. class BugReportDialog(wx.Dialog):
  195.     
  196.     def __init__(self, parent, callback = None):
  197.         wx.Dialog.__init__(self, parent, -1, _('Submit Bug Report - Digsby'))
  198.         self.SetFrameIcon(skin.get('appdefaults.taskbaricon'))
  199.         self.panel = BugReportPanel(self, callback)
  200.         self.info = self.panel.info
  201.         s = self.Sizer = VSizer()
  202.         s.Add(self.panel, 1, EXPAND | ALL, 8)
  203.         self.Fit()
  204.  
  205.  
  206.  
  207. def resize_screenshot(img):
  208.     (w, h) = img.size
  209.     squaresize = 650
  210.     if w > h:
  211.         new_height = int((h / float(w)) * squaresize)
  212.         img = None(img.resize, (squaresize, new_height) if squaresize > w else ANTIALIAS)
  213.     else:
  214.         new_width = int((w / float(h)) * squaresize)
  215.         img = None(img.resize, (new_width, squaresize) if squaresize > h else ANTIALIAS)
  216.     return img
  217.  
  218.  
  219. class ScreenshotDialog(wx.Dialog):
  220.     
  221.     def __init__(self, parent, screenshot_full, screenshot, pos):
  222.         wx.Dialog.__init__(self, parent, -1, _('Submit Bug Report - Screenshot - Digsby'))
  223.         self.SetFrameIcon(skin.get('appdefaults.taskbaricon'))
  224.         self.big_screenshot_digsby = screenshot
  225.         self.screenshot_digsby = resize_screenshot(screenshot).WXB
  226.         self.big_screenshot_full = screenshot_full
  227.         self.screenshot_full = resize_screenshot(screenshot_full).WXB
  228.         self.screenshot = self.screenshot_digsby
  229.         self.hide_non_digsby = True
  230.         p = self.panel = wx.Panel(self)
  231.         s = self.panel.Sizer = VSizer()
  232.         s.Add((self.screenshot_full.Width, self.screenshot_full.Height + 20))
  233.         p.Bind(wx.EVT_PAINT, self.paint)
  234.         hz = wx.BoxSizer(wx.HORIZONTAL)
  235.         checkbox = wx.CheckBox(p, -1, _('Blank out non Digsby windows'))
  236.         checkbox.SetValue(True)
  237.         checkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckFullScreenShot)
  238.         hz.Add(checkbox, 0, EXPAND)
  239.         hz.AddStretchSpacer(1)
  240.         hz.Add(StaticText(p, -1, _('Is it OK to send this screenshot to digsby.com?')), 0, EXPAND)
  241.         s.Add(hz, 0, wx.BOTTOM | EXPAND, 7)
  242.         send = Button(p, wx.ID_OK, _('OK'))
  243.         send.SetDefault()
  244.         cancel = Button(p, wx.ID_CANCEL, _('Cancel'))
  245.         h = HSizer()
  246.         h.AddStretchSpacer(1)
  247.         h.AddMany([
  248.             (send, 0, EXPAND | RIGHT, 10),
  249.             (cancel, 0)])
  250.         s.Add(h, 0, EXPAND)
  251.         s = self.Sizer = VSizer()
  252.         s.Add(self.panel, 1, EXPAND | ALL, 8)
  253.         self.Fit()
  254.         self.SetPosition(pos)
  255.  
  256.     
  257.     def SelectedScreenshot(self):
  258.         if self.hide_non_digsby:
  259.             return self.big_screenshot_digsby
  260.         else:
  261.             return self.big_screenshot_full
  262.  
  263.     SelectedScreenshot = property(SelectedScreenshot)
  264.     
  265.     def OnCheckFullScreenShot(self, e):
  266.         self.hide_non_digsby = e.IsChecked()
  267.         self.Refresh()
  268.  
  269.     
  270.     def paint(self, e):
  271.         dc = wx.PaintDC(e.EventObject)
  272.         screenshot = None if self.hide_non_digsby else self.screenshot_full
  273.         dc.DrawBitmap(screenshot, 10, 10, True)
  274.  
  275.  
  276.  
  277. class ScreenshotTimer(wx.Timer):
  278.     
  279.     def __init__(self, secs, on_tick, on_done):
  280.         wx.Timer.__init__(self)
  281.         self.secs = secs
  282.         self.tick = on_tick
  283.         self.done = on_done
  284.  
  285.     
  286.     def Start(self):
  287.         self.count = self.secs
  288.         wx.Timer.Start(self, 1000, False)
  289.         self.tick(self.count)
  290.  
  291.     
  292.     def Notify(self):
  293.         self.count -= 1
  294.         self.tick(self.count)
  295.  
  296.  
  297.  
  298. HSizer = lambda : BoxSizer(HORIZONTAL)
  299.  
  300. VSizer = lambda : BoxSizer(VERTICAL)
  301. import gui.wxextensions as gui
  302.  
  303. def app_windows_image():
  304.     rect = reduce(wx.Rect.Union, (lambda .0: for m in .0:
  305. m.Geometry)(Monitor.All()))
  306.     if 'wxMSW' in wx.PlatformInfo:
  307.         screen = getScreenBitmap(rect).PIL
  308.     else:
  309.         screen = wx.ScreenDC().GetAsBitmap().PIL
  310.     mask = Image.new('RGBA', rect.Size, (255, 255, 255, 255))
  311.     
  312.     drawrect = lambda r: ImageDraw.Draw(mask).rectangle([
  313. r.x,
  314. r.y,
  315. r.Right,
  316. r.Bottom], fill = (0, 0, 0, 0))
  317.     for w in wx.GetTopLevelWindows():
  318.         if w.IsShown():
  319.             continue
  320.         _[1][w.Rect]
  321.     
  322.     screen_full = screen.copy()
  323.     screen.paste(mask, (0, 0), mask)
  324.     return (screen_full, screen)
  325.  
  326. if __name__ == '__main__':
  327.     import gettext
  328.     gettext.install('Digsby')
  329.     from tests.testapp import testapp
  330.     a = testapp('../../..')
  331.     f = wx.Frame(None, pos = (50, 50))
  332.     f.Show()
  333.     f = wx.Frame(None, pos = (10050, 80))
  334.     f.Show()
  335.     f = wx.Frame(None, pos = (400, 300))
  336.     f.Show()
  337.     print show_dialog()
  338.  
  339.