Changeset 29508

Show
Ignore:
Timestamp:
02/04/09 12:24:16 (4 years ago)
Author:
showyou
Message:

各種設定記憶. .chat/configは一回消したほうがいいかも

Location:
lang/python/crochet
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/python/crochet/config.py

    r23420 r29508  
    11# -*- coding: utf-8 -*- 
     2import cPickle as pickle  
    23import wx 
    34 
     5class 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 
    423 
    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() 
    633 
    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 = user 
    12         self.password = password 
    13          
    14         panel = wx.Panel(self.dialog, -1) 
    15         vbox = wx.BoxSizer(wx.VERTICAL) 
    1634 
    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") 
    2242 
    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] 
    2645 
    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  
    11#!/usr/bin/env python 
    2 # -*- coding: utf-8 -*- 
     2# -*- coding:utf-8 -*- 
    33 
    44import sys,os,time,re 
     
    88import urllib 
    99 
    10 import twitter3 
     10import twitterscraping 
    1111import simplejson 
    1212import Image 
     
    1616from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin 
    1717 
     18import configDialog 
    1819import config 
    1920 
     
    2223os.chdir(dir) 
    2324 
    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  
     25g_config = config.Config() 
    3326"""自動リサイズするListCtrl""" 
    3427class ListCtrlAutoWidth(wx.ListCtrl, ListCtrlAutoWidthMixin): 
     
    225218                self.lock = threadLock 
    226219                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) 
    229222                list = self.list = ListCtrlAutoWidth(self) 
    230223                list.Bind(wx.EVT_KEY_DOWN, self.myKeyHandler) 
     
    253246 
    254247                """ 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 
    288249                                         
    289250                #print "mainText",mainText 
     
    309270 
    310271                        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']) 
    312273 
    313274        def ResetCount(self): 
     
    319280                selectedRow = event.GetIndex() 
    320281                user = "@" + self.dataList[selectedRow][1] + ' ' 
    321                 self.owner.addUser2Inputbox(user) 
     282                self.owner.AddUser2Inputbox(user) 
    322283 
    323284        def myKeyHandler(self,evt): 
     
    427388 
    428389                        if re.search(user,b[2]): 
    429                                 self.list.SetItemBackgroundColour(i,wx.Color(255,153,153)) 
     390                                self.list.SetItemBackgroundColour(i,g_config['forMeColor']) 
    430391                 
    431392                        #import time 
     
    470431customPageは上に移った 
    471432""" 
    472  
    473433class RecentPage(TmpTwitPage): 
    474434        def __init__(self, parent,threadLock,filter): 
     435                  
    475436                TmpTwitPage.__init__(self,u"最新",parent,threadLock) 
    476437 
    477                 #self.dataList = [] 
    478                 #self.hiddenDataList = [] 
    479438                self.customPages = {}# フィルタリングページの固まり? 
    480439                self.filter = filter 
     
    519478                                dataListElement.append(x[0]) 
    520479                                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") 
    522483                                dataListElement.append(x2) 
    523484                                dataListElement.append(x[3]) 
     
    551512                                TmpTwitPage.CallGrowl(self,"Recent 新着"+str(outCount)+"件",outString) 
    552513 
    553                 #print ("xe"), 
    554                 #print self.owner, 
    555                 #self.owner.SetNowTime2StatusBar() 
    556                 #print ("end recent:refreshlist") 
    557  
    558514class ReplyPage(TmpTwitPage): 
    559  
    560515        def __init__(self, parent,threadLock): 
    561516                TmpTwitPage.__init__(self,"Re",parent,threadLock) 
     
    608563 
    609564class DMPage(TmpTwitPage): 
    610  
    611565        def __init__(self, parent,threadLock): 
    612566                TmpTwitPage.__init__(self,"DM",parent,threadLock) 
     
    670624        """MainFrame class deffinition. 
    671625        """ 
    672         #binder = wx_utils.bind_manager() 
    673626 
    674627        TIMER_ID = 1 
     
    696649                        twUserdata = self.loadUserData(".chat/twdata") 
    697650                except: 
    698                         twUserdata = config.ConfigDialog(None, -1, 'crochet config').GetAccount() 
     651                        twUserdata = configDialog.ConfigDialog(None, -1, 'crochet config').GetAccount() 
    699652                        if twUserdata["user"] and twUserdata["pass"]: 
    700653                                file = open(".chat/twdata","w") 
     
    728681                filter = [] 
    729682                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] ))    
    731684                 
    732685                self.recentPage = RecentPage(self,self.httpThreadLock,filter) 
     
    773726                self.sizer.Fit(self) 
    774727         
    775                 self.tw = twitter3.Twitter(twUserdata) 
     728                self.tw = twitterscraping.Twitter(twUserdata) 
    776729                self.tw.setAuthService("twitter") 
    777730                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']) 
    779733                self.timer = wx.Timer(self,self.TIMER_ID) 
    780734                wx.EVT_TIMER(self,self.TIMER_ID,self.OnUpdate) 
     
    792746                wx.EVT_TIMER(self,self.TIMER_ID3,self.OnDMUpdate) 
    793747                self.timer3.Start(300000) 
    794                  
     748 
     749                wx.EVT_CLOSE(self,self.OnClose)  
    795750                self.RefreshTw() 
    796751                self.replyPage.Refresh() 
     
    799754                self.SetNowTime2StatusBar() 
    800755                self.CreateMenu()        
     756                 
    801757        def CreateMenu(self): 
    802758                #表示メニュー項目作る 
     
    818774        def OnMenuViewListIcon_Click(self,e): 
    819775                g_config['listIcon'] = self.listIconCheck.IsChecked(); 
    820  
     776         
     777        # 送信する 
     778        # コンボボックスの中身を空にする 
    821779        def OnSendTW(self, event): 
    822                 # 送信する 
    823                 # コンボボックスの中身を空にする 
    824780                combo = self.text  
    825781                self.tw.put(combo.GetValue())    
    826782                combo.SetValue("") 
    827783                self.RefreshTw() 
    828          
     784 
    829785        # チャットのログデータをListCtrlに表示 
    830786        def RefreshTw(self): 
    831787                self.recentPage.Refresh()        
    832788         
     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 
    833797        def OnUpdate(self, event): 
    834798                self.SetStatusBar(u"新着取得中...") 
     
    934898                        bmp.SetBitmap(image.ConvertToBitmap()) 
    935899         
    936         def addUser2Inputbox(self,user): 
     900        def AddUser2Inputbox(self,user): 
    937901                 
    938902                text = self.text 
     
    947911                        text.SetValue(user+value) 
    948912 
    949         def getNotebook(self): 
     913        def GetNotebook(self): 
    950914                return self.notebook 
    951915 
    952916# startup application. 
    953917if __name__=='__main__': 
     918         
    954919        app = wx.App(False) 
    955920        frame = MainFrame() 
  • lang/python/crochet/toDate.py

    r28972 r29508  
    1616                return 0 
    1717 
     18# 自作strptime 
     19""" 
     20strpTable = [ "a":0, "b":0, "d":0, "H":0, "M":0, "S":0, "Y":0 ] 
     21strpWeek = [ "Sun", "Mon", "Thu", "Wen", "Thi", "Fri", "Sut" ] 
     22def 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                 
    1834def 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")) 
    2237         
    2338        return dt 
    2439 
    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