def unshorten_click (self, evt): logging.debug("URL Unshorten button activated.") urls = self.GetURLList() if not urls: logging.debug("No URLs found in tweet. Nothing to unshorten.") dlg_title = _('URL Unshortener - No URLs') dlg_text = _('No URLs were found to unshorten. If there is one, select the URL and click this button again.') dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() # Set focus to the edit field by default self.message.SetFocus() #Deselect any current text. self.message.SetSelection(len(self.message.GetValue()),len(self.message.GetValue())) return 0 logging.debug("Found at least 1 URL. Showing selection dialog.") if len(urls) == 1: url=urls[0] else: # Adapted from interface.py. dlg_title = _('URL Unshortener - Select URL') dlg_text = _('Select URL to unshorten.') dlg = wx.SingleChoiceDialog(None, dlg_title, dlg_text, urls, wx.CHOICEDLG_STYLE) dlg.Raise() if dlg.ShowModal() == wx.ID_OK: url = dlg.GetStringSelection() logging.debug("User selected URL to unshorten: %s" % (url)) clean = misc.url_cleanup(url) logging.debug("Clean URL (what will be replaced) is: %s" % (clean)) surl = clean # URL to unshorten if "://" not in surl: surl = "http://" + surl logging.debug("URL being unshortened: %s" % (surl)) try: unshortened = url_shortener.unshorten(surl) except: logging.exception("Error in unshortening URL: %s" % surl) unshortened = None if unshortened: logging.debug("Started with %s, will replace %s, unshortening %s, unshortened as %s" % (url, clean, surl, unshortened)) self.message.SetValue(self.message.GetValue().replace(clean, unshortened)) output.speak(_("URL expanded."), True) else: logging.debug("Unshorten failed: started with %s, will replace %s, tried unshortening %s" % (url, clean, surl)) dlg_title = _('URL Unshortener - Problem') dlg_text = _('There was a problem unshortening the selected URL.') dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() #Set focus to the edit field by default self.message.SetFocus() #Deselect any current text. self.message.SetSelection(self.getMessageLength(), self.getMessageLength())
def shorten_click(self, evt): logging.debug("URL Shorten button activated.") urls = self.GetURLList() if not urls: logging.debug("No URLs found in tweet. Nothing to shorten.") dlg_title = _('URL Shortener - No URLs') dlg_text = _( 'No URLs were found to shorten. If there is one, select the URL and click this button again.' ) dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() # Set focus to the edit field by default self.message.SetFocus() #Deselect any current text. self.message.SetSelection(len(self.message.GetValue()), len(self.message.GetValue())) return 0 logging.debug("Found at least 1 URL. Showing selection dialog.") if len(urls) == 1: url = urls[0] else: # Adapted from interface.py. dlg_title = _('URL Shortener - Select URL') dlg_text = _('Select URL to shorten.') dlg = wx.SingleChoiceDialog(None, dlg_title, dlg_text, urls, wx.CHOICEDLG_STYLE) dlg.Raise() if dlg.ShowModal() == wx.ID_OK: url = dlg.GetStringSelection() logging.debug("User selected URL to shorten: %s" % (url)) clean = misc.url_cleanup(url) logging.debug("Clean URL (what will be replaced) is: %s" % (clean)) surl = clean # URL to shorten if "://" not in surl: surl = "http://" + surl logging.debug("URL sent to shortener: %s" % (surl)) short = url_shortener.shorten( surl, service=config.main['shortener']['urlShortener']) if short: logging.debug( "Started with %s, will replace %s, shortening %s, shortened as %s" % (url, clean, surl, short)) self.message.SetValue(self.message.GetValue().replace( clean, short)) output.speak(_("URL Shortened."), True) else: logging.debug( "Shorten failed: started with %s, will replace %s, tried shortening %s" % (url, clean, surl)) dlg_title = _('URL Shortener - Problem') dlg_text = _('There was a problem shortening the selected URL.') dlg = wx.MessageDialog(self, dlg_text, dlg_title, wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() #Set focus to the edit field by default self.message.SetFocus() #Deselect any current text. self.message.SetSelection(len(self.message.GetValue()), len(self.message.GetValue()))