Changeset 29508
- Timestamp:
- 02/04/09 12:24:16 (4 years ago)
- Location:
- lang/python/crochet
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/python/crochet/config.py
r23420 r29508 1 1 # -*- coding: utf-8 -*- 2 import cPickle as pickle 2 3 import wx 3 4 5 class Config(): 6 def __init__(self): 7 self.Load() 8 def __del__(self): 9 self.Save() 10 def LoadDefaults(self): 11 self.d = {} 12 self.d['mycolor'] = wx.Color(240,248,255) 13 self.d['forMeColor'] = wx.Color(255,153,153) 14 self.d['listIcon'] = False 15 self.d['popup'] = True 16 self.d['narrowmsg'] = True 17 self.d['timestring_twitter_api'] = "%a %b %d %H:%M:%S +0000 %Y" 18 self.d['timestring_twitter_friend_scraping'] = "%Y-%m-%dT%H:%M:%S+00:00" 19 self.d['x'] = 0 20 self.d['y'] = 0 21 self.d['w'] = 600 22 self.d['h'] = 400 4 23 5 #chgdep = ConfigDialog(None, -1, 'crochet config') 24 def Load(self): 25 try: 26 file = open(".chat/config","r") 27 self.d = pickle.load(file) 28 file.close() 29 except: 30 print ("config file not exist: create config file") 31 self.LoadDefaults() 32 self.Save() 6 33 7 class ConfigDialog(wx.Dialog):8 # ダイアログを表示しイベント処理を行う9 def __init__(self, parent, id, title, user='', password=''):10 self.dialog = wx.Dialog(parent, id, title, size=(250, 150))11 self.user = user12 self.password = password13 14 panel = wx.Panel(self.dialog, -1)15 vbox = wx.BoxSizer(wx.VERTICAL)16 34 17 wx.StaticBox(panel, -1, 'Twitter Account', (5, 5), (240, 90)) 18 wx.StaticText(panel, -1, 'ID', (15, 30)) 19 wx.StaticText(panel, -1, 'Password', (15, 60)) 20 self.userFld = wx.TextCtrl(panel, -1, self.user, (100, 30)) 21 self.passwordFld = wx.TextCtrl(panel, -1, self.password, (100, 60), style=wx.TE_PASSWORD) 35 def Save(self): 36 37 wfile = open(".chat/config","w") 38 pickle.dump(self.d, wfile) 39 wfile.close() 40 #except: 41 # print ("write config error") 22 42 23 okButton = wx.Button(self.dialog, 1, 'OK', size=(70, 30)) 24 okButton.SetDefault() 25 self.dialog.Bind(wx.EVT_BUTTON, self.OnSave, id=1) 43 def __getitem__(self,key): 44 return self.d[key] 26 45 27 vbox.Add(panel) 28 vbox.Add(okButton, 1, wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, 10) 29 self.dialog.SetSizer(vbox) 30 self.dialog.ShowModal() # ダイアログが閉じられるまで待機 31 self.dialog.Destroy() 32 33 # OKボタンが押されたら値を保存してダイアログを閉じる 34 def OnSave(self, event): 35 self.user = self.userFld.GetValue() 36 self.password = self.passwordFld.GetValue() 37 self.dialog.EndModal(1) 38 39 # ユーザ,パスワードを返す 40 def GetAccount(self): 41 return {"user": self.user, "pass": self.password} 46 def __setitem__(self,key,item): 47 self.d[key] = item -
lang/python/crochet/crochet.py
r28972 r29508 1 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*-2 # -*- coding:utf-8 -*- 3 3 4 4 import sys,os,time,re … … 8 8 import urllib 9 9 10 import twitter 310 import twitterscraping 11 11 import simplejson 12 12 import Image … … 16 16 from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin 17 17 18 import configDialog 18 19 import config 19 20 … … 22 23 os.chdir(dir) 23 24 24 25 g_config = {} 26 g_config['mycolor'] = wx.Color(240,248,255) 27 g_config['listIcon'] = False 28 g_config['popup'] = True 29 g_config['narrowmsg'] = True 30 g_config['timestring_twitter_api'] = "%a %b %d %H:%M:%S +0000 %Y" 31 g_config['timestring_twitter_friend_scraping'] = "%Y-%m-%dT%H:%M:%S+00:00" 32 25 g_config = config.Config() 33 26 """自動リサイズするListCtrl""" 34 27 class ListCtrlAutoWidth(wx.ListCtrl, ListCtrlAutoWidthMixin): … … 225 218 self.lock = threadLock 226 219 self.dataListLock = thread.allocate_lock() 227 wx.NotebookPage.__init__(self,parent. getNotebook(),-1)228 parent. getNotebook().AddPage(self,title)220 wx.NotebookPage.__init__(self,parent.GetNotebook(),-1) 221 parent.GetNotebook().AddPage(self,title) 229 222 list = self.list = ListCtrlAutoWidth(self) 230 223 list.Bind(wx.EVT_KEY_DOWN, self.myKeyHandler) … … 253 246 254 247 """ 30文字折り返し""" 255 if g_config['narrowmsg']: 256 tmpTextLen = len(mainText); 257 tmpText = mainText; 258 tmpTagRe = re.compile("(<.+?>)") 259 tmpTagSplit = tmpTagRe.split(tmpText); 260 mainText = "" 261 tb = 30 262 tbc = 0 263 for s in tmpTagSplit: 264 tmplen = len(s); 265 #print "s:",s,",",tmplen,",",tbc 266 if tmpTagRe.match(s) != None: 267 mainText += s 268 continue 269 if tbc != 0: 270 if tb <= tbc+tmplen: 271 mainText+=s[0:tb-tbc] 272 mainText += u"<BR>" 273 i = tb-tbc 274 tbc = 0 275 else: 276 mainText+=s 277 tbc += tmplen 278 continue 279 else: i=0 280 281 while i<tmplen-tb: 282 mainText += s[i:i+tb] 283 mainText += u"<BR>" 284 i+=tb 285 if i<tmplen: 286 mainText += s[i:tmplen] 287 tbc+=tmplen-i; 248 288 249 289 250 #print "mainText",mainText … … 309 270 310 271 if re.search(user,self.dataList[i][2]): 311 self.list.SetItemBackgroundColour(i, wx.Color(255,153,153))272 self.list.SetItemBackgroundColour(i,g_config['forMeColor']) 312 273 313 274 def ResetCount(self): … … 319 280 selectedRow = event.GetIndex() 320 281 user = "@" + self.dataList[selectedRow][1] + ' ' 321 self.owner. addUser2Inputbox(user)282 self.owner.AddUser2Inputbox(user) 322 283 323 284 def myKeyHandler(self,evt): … … 427 388 428 389 if re.search(user,b[2]): 429 self.list.SetItemBackgroundColour(i, wx.Color(255,153,153))390 self.list.SetItemBackgroundColour(i,g_config['forMeColor']) 430 391 431 392 #import time … … 470 431 customPageは上に移った 471 432 """ 472 473 433 class RecentPage(TmpTwitPage): 474 434 def __init__(self, parent,threadLock,filter): 435 475 436 TmpTwitPage.__init__(self,u"最新",parent,threadLock) 476 437 477 #self.dataList = []478 #self.hiddenDataList = []479 438 self.customPages = {}# フィルタリングページの固まり? 480 439 self.filter = filter … … 519 478 dataListElement.append(x[0]) 520 479 dataListElement.append(x[1]) 521 x2 = toDate.toDate(x[2],g_config["timestring_twitter_api"]).strftime("%b %d %H:%M:%S") 480 #x2 = "--" 481 x2 = x[2] 482 #x2 = toDate.toDate(x[2],g_config["timestring_twitter_api"]).strftime("%b %d %H:%M:%S") 522 483 dataListElement.append(x2) 523 484 dataListElement.append(x[3]) … … 551 512 TmpTwitPage.CallGrowl(self,"Recent 新着"+str(outCount)+"件",outString) 552 513 553 #print ("xe"),554 #print self.owner,555 #self.owner.SetNowTime2StatusBar()556 #print ("end recent:refreshlist")557 558 514 class ReplyPage(TmpTwitPage): 559 560 515 def __init__(self, parent,threadLock): 561 516 TmpTwitPage.__init__(self,"Re",parent,threadLock) … … 608 563 609 564 class DMPage(TmpTwitPage): 610 611 565 def __init__(self, parent,threadLock): 612 566 TmpTwitPage.__init__(self,"DM",parent,threadLock) … … 670 624 """MainFrame class deffinition. 671 625 """ 672 #binder = wx_utils.bind_manager()673 626 674 627 TIMER_ID = 1 … … 696 649 twUserdata = self.loadUserData(".chat/twdata") 697 650 except: 698 twUserdata = config .ConfigDialog(None, -1, 'crochet config').GetAccount()651 twUserdata = configDialog.ConfigDialog(None, -1, 'crochet config').GetAccount() 699 652 if twUserdata["user"] and twUserdata["pass"]: 700 653 file = open(".chat/twdata","w") … … 728 681 filter = [] 729 682 for f in twTabConfig['tabFilter']: 730 filter.append(BranchFilter( f[0],f[1],f[2],f[3],f[4],f[5],f[6]))683 filter.append(BranchFilter(*f[0:7] )) 731 684 732 685 self.recentPage = RecentPage(self,self.httpThreadLock,filter) … … 773 726 self.sizer.Fit(self) 774 727 775 self.tw = twitter 3.Twitter(twUserdata)728 self.tw = twitterscraping.Twitter(twUserdata) 776 729 self.tw.setAuthService("twitter") 777 730 self.SetIcon(main_icon.getIcon()) 778 self.SetSize((600,400)) 731 self.SetSize((g_config['w'],g_config['h'])) 732 self.MoveXY(g_config['x'], g_config['y']) 779 733 self.timer = wx.Timer(self,self.TIMER_ID) 780 734 wx.EVT_TIMER(self,self.TIMER_ID,self.OnUpdate) … … 792 746 wx.EVT_TIMER(self,self.TIMER_ID3,self.OnDMUpdate) 793 747 self.timer3.Start(300000) 794 748 749 wx.EVT_CLOSE(self,self.OnClose) 795 750 self.RefreshTw() 796 751 self.replyPage.Refresh() … … 799 754 self.SetNowTime2StatusBar() 800 755 self.CreateMenu() 756 801 757 def CreateMenu(self): 802 758 #表示メニュー項目作る … … 818 774 def OnMenuViewListIcon_Click(self,e): 819 775 g_config['listIcon'] = self.listIconCheck.IsChecked(); 820 776 777 # 送信する 778 # コンボボックスの中身を空にする 821 779 def OnSendTW(self, event): 822 # 送信する823 # コンボボックスの中身を空にする824 780 combo = self.text 825 781 self.tw.put(combo.GetValue()) 826 782 combo.SetValue("") 827 783 self.RefreshTw() 828 784 829 785 # チャットのログデータをListCtrlに表示 830 786 def RefreshTw(self): 831 787 self.recentPage.Refresh() 832 788 789 def OnClose(self, event): 790 size = self.GetRect() 791 g_config['x'] = size.x 792 g_config['y'] = size.y 793 g_config['w'] = size.width 794 g_config['h'] = size.height 795 self.Destroy() 796 833 797 def OnUpdate(self, event): 834 798 self.SetStatusBar(u"新着取得中...") … … 934 898 bmp.SetBitmap(image.ConvertToBitmap()) 935 899 936 def addUser2Inputbox(self,user):900 def AddUser2Inputbox(self,user): 937 901 938 902 text = self.text … … 947 911 text.SetValue(user+value) 948 912 949 def getNotebook(self):913 def GetNotebook(self): 950 914 return self.notebook 951 915 952 916 # startup application. 953 917 if __name__=='__main__': 918 954 919 app = wx.App(False) 955 920 frame = MainFrame() -
lang/python/crochet/toDate.py
r28972 r29508 16 16 return 0 17 17 18 # 自作strptime 19 """ 20 strpTable = [ "a":0, "b":0, "d":0, "H":0, "M":0, "S":0, "Y":0 ] 21 strpWeek = [ "Sun", "Mon", "Thu", "Wen", "Thi", "Fri", "Sut" ] 22 def mystrptime(str, format, assign): 23 import re 24 m = re.search(str, format) 25 if !m: 26 print ("Value error: bad format"+str+":"+format) 27 else: 28 29 for a in assign: 30 if a == "a": 31 result 32 """ 33 18 34 def toDate(date,str): 19 import time 20 dates = time.strptime(date,str) 21 dt = datetime.datetime(dates[0],dates[1],dates[2],dates[3],dates[4],dates[5],dates[6])+datetime.timedelta(hours=getLocalTime("JP")) 35 dates = datetime.datetime.strptime(date,str) 36 dt = dates+datetime.timedelta(hours=getLocalTime("JP")) 22 37 23 38 return dt 24 39 25 if __name__ == "__main__":26 date = "2008-02-24T06:39:37+00:00"27 apiDate = "Thu Jan 22 05:19:28 +0000 2009"28 apiFormat = "%a %b %d %H:%M:%S +0000 %Y"29 scrapingFormat = "%Y-%m-%dT%H:%M:%S+00:00"30 print toDate(apiDate,apiFormat)31 print datetime.datetime.today()32
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)