Attachment 'TwitterStock_Version6.py'

Download

   1 ...
   2 TWITTER_STATUS_MAX_LENGTH = 140
   3 ...
   4 
   5 class TwitterStock(Stock):
   6 
   7     def __init__(self, *args, **kwargs):
   8         ...
   9   
  10         self.__twitter_status_counter_text = hippo.CanvasText(text=str(TWITTER_STATUS_MAX_LENGTH))
  11    
  12         self.__twitter_status_input = hippo.CanvasEntry()
  13         self.__twitter_status_input.get_property("widget").set_max_length(TWITTER_STATUS_MAX_LENGTH)
  14         self.__twitter_status_input.connect("notify::text", self.__on_status_edited)
  15         self.__twitter_status_input.connect("key-press-event", self.__on_status_submitted)
  16 
  17         ...
  18 
  19     def __on_status_edited(self, input, param_spec):
  20         self.__twitter_status_counter_text.set_property("text", str(TWITTER_STATUS_MAX_LENGTH - len(self.__twitter_status_input.get_property("text"))))
  21 
  22     def __on_status_submitted(self, entry, event):
  23         if event.key == hippo.KEY_RETURN:
  24             status = self.__twitter_status_input.get_property("text").strip()
  25             if status != "":
  26                 _logger.debug("will send status: %s" % status)
  27                 username = self.__twitter_account.GetUsername()
  28                 password =  self.__twitter_account.GetPassword()
  29                 self.__fetcher.fetch("http://twitter.com/statuses/update.json", 
  30                                  username, password,
  31                                  lambda url, data: self.__on_twitter_status_response(url, data, username, password), 
  32                                  lambda url, resp: self.__on_twitter_error(url, resp, username, password),
  33                                  lambda url: self.__on_auth_failed(username, password),
  34                                  data = urllib.urlencode({"status":status}))
  35 
  36             self.__twitter_status_input.set_property("text", "")
  37 
  38     def __on_twitter_response(self, url, data, username, password):
  39         _logger.debug("Authentication must be good")
  40         if self.__same_credentials(username, password):
  41             self.__box.remove_all()
  42             hello_message = hippo.CanvasText(text="Update status for " + self.__twitter_account.GetUsername() + ":",
  43                                              size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
  44             self.__box.append(hello_message)
  45             self.__box.append(self.__twitter_status_counter_text)
  46             self.__box.append(self.__twitter_status_input)  
  47 
  48     def __on_twitter_status_response(self, url, data, username, password):
  49         _logger.debug("Twitter status update went fine")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-02-25 09:46:11, 450.6 KB) [[attachment:GUADEC-Presentation.odp]]
  • [get | view] (2021-02-25 09:46:11, 0.6 KB) [[attachment:HippoCanvasExample.txt]]
  • [get | view] (2021-02-25 09:46:11, 0.5 KB) [[attachment:TwitterStock_Version1.py]]
  • [get | view] (2021-02-25 09:46:11, 3.9 KB) [[attachment:TwitterStock_Version2.py]]
  • [get | view] (2021-02-25 09:46:11, 0.4 KB) [[attachment:TwitterStock_Version3.py]]
  • [get | view] (2021-02-25 09:46:11, 0.9 KB) [[attachment:TwitterStock_Version4.py]]
  • [get | view] (2021-02-25 09:46:11, 3.1 KB) [[attachment:TwitterStock_Version5.py]]
  • [get | view] (2021-02-25 09:46:11, 2.4 KB) [[attachment:TwitterStock_Version6.py]]
  • [get | view] (2021-02-25 09:46:11, 14.1 KB) [[attachment:TwitterStock_Version7.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.