示例#1
0
 def __init__(self):
     self.connected_accounts = []
     self.account_manager = S(connected_accounts = self.connected_accounts)
示例#2
0
def main():
    def on_close(e):
        twitter.disconnect()

        import AsyncoreThread
        AsyncoreThread.join()

        f.Destroy()

    def droptables():
        if wx.YES == wx.MessageBox(
                'Are you sure you want to drop all tables?',
                style = wx.YES_NO, parent = f):
            twitter.clear_cache()

    def build_test_frame():
        f = wx.Frame(None, title='Twitter Test')
        f.SetSize((500, 700))
        f.Bind(wx.EVT_CLOSE, on_close)

        buttons = []
        def button(title, callback):
            b = wx.Button(f, -1, title)
            b.Bind(wx.EVT_BUTTON, lambda e: callback())
            buttons.append(b)

        def infobox():
            from gui.toolbox import Monitor
            from gui.infobox.infobox import DEFAULT_INFOBOX_WIDTH
            from gui.infobox.infoboxapp import init_host, set_hosted_content

            f = wx.Frame(None)
            size = (DEFAULT_INFOBOX_WIDTH, Monitor.GetFromWindow(f).ClientArea.height * .75)
            f.SetClientSize(size)

            w = wx.webview.WebView(f)

            init_host(w)
            set_hosted_content(w, MockTwitterAccount(twitter))
            f.Show()

        def popup():
            twitter.webkitcontroller.evaljs('account.showTimelinePopup();')

        def fake_tweets():
            j('fakeTweets(%d);' % int(fake_tweets_txt.Value))
            twitter.webkitcontroller.webview.GarbageCollect()

        button('Open Window', twitter.open_timeline_window)
        button('Update',      twitter.update)
        button('Infobox',     infobox)
        button('Drop Tables', droptables)
        button('Popup',       popup)
        button('Fake Tweets', fake_tweets)

        s = f.Sizer = wx.BoxSizer(wx.HORIZONTAL)

        v = wx.BoxSizer(wx.VERTICAL)
        v.AddMany(buttons)

        fake_tweets_txt = wx.TextCtrl(f, -1, '1000')
        v.Add(fake_tweets_txt)

        s.Add(v, 0, wx.EXPAND)

        v2 = wx.BoxSizer(wx.VERTICAL)
        stxt = wx.StaticText(f)
        v2.Add(stxt, 0, wx.EXPAND)

        from pprint import pformat
        from common.commandline import wkstats
        def update_text():
            debug_txt = '\n\n'.join([
                pformat(wkstats()),
                j('debugCounts()')
            ])

            stxt.Label = debug_txt
            f.Sizer.Layout()

        f._timer = wx.PyTimer(update_text)
        f._timer.StartRepeating(1000)
        f.SetBackgroundColour(wx.WHITE)

        s.Add((50, 50))
        s.Add(v2, 0, wx.EXPAND)

        return f

    from tests.testapp import testapp

    username, password = '******', 'no passwords'
    if len(sys.argv) > 2:
        username, password = sys.argv[1:3]

    app = testapp(skinname='Windows 7', plugins=True)

    global twitter # on console
    from twitter.twitter import TwitterProtocol
    twitter = TwitterProtocol(username, password)
    twitter.events.state_changed += lambda state: print('state changed:', state)
    twitter.events.reply += lambda screen_name: print('reply:', screen_name)

    import common.protocolmeta
    account_opts = common.protocolmeta.protocols['twitter']['defaults'].copy()

    if '--twitter-offline' in sys.argv:
        account_opts['offlineMode'] = True

    #import simplejson
    #account_opts['feeds'] = simplejson.loads('[{"type": "timeline", "name": "timeline"}, {"type": "mentions", "name": "mentions"}, {"type": "directs", "name": "directs"}, {"name": "group:1", "popups": false, "ids": [14337372, 9499402, 8517312, 7341872, 32218792, 9853162], "filter": false, "groupName": ".syntax", "type": "group"}, {"name": "search:1", "title": "foramilliondollars", "popups": false, "merge": false, "query": "#foramilliondollars", "save": true, "type": "search"}]')

    twitter.connect(account_opts)

    # mock an accountmanager/social networks list for the global status dialog
    from util.observe import ObservableList, Observable
    class TwitterAccount(Observable):
        service = protocol = 'twitter'
        enabled = True
        ONLINE = True
        def __init__(self, connection):
            Observable.__init__(self)
            self.display_name = self.name = connection.username
            self.connection = connection
            self.connection.account = self

    import digsbyprofile
    from util import Storage as S

    acctmgr = digsbyprofile.profile.account_manager = S(
        socialaccounts = ObservableList([TwitterAccount(twitter)])
    )
    digsbyprofile.profile.socialaccounts = acctmgr.socialaccounts

    global j
    j = twitter.webkitcontroller.evaljs

    def _html():
        txt = twitter.webkitcontroller.FeedWindow.PageSource.encode('utf-8')
        from path import path
        p = path(r'c:\twitter.html')
        p.write_bytes(txt)
        wx.LaunchDefaultBrowser(p.url())

    global html
    html = _html

    f = build_test_frame()
    f.Show()

    if '--drop' in sys.argv:
        twitter.clear_cache()

    wx.CallLater(500, twitter.open_timeline_window)

    app.MainLoop()
示例#3
0
    def construct(self):
        def Text(*a, **k):
            txt = StaticText(self, -1, *a, **k)
            txt.Wrap(520)
            return txt

        def BoldText(*a, **k):
            t = Text(*a, **k)
            t.SetBold()
            return t

        self.header = BoldText(_(
            'Use this tool to submit a diagnostic log right after you experience a bug'
        ),
                               style=ALIGN_CENTER)

        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)

        self.subheader.SetSizerProps(expand=True)

        self.line = StaticLine(self)

        self.input_desc = BoldText(
            _('Please describe the bug in as much detail as possible. Include information such as what you were doing when the bug occurred and exactly what goes wrong.'
              ))

        self.input_desc.SetSizerProps(expand=True)

        self.input = TextCtrl(self, -1, size=(400, 200), style=wx.TE_MULTILINE)
        self.input.SetSizerProps(expand=True, proportion=1)

        radioPanel = self.radioPanel = sc.SizedPanel(self, -1)
        radioPanel.SetSizerType("horizontal")

        self.reproduce_text = wx.StaticText(
            radioPanel, -1, _('Can you consistently reproduce this bug?'))

        self.radios = S(yes=RadioButton(radioPanel,
                                        -1,
                                        _('&Yes'),
                                        style=wx.RB_GROUP),
                        no=RadioButton(radioPanel, -1, _('&No')),
                        unknown=RadioButton(radioPanel, -1, _("&Don't Know")))
        self.radios.unknown.SetValue(True)

        self.screenshot_text = BoldText(
            _('If this is a visual bug, please attach a screenshot to this report.'
              ))
        self.screenshot_link = wx.HyperlinkCtrl(self, -1, _('Take Screenshot'),
                                                '#')
        self.screenshot_link.Bind(wx.EVT_HYPERLINK, self.OnScreenshot)

        self.screenshot_timer = ScreenshotTimer(
            SCREENSHOT_TIMER_SECS, lambda t: self.OnScreenshotLinkTimer(
                _('Taking Screenshot in {secs}').format(secs=t)),
            self.OnScreenshotTimer)

        self.Bind(wx.EVT_SIZE, self.OnSize)
示例#4
0
 def msgobj(msg):
     return S(buddy=b,
              conversation=c,
              message=msg,
              timestamp=datetime.now())
示例#5
0
from util import Point2HTMLSize, Storage as S

DEFAULTS = S(FONT='Times New Roman',
             SIZE=12,
             BACK=(255, 255, 255),
             FORE=(0, 0, 0))


def tohex(t, n=3):
    return ''.join('%02x' % c for c in t[:n])


pointsize_map = {8: 1, 10: 2, 12: 3, 14: 4, 18: 5, 24: 6, 36: 7, 38: 7}


def aimsize(n):
    n = int(n)

    try:
        return pointsize_map[n]
    except KeyError:
        return Point2HTMLSize(n)


def to_aimhtml(s, fmt, body_bgcolor=False, replace_newlines=False):
    '''
    Given a string, and a fmt dictionary containing color and font information, returns "AIM" html.

    AIM html is a limited subset of HTML displayed by AIM clients.
    '''
    before, after = '', ''
示例#6
0
def _no_song():
    return S(format_string = '%(title)s',
             format_args   = dict(title = NO_SONG_MESSAGE, is_blank = True,),
             app           = '')
示例#7
0
    add(pref('plugins.nowplaying.format', default=u'%(title)s - %(artist)s'))
    add(pref('plugins.nowplaying.backup_format', default=u'%(filename)s'))

    for fmt in formats[:]:
        if type(fmt) is not unicode:
            fmt = fmt.decode('ascii')

        try:
            fmt % format_dict
        except (KeyError, TypeError), e:
            formats.remove(fmt)

    if formats:
        retval = S(format_string = formats[0],
                   format_args   = format_dict,
                   app           = g('app'))
    else:
        retval = _no_song()

    return retval

def currentSong():
    '''
    Discover the current song.

    Checks MODULE.currentSong() where MODULE is one of the modules listed above
    in player_order.
    '''
    songs = []
示例#8
0
 def get_info(self):
     return S(name = self.name,
              account = self.get_acct())