WEB开发网
开发学院手机开发Symbian 开发 python for Symbian s60:短信搜索程序(smsearch)... 阅读

python for Symbian s60:短信搜索程序(smsearch)

 2010-08-30 00:08:00 来源:WEB开发网   
核心提示:if m > n: return -1skip = []for k in range(256): skip.append(m)for k in range(m - 1): skip[ord(pattern[k])] = m - k - 1skip = tuple(skip)k = m - 1while k <

if m > n: return -1

skip = []

for k in range(256): skip.append(m)

for k in range(m - 1): skip[ord(pattern[k])] = m - k - 1

skip = tuple(skip)

k = m - 1

while k < n:

j = m - 1; i = k

while j >= 0 and text[i] == pattern[j]:

j -= 1; i -= 1

if j == -1: return i + 1

k += skip[ord(text[k])]

return -1

def search(self,pattern):

self.results = []

lst = []

folders = {inbox.EInbox:u"Inbox",

inbox.EOutbox:u"Outbox",

inbox.ESent:u"Sent",

inbox.EDraft:u"Draft"}

for f,fn in folders.iteritems():

ibx = inbox.Inbox(f)

for sms_id in ibx.sms_messages():

txt = ibx.content(sms_id)

txt_utf8 = txt.encode('utf-8')

pattern_utf8 = pattern.encode('utf-8')

if self.bmh_search(pattern_utf8.lower(),txt_utf8.lower()) > -1:

tm = ibx.time(sms_id)

dt = unicode(time.ctime(tm),'utf-8',errors='ignore')

self.results.append((sms_id,txt,dt,ibx.address(sms_id),fn))

lst.append((tm,dt,txt[:50]))

if self.results:

# order following unix time and remove it after

lst.sort(reverse=True)

lst = map(lambda x: x[1:],lst)

self.body = Listbox(lst,self.lst_cbk)

app.screen = 'normal' # avoid wrong screen redraw

self.refresh()

else:

note(u"No results for " + self.terms,"info")

def get_pattern(self):

pattern = query(u"Search terms:", "text", self.terms)

if pattern is not None:

if pattern:

pattern = pattern.strip()

self.terms = pattern

self.search(pattern)

if __name__ == "__main__":

sms = SMSearch()

sms.run()

default.py,

上一页  1 2 3 4 5  下一页

Tags:python for Symbian

编辑录入:coldstar [复制链接] [打 印]
赞助商链接