Example #1
0
    def on_call_fire(self, opts, id=None, buttons=None, onclick=None):
        from common import fire, pref
        from gui import skin

        # stringify keys, so that they can be keywords.
        # also turn dicts into storages
        opts = to_storage(dict((str(k), v)
                    for k, v in opts.iteritems()))

        if pref('twitter.popups.user_icons', default=True):
            from gui.browser.webkit.imageloader import LazyWebKitImage
            twitter_icon = skin.get('serviceicons.twitter', None)
            for tweet in opts.tweets:
                tweet.icon = LazyWebKitImage(tweet.user.profile_image_url, twitter_icon)

        def buttons_cb(item):
            if hasattr(item.tweet, 'sender_id'):
                return self.direct_buttons
            else:
                return self.tweet_buttons

        opts.update(onclick=onclick or self.on_popup_click,
                    popupid='twitter20_' + self.username + str(opts.get('popupid_postfix', '')),
                    buttons=buttons or buttons_cb,
                    max_lines=10)

        if pref('twitter.popups.mark_as_read', default=True):
            opts.update(mark_as_read=self.mark_as_read)

        opts.update(badge=skin.get('serviceicons.twitter', None))

        fire(**opts)
Example #2
0
    def on_call_fire(self, opts, id=None, buttons=None, onclick=None):
        from common import fire, pref
        from gui import skin

        # stringify keys, so that they can be keywords.
        # also turn dicts into storages
        opts = to_storage(dict((str(k), v) for k, v in opts.iteritems()))

        if pref('twitter.popups.user_icons', default=True):
            from gui.browser.webkit.imageloader import LazyWebKitImage
            twitter_icon = skin.get('serviceicons.twitter', None)
            for tweet in opts.tweets:
                tweet.icon = LazyWebKitImage(tweet.user.profile_image_url,
                                             twitter_icon)

        def buttons_cb(item):
            if hasattr(item.tweet, 'sender_id'):
                return self.direct_buttons
            else:
                return self.tweet_buttons

        opts.update(onclick=onclick or self.on_popup_click,
                    popupid='twitter20_' + self.username +
                    str(opts.get('popupid_postfix', '')),
                    buttons=buttons or buttons_cb,
                    max_lines=10)

        if pref('twitter.popups.mark_as_read', default=True):
            opts.update(mark_as_read=self.mark_as_read)

        opts.update(badge=skin.get('serviceicons.twitter', None))

        fire(**opts)
Example #3
0
 def on_self_tweet(self, tweet):
     self.self_tweet = to_storage(tweet)
Example #4
0
 def on_recent_timeline(self, tweets):
     self.recent_timeline = [to_storage(t) for t in tweets]
     self.recent_timeline.reverse()
     self.events.update_social_ids()
Example #5
0
def load_sample_tweets():
    from util.primitives.mapping import to_storage
    sample_tweets_jsonfile = os.path.join(os.path.dirname(__file__), 'sample_tweets.json')
    with open(sample_tweets_jsonfile, 'rb') as f:
        return [to_storage(t) for t in simplejson.loads(f.read())]
Example #6
0
    def __init__(self, image_dict):
        '''
        Sets up this image, splitting what is necessary and preparing the cache.

        @param image_dict: a descriptive dictionary for how to load and draw
        this image it is probably a good idea to pass in a copy if this
        dictionary will be used elsewhere.
        '''
        imgs = self.image_dictionary = to_storage(image_dict)
        image = skin.load_image(imgs.source)
        self.cache = Storage()

        clipcolor = imgs.get('clipcolor', None)
        if clipcolor is not None:
            self.cache.clipcolor = get_wxColor(imgs.clipcolor)
            image.SetMask(wx.Mask(image, self.cache.clipcolor))

        imgw = image.GetWidth()
        self.imgw = imgw
        imgh = image.GetHeight()
        self.imgh = imgh
        self.draw_commands = []
        #if corners exit
        if imgs.corners:
            self.regions_to_draw = None
            cornw = imgs.cornw = imgs.corners.size[0]
            cornh = imgs.cornh = imgs.corners.size[1]
            #else:
            #do 4-section magic
            #not really! just 2 sections, corners just drawn
            if imgs.corners.side == 'left':
                self.corners_to_draw = ['top_left', 'bottom_left']
                #cache big right
                if imgw - cornw > 0:
                    self.cache.large_right = \
                    image.GetSubBitmap(wx.Rect(cornw, 0, imgw - cornw, imgh))
                    self.regions_to_draw = ['left', 'large_right']
                else:
                    self.regions_to_draw = ['left']
                #stretch the right from x pixels off
            elif imgs.corners.side == 'right':
                self.corners_to_draw = ['top_right', 'bottom_right']
                if imgw - cornw > 0:
                    self.cache.large_left = \
                    image.GetSubBitmap(wx.Rect(0, 0, imgw - cornw, imgh))
                    self.regions_to_draw = ['large_left', 'right']
                else:
                    self.regions_to_draw = ['right']
            elif imgs.corners.side == 'top':
                self.corners_to_draw = ['top_left', 'top_right']
                if imgh - cornh > 0:
                    self.cache.large_bottom = \
                    image.GetSubBitmap(wx.Rect(0, cornh, imgw, imgh - cornh))
                    self.regions_to_draw = ['top', 'large_bottom']
                else:
                    self.regions_to_draw = ['top']
            elif imgs.corners.side == 'bottom':
                self.corners_to_draw = ['bottom_left', 'bottom_right']
                if imgh - cornh > 0:
                    self.cache.large_top = \
                    image.GetSubBitmap(wx.Rect(0, 0, imgw, imgh - cornh))
                    self.regions_to_draw = ['large_top', 'bottom']
                else:
                    self.regions_to_draw = ['bottom']
            #if all corners:
            #else if image.corners.side == 'all':
            else:
                #go do 9-section magic
                #not really! just 5 sections, corners just drawn
                self.corners_to_draw = [
                    'top_left', 'top_right', 'bottom_left', 'bottom_right'
                ]
                self.regions_to_draw = [
                    'left', 'right', 'top', 'bottom', 'center'
                ]

            [
                self.draw_commands.append(
                    (getattr(self, 'draw_' + corner + '_corner'), None))
                for corner in self.corners_to_draw
            ]
            if 'top_left' in self.corners_to_draw:
                #cache this corner
                self.cache.top_left = \
                image.GetSubBitmap(wx.Rect(0, 0, cornw, cornh))
            if 'top_right' in self.corners_to_draw:
                self.cache.top_right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, 0, cornw, cornh))
            if 'bottom_left' in self.corners_to_draw:
                self.cache.bottom_left = \
                image.GetSubBitmap(wx.Rect(0, imgh - cornh, cornw, cornh))
            if 'bottom_right' in self.corners_to_draw:
                self.cache.bottom_right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, imgh - cornh, cornw, cornh))
            if 'left' in self.regions_to_draw:
                self.cache.left = \
                image.GetSubBitmap(wx.Rect(0, cornh, cornw, imgh - cornh*2))
            if 'right' in self.regions_to_draw:
                self.cache.right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, cornh, cornw, imgh - cornh*2))
            if 'top' in self.regions_to_draw:
                self.cache.top = \
                image.GetSubBitmap(wx.Rect(cornw, 0, imgw - cornw*2, cornh))
            if 'bottom' in self.regions_to_draw:
                self.cache.bottom = \
                image.GetSubBitmap(wx.Rect(cornw, imgh - cornh, imgw - cornw*2, cornh))
            if 'center' in self.regions_to_draw:
                self.cache.center = \
                image.GetSubBitmap(wx.Rect(cornw, cornh, imgw - cornw*2, imgh - cornh*2))
        else:
            #default (stretch/tile) everything
            self.cache.total = image
            #no - assert(image.style == 'stretch' or image.style == 'tile')
            self.cache["totalch"] = 'left'
            self.cache["totalcv"] = 'top'
            self.cache["totalco"] = [0, 0]
            self.regions_to_draw = ["total"]
            #image.style to everything
        for region in self.regions_to_draw:
            if region in self.image_dictionary.regions:
                region_dict = self.image_dictionary.regions[region]
                style = region_dict['style']
                self.draw_commands.append((getattr(self,
                                                   'draw_' + region), style))
                if style == 'static' or self.image_dictionary.style == 'static':
                    color = get_wxColor(region_dict['color'])
                    if color is not None:
                        self.cache[region + "cb"] = wx.Brush(color)
                    else:
                        self.cache[region + "cb"] = None
                    self.cache[region + "ch"] = region_dict['halign']
                    self.cache[region + "cv"] = region_dict['valign']
                    self.cache[region + "co"] = region_dict['offset']
            else:
                self.draw_commands.append((getattr(self, 'draw_' + region),
                                           self.image_dictionary['style']))
Example #7
0
    def __init__(self,image_dict):
        '''
        Sets up this image, splitting what is necessary and preparing the cache.

        @param image_dict: a descriptive dictionary for how to load and draw
        this image it is probably a good idea to pass in a copy if this
        dictionary will be used elsewhere.
        '''
        imgs = self.image_dictionary = to_storage(image_dict)
        image = skin.load_image(imgs.source)
        self.cache = Storage()

        clipcolor = imgs.get('clipcolor', None)
        if clipcolor is not None:
            self.cache.clipcolor = get_wxColor(imgs.clipcolor)
            image.SetMask(wx.Mask(image, self.cache.clipcolor))

        imgw = image.GetWidth()
        self.imgw = imgw
        imgh = image.GetHeight()
        self.imgh = imgh
        self.draw_commands = []
        #if corners exit
        if imgs.corners:
            self.regions_to_draw = None
            cornw = imgs.cornw = imgs.corners.size[0]
            cornh = imgs.cornh = imgs.corners.size[1]
            #else:
                #do 4-section magic
                #not really! just 2 sections, corners just drawn
            if imgs.corners.side == 'left':
                self.corners_to_draw = ['top_left', 'bottom_left']
                #cache big right
                if imgw - cornw > 0:
                    self.cache.large_right = \
                    image.GetSubBitmap(wx.Rect(cornw, 0, imgw - cornw, imgh))
                    self.regions_to_draw = ['left','large_right']
                else:
                    self.regions_to_draw = ['left']
                #stretch the right from x pixels off
            elif imgs.corners.side == 'right':
                self.corners_to_draw = ['top_right', 'bottom_right']
                if imgw - cornw > 0:
                    self.cache.large_left = \
                    image.GetSubBitmap(wx.Rect(0, 0, imgw - cornw, imgh))
                    self.regions_to_draw = ['large_left','right']
                else:
                    self.regions_to_draw = ['right']
            elif imgs.corners.side == 'top':
                self.corners_to_draw = ['top_left', 'top_right']
                if imgh - cornh >0:
                    self.cache.large_bottom = \
                    image.GetSubBitmap(wx.Rect(0, cornh, imgw, imgh - cornh))
                    self.regions_to_draw = ['top','large_bottom']
                else:
                    self.regions_to_draw = ['top']
            elif imgs.corners.side == 'bottom':
                self.corners_to_draw = ['bottom_left', 'bottom_right']
                if imgh - cornh >0:
                    self.cache.large_top = \
                    image.GetSubBitmap(wx.Rect(0, 0, imgw, imgh - cornh))
                    self.regions_to_draw = ['large_top','bottom']
                else:
                    self.regions_to_draw = ['bottom']
            #if all corners:
            #else if image.corners.side == 'all':
            else:
                #go do 9-section magic
                #not really! just 5 sections, corners just drawn
                self.corners_to_draw = ['top_left', 'top_right',
                                   'bottom_left', 'bottom_right']
                self.regions_to_draw = ['left','right','top','bottom','center']

            [self.draw_commands.append((getattr(self,'draw_' + corner + '_corner'),None))
                                       for corner in self.corners_to_draw]
            if 'top_left'     in self.corners_to_draw:
                #cache this corner
                self.cache.top_left = \
                image.GetSubBitmap(wx.Rect(0, 0, cornw, cornh))
            if 'top_right'    in self.corners_to_draw:
                self.cache.top_right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, 0, cornw, cornh))
            if 'bottom_left'  in self.corners_to_draw:
                self.cache.bottom_left = \
                image.GetSubBitmap(wx.Rect(0, imgh - cornh, cornw, cornh))
            if 'bottom_right' in self.corners_to_draw:
                self.cache.bottom_right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, imgh - cornh, cornw, cornh))
            if 'left'   in self.regions_to_draw:
                self.cache.left = \
                image.GetSubBitmap(wx.Rect(0, cornh, cornw, imgh - cornh*2))
            if 'right'  in self.regions_to_draw:
                self.cache.right = \
                image.GetSubBitmap(wx.Rect(imgw - cornw, cornh, cornw, imgh - cornh*2))
            if 'top'    in self.regions_to_draw:
                self.cache.top = \
                image.GetSubBitmap(wx.Rect(cornw, 0, imgw - cornw*2, cornh))
            if 'bottom' in self.regions_to_draw:
                self.cache.bottom = \
                image.GetSubBitmap(wx.Rect(cornw, imgh - cornh, imgw - cornw*2, cornh))
            if 'center' in self.regions_to_draw:
                self.cache.center = \
                image.GetSubBitmap(wx.Rect(cornw, cornh, imgw - cornw*2, imgh - cornh*2))
        else:
            #default (stretch/tile) everything
            self.cache.total = image
            #no - assert(image.style == 'stretch' or image.style == 'tile')
            self.cache["totalch"] = 'left'
            self.cache["totalcv"] = 'top'
            self.cache["totalco"] = [0,0]
            self.regions_to_draw = ["total"]
            #image.style to everything
        for region in self.regions_to_draw:
            if region in self.image_dictionary.regions:
                region_dict = self.image_dictionary.regions[region]
                style = region_dict['style']
                self.draw_commands.append((getattr(self,'draw_' + region),style))
                if style == 'static' or self.image_dictionary.style == 'static':
                    color = get_wxColor(region_dict['color'])
                    if color is not None:
                        self.cache[region + "cb"] = wx.Brush(color)
                    else:
                        self.cache[region + "cb"] = None
                    self.cache[region + "ch"] = region_dict['halign']
                    self.cache[region + "cv"] = region_dict['valign']
                    self.cache[region + "co"] = region_dict['offset']
            else:
                self.draw_commands.append((getattr(self,'draw_' + region), self.image_dictionary['style']))
Example #8
0
 def on_self_tweet(self, tweet):
     self.self_tweet = to_storage(tweet)
Example #9
0
 def on_recent_timeline(self, tweets):
     self.recent_timeline = [to_storage(t) for t in tweets]
     self.recent_timeline.reverse()
     self.events.update_social_ids()
Example #10
0
def load_sample_tweets():
    from util.primitives.mapping import to_storage
    sample_tweets_jsonfile = os.path.join(os.path.dirname(__file__),
                                          'sample_tweets.json')
    with open(sample_tweets_jsonfile, 'rb') as f:
        return [to_storage(t) for t in simplejson.loads(f.read())]