home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / gui / bugreporter / bugreporterguiold.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  14.8 KB  |  349 lines

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