home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / bugreporter / bugreportergui.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  12.5 KB  |  273 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, 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 cgui import getScreenBitmap, GetTrayRect
  10. from gui import skin
  11. from gui.toolbox import Monitor
  12. from PIL import Image, ImageDraw
  13. from cStringIO import StringIO
  14. from gui.imagedialog import ImageDialog
  15. import wx.lib.sized_controls as sc
  16. SCREENSHOT_TIMER_SECS = 4
  17.  
  18. class BugReportPanel(sc.SizedPanel):
  19.     
  20.     def __init__(self, parent, callback = None):
  21.         sc.SizedPanel.__init__(self, parent)
  22.         self.screenshot = None
  23.         self.construct()
  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,the content of emails, and the content of social network newsfeeds except where it directly pertains to an error.'), style = ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
  65.         self.subheader.SetSizerProps(expand = True)
  66.         self.line = StaticLine(self)
  67.         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.'))
  68.         self.input_desc.SetSizerProps(expand = True)
  69.         self.input = TextCtrl(self, -1, size = (400, 200), style = wx.TE_MULTILINE)
  70.         self.input.SetSizerProps(expand = True, proportion = 1)
  71.         radioPanel = sc.SizedPanel(self, -1)
  72.         radioPanel.SetSizerType('horizontal')
  73.         self.reproduce_text = wx.StaticText(radioPanel, -1, _('Can you consistently reproduce this bug?'))
  74.         self.radios = S(yes = RadioButton(radioPanel, -1, _('&Yes'), style = wx.RB_GROUP), no = RadioButton(radioPanel, -1, _('&No')), unknown = RadioButton(radioPanel, -1, _("&Don't Know")))
  75.         self.radios.yes.SetValue(True)
  76.         self.screenshot_text = BoldText(_('If this is a visual bug, please attach a screenshot to this report.'))
  77.         self.screenshot_link = wx.HyperlinkCtrl(self, -1, _('Take Screenshot'), '#')
  78.         self.screenshot_link.Bind(wx.EVT_HYPERLINK, self.OnScreenshot)
  79.         
  80.         set = lambda l: (self.screenshot_link.SetLabel(l), self.Layout(), self.screenshot_link.Refresh())
  81.         self.screenshot_timer = ScreenshotTimer((SCREENSHOT_TIMER_SECS,), (lambda t: set(_('Taking Screenshot in ') + str(t))), self.OnScreenshotTimer)
  82.         self.Bind(wx.EVT_SIZE, self.OnSize)
  83.  
  84.     
  85.     def OnSize(self, event):
  86.         self.subheader.SetLabel(_('This diagnostic log file does not contain personal data such as the content of sent/received IMs, the content of emails, and the content of social network newsfeeds except where it directly pertains to an error.'))
  87.         self.subheader.Wrap(event.Size.width)
  88.         self.input_desc.SetLabel(_('Please describe the bug in as much detail as possible. Include information such as what you were doing when the bug occured and exactly what goes wrong.'))
  89.         self.input_desc.Wrap(event.Size.width)
  90.         event.Skip()
  91.  
  92.     
  93.     def OnScreenshot(self, e):
  94.         if self.screenshot_timer.IsRunning() or self.screenshot is not None:
  95.             self.screenshot = None
  96.             self.screenshot_timer.Stop()
  97.             self.screenshot_link.Label = _('Take Screenshot')
  98.             return None
  99.         else:
  100.             self.screenshot_timer.Start()
  101.  
  102.     
  103.     def OnScreenshotTimer(self):
  104.         oldpos = self.Parent.ScreenPosition
  105.         
  106.         try:
  107.             top = self.Top
  108.             top.Move((-(top.Size.width) - 50, -(top.Size.height) - 50))
  109.             wx.BeginBusyCursor()
  110.             wx.WakeUpIdle()
  111.             wx.MilliSleep(500)
  112.             screen = app_windows_image()
  113.             diag = ImageDialog(self, screen, pos = oldpos + Point(40, 40), title = _('Submit Bug Report - Screenshot - Digsby'), message = _('Is it OK to send this screenshot to digsby.com?'))
  114.             diag.SetFrameIcon(skin.get('appdefaults.taskbaricon'))
  115.         except Exception:
  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 = screen
  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(sc.SizedDialog):
  195.     
  196.     def __init__(self, parent, callback = None):
  197.         sc.SizedDialog.__init__(self, parent, -1, _('Submit Bug Report - Digsby'), size = (590, 600), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
  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.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL))
  204.         button = self.FindWindowById(wx.ID_OK)
  205.         if button:
  206.             button.SetLabel(_('Submit'))
  207.         
  208.  
  209.  
  210.  
  211. class ScreenshotTimer(wx.Timer):
  212.     
  213.     def __init__(self, secs, on_tick, on_done):
  214.         wx.Timer.__init__(self)
  215.         self.secs = secs
  216.         self.tick = on_tick
  217.         self.done = on_done
  218.  
  219.     
  220.     def Start(self):
  221.         self.count = self.secs
  222.         wx.Timer.Start(self, 1000, False)
  223.         self.tick(self.count)
  224.  
  225.     
  226.     def Notify(self):
  227.         self.count -= 1
  228.         self.tick(self.count)
  229.  
  230.  
  231.  
  232. HSizer = lambda : BoxSizer(HORIZONTAL)
  233.  
  234. VSizer = lambda : BoxSizer(VERTICAL)
  235. import gui.wxextensions as gui
  236.  
  237. def app_windows_image():
  238.     rect = reduce(wx.Rect.Union, (lambda .0: for m in .0:
  239. m.Geometry)(Monitor.All()))
  240.     if 'wxMSW' in wx.PlatformInfo:
  241.         screen = getScreenBitmap(rect).PIL
  242.     else:
  243.         screen = wx.ScreenDC().GetAsBitmap().PIL
  244.     mask = Image.new('RGBA', rect.Size, (255, 255, 255, 255))
  245.     
  246.     drawrect = lambda r: ImageDraw.Draw(mask).rectangle([
  247. r.x,
  248. r.y,
  249. r.Right,
  250. r.Bottom], fill = (0, 0, 0, 0))
  251.     for w in wx.GetTopLevelWindows():
  252.         if w.IsShown():
  253.             continue
  254.         _[1][w.Rect]
  255.     
  256.     screen.paste(mask, (0, 0), mask)
  257.     return screen
  258.  
  259. if __name__ == '__main__':
  260.     import gettext
  261.     gettext.install('Digsby')
  262.     from tests.testapp import testapp
  263.     a = testapp()
  264.     f = wx.Frame(None, pos = (50, 50))
  265.     f.Show()
  266.     f = wx.Frame(None, pos = (10050, 80))
  267.     f.Show()
  268.     f = wx.Frame(None, pos = (400, 300))
  269.     f.Show()
  270.     print show_dialog()
  271.     a.MainLoop()
  272.  
  273.