Пример #1
0
    def __init__(self, checkedItems=(), lang='thai'):
        self.lang = lang
        w,h = wx.GetDisplaySize()
        self.margin = 150
        wx.Dialog.__init__(self, None, -1, u'โปรดเลือกเล่มที่ต้องการค้นหา',size=(w-self.margin,h-self.margin-30),pos=(self.margin/2,self.margin/2))
        f = open(os.path.join(sys.path[0],'resources','book_name.pkl'),'rb')
        db = cPickle.load(f)
        f.close()
        if lang == 'thai' or lang == 'pali' or lang == 'thaiwn' or lang == 'thaimc':
            self.checklist = wx.CheckListBox(self, -1, 
                choices=[arabic2thai(u'พระไตรปิฎกเล่มที่ %d %s'%(x,db['thai_'+str(x)].decode('utf8','ignore'))) for x in range(1,46)])
        elif lang == 'thaimm':
            self.checklist = wx.CheckListBox(self, -1, 
                choices=[arabic2thai(u'พระไตรปิฎกเล่มที่ %d %s'%(x,db['thaimm_'+str(x)].decode('utf8','ignore'))) for x in range(1,92)])

        for i in checkedItems:
            self.checklist.Check(i,True)

        self.checklist.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckListBox)
            
        leftSizer = wx.BoxSizer(wx.VERTICAL)
        self.btnFirst = wx.Button(self, -1, u'พระวินัยปิฎก')
        self.btnSecond = wx.Button(self, -1, u'พระสุตตันตปิฎก')
        self.btnThird = wx.Button(self, -1, u'พระอภิธรรมปิฎก')
        self.btnSelAll = wx.Button(self, -1, u'เลือกทั้งหมด')
        self.btnDelAll = wx.Button(self, -1, u'ลบทั้งหมด')

        self.btnFirst.Bind(wx.EVT_BUTTON,self.OnClickFirst)
        self.btnSecond.Bind(wx.EVT_BUTTON,self.OnClickSecond)
        self.btnThird.Bind(wx.EVT_BUTTON,self.OnClickThird)
        self.btnSelAll.Bind(wx.EVT_BUTTON,self.OnClickSelAll)
        self.btnDelAll.Bind(wx.EVT_BUTTON,self.OnClickDelAll)

        self.btnOk = wx.Button(self, wx.ID_OK, u'ตกลง')
        self.btnOk.SetDefault()
        self.btnCancel = wx.Button(self, wx.ID_CANCEL, u'ยกเลิก')

        if len(checkedItems) == 0:
            self.btnOk.Disable()
        
        leftSizer.Add(self.btnFirst,flag=wx.EXPAND)
        leftSizer.Add(self.btnSecond,flag=wx.EXPAND)
        leftSizer.Add(self.btnThird,flag=wx.EXPAND)
        leftSizer.Add((-1,30),flag=wx.EXPAND)
        leftSizer.Add(self.btnSelAll,flag=wx.EXPAND)
        leftSizer.Add(self.btnDelAll,flag=wx.EXPAND)
        leftSizer.Add((-1,-1),1,flag=wx.EXPAND)
        leftSizer.Add(self.btnOk,flag=wx.EXPAND)
        leftSizer.Add(self.btnCancel,flag=wx.EXPAND)

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(leftSizer,flag=wx.EXPAND)
        mainSizer.Add(self.checklist,1,flag=wx.EXPAND)
        self.SetSizer(mainSizer)
Пример #2
0
    def UpdateResults(self,now,per,total):
        text = u''
        label1 = u'พระไตรปิฎก เล่มที่'
        label2 = u'หน้าที่'
        
        p2 = now * per
        p1 = p2 - per
        
        pages = total/per
        if total % 10:
            pages += 1
        
        if p2 > total:
            p2 = total

        if p1 >= 0:            
            key = '%d:%d'%(p1,p2)
            for i,vol,page,items,excerpts in dataModel[key]:
                labelItems = items.split()
                if len(items.split()) == 1:
                    labelItems = labelItems[0]
                else:
                    labelItems = u'%s - %s'%(labelItems[0],labelItems[-1])
                read = u''
                if i in self.read:
                    read = u'(อ่านแล้ว)'
                text += u'<div><font size="4"><a href="p:%s_%s_%s_%d_%d_%d_%d">%s. %s %s %s %s</a><font color="red"> %s</font></font><br>'%(vol,page,self.lang,now,per,total,i,
                                                                                             arabic2thai(unicode(i)),
                                                                                             label1,arabic2thai(vol),label2,arabic2thai(page),read)\
                 + u'<font size="4">%s</font>'%(excerpts) + u'<br>'\
                 + u'<font size="4" color="#378000">%s ข้อที่ %s</font>'%(self.bookNames['%s_%s'%(self.lang,vol.encode('utf8'))].decode('utf8'),arabic2thai(labelItems))\
                 + u'</div><br>'
            keywords = self.keywords
            if self.lang == 'pali':
                keywords = self.keywords.replace(u'ฐ',u'\uf700').replace(u'ญ',u'\uf70f').replace(u'\u0e4d',u'\uf711')
            header = u'<div align="center"><font size="3" color="brown">ผลการค้นหา %d - %d จากทั้งหมด %d หน้า สำหรับคำว่า "%s"</font></div>' % (p1+1,p2,self.total,keywords)
            suggests = self.DoSuggest(self.keywords)
            hint = u''
            if suggests != []:
                hint = u'<br><br><div align="right"><font size="3" color="red">หรือคุณหมายถึง: %s</font></div><br>'%(self.MakeUpSuggests(suggests))
            select_pages = self.MakeUpSelectPages(self.pages,now,per,total)
            self.resultWindow.SetPage(arabic2thai(header) + hint + text + '<br>' + select_pages)
            self.statusBar.SetStatusText(u'ผลการค้นหา %d - %d'%(p1+1,p2), 2)
            
        if now == 1:
            self.btnPrev.Disable()          
        if now == pages:
            self.btnNext.Disable()
        if now > 1:
            self.btnPrev.Enable()
        if now < pages:
            self.btnNext.Enable()
Пример #3
0
    def MakeUpSelectPages(self, pages, now, per, total):
        text = u'ผลการค้นหาทั้งหมด<br>'
        for i in range(1,pages+1):
            thai_num = arabic2thai(unicode(i))
            if i != now:
                if i in self.resultWindow.clicked_pages:
                    text += u'<b><i><a href="n:%d_%d_%d">%s</a></i></b> '%(i,per,total,thai_num)
                else:
                    text += u'<a href="n:%d_%d_%d">%s</a> '%(i,per,total,thai_num)
            else:
                text += u'<b>%s</b> '%(thai_num)

        return '<div align="center">' + text + '</div>'
Пример #4
0
    def MakeUpSelectPages(self, pages, now, per, total):
        text = u'ผลการค้นหาทั้งหมด<br>'
        for i in range(1,pages+1):
            thai_num = arabic2thai(unicode(i))
            if i != now:
                if i in self.resultWindow.clicked_pages:
                    text += u'<b><i><a href="n:%d_%d_%d">%s</a></i></b> '%(i,per,total,thai_num)
                else:
                    text += u'<a href="n:%d_%d_%d">%s</a> '%(i,per,total,thai_num)
            else:
                text += u'<b>%s</b> '%(thai_num)

        return '<div align="center">' + text + '</div>'
Пример #5
0
    def CreateReadingFrame(self, volume, page, lang=None, isCompare=False,hide=False, item=None):
        if lang is None:
            lang = self.lang
        keywords = u''
        if not isCompare:
            keywords = self.keywords
            
        if True or lang not in self.bookFrames:
            self.frameId[lang] = wx.NewId()
            size,pos = None,None
            if isCompare:
                w,h = wx.GetDisplaySize()
                x = 0
                if 'wxGTK' in wx.PlatformInfo:
                    x = 5 
                size = (w/2)-x,h-30
                if lang == 'thai' or lang == 'thaimm' or lang == 'thaiwn' or lang == 'thaimc' or lang == 'thaibt':
                    pos = (0,0)
                elif isCompare and lang == 'pali':
                    pos = (w/2)+x,0
            self.bookFrames[lang] = ReadingToolFrame(self,self.frameId[lang],
                                                          volume,page,lang=lang, 
                                                          keywords=keywords,size=size,pos=pos)
            self.bookFrames[lang].Show()
            self.bookFrames[lang].Bind(wx.EVT_CLOSE, self.OnFrameClose) 
        else:
            self.bookFrames[lang].SetKeyWords(keywords)
            self.bookFrames[lang].Raise()
            self.bookFrames[lang].Iconize(False)

        # scroll to item position
        scroll_position = 0
        if isCompare and item != None:
            for result in self.bookFrames[lang].GetContent(volume, page):
                content = result['content']
                scroll_position = content.find(u'[%s]'%(arabic2thai(unicode(item))))
                break;

        if lang != 'thaibt' and page == 0:
            self.bookFrames[lang].GenStartPage()
        elif lang != 'thaibt' and page != 0:
            self.bookFrames[lang].GenStartPage()
            self.bookFrames[lang].SetVolumePage(volume,page)
            self.bookFrames[lang].LoadContent(scroll=scroll_position)
        else:
            self.bookFrames[lang].LoadFiveBookContent(volume, page)
            
        if hide:
            self.bookFrames[lang].HideBooks()
Пример #6
0
    def CreateReadingFrame(self, volume, page, lang=None, isCompare=False,hide=False, item=None):
        if lang is None:
            lang = self.lang
        keywords = u''
        if not isCompare:
            keywords = self.keywords
            
        if lang not in self.bookFrames:
            self.frameId[lang] = wx.NewId()
            size,pos = None,None
            if isCompare:
                w,h = wx.GetDisplaySize()
                x = 0
                if 'wxGTK' in wx.PlatformInfo:
                    x = 5 
                size = (w/2)-x,h-30
                if lang == 'thai' or lang == 'thaimm' or lang == 'thaiwn' or lang == 'thaimc' or lang == 'thaibt':
                    pos = (0,0)
                elif isCompare and lang == 'pali':
                    pos = (w/2)+x,0
            self.bookFrames[lang] = ReadingToolFrame(self,self.frameId[lang],
                                                          volume,page,lang=lang, 
                                                          keywords=keywords,size=size,pos=pos)
            self.bookFrames[lang].Show()
            self.bookFrames[lang].Bind(wx.EVT_CLOSE, self.OnFrameClose) 
        else:
            self.bookFrames[lang].SetKeyWords(keywords)
            self.bookFrames[lang].Raise()
            self.bookFrames[lang].Iconize(False)

        # scroll to item position
        scroll_position = 0
        if isCompare and item != None:
            for result in self.bookFrames[lang].GetContent(volume, page):
                content = result['content']
                scroll_position = content.find(u'[%s]'%(arabic2thai(unicode(item))))
                break;

        if lang != 'thaibt' and page == 0:
            self.bookFrames[lang].GenStartPage()
        elif lang != 'thaibt' and page != 0:
            self.bookFrames[lang].GenStartPage()
            self.bookFrames[lang].SetVolumePage(volume,page)
            self.bookFrames[lang].LoadContent(scroll=scroll_position)
        else:
            self.bookFrames[lang].LoadFiveBookContent(volume, page)
            
        if hide:
            self.bookFrames[lang].HideBooks()
Пример #7
0
    def UpdateResults(self,now,per,total):
        text = u''
        label1 = u'พระไตรปิฎก เล่มที่'
        label2 = u'หน้าที่'
        
        p2 = now * per
        p1 = p2 - per
        
        pages = total/per
        if total % 10:
            pages += 1
        
        if p2 > total:
            p2 = total

        if p1 >= 0:            
            key = '%d:%d'%(p1,p2)
            for i,vol,page,items,excerpts in dataModel[key]:
                labelItems = items.split()
                if len(items.split()) == 1:
                    labelItems = labelItems[0]
                else:
                    labelItems = u'%s - %s'%(labelItems[0],labelItems[-1])
                read = u''
                if i in self.read:
                    read = u'(อ่านแล้ว)'

                if int(vol) <= 8:
                    ccode ="#1e90ff"
                elif int(vol) <= 33:
                    ccode ="#ff4500"
                else:
                    ccode ="#a020f0"

                if self.lang != 'thaibt':
                    bookname = self.bookNames['%s_%s'%(self.lang,vol.encode('utf8','ignore'))].decode('utf8','ignore')
                    html_item = u'<font size="4" color="%s">%s ข้อที่ %s</font>'%(ccode, bookname, arabic2thai(labelItems))
                else:
                    bookname, html_item = u'', u''
                
                html_excerpts = u'<font size="4">%s</font><br>'%(excerpts) 
                if self.lang != 'thaibt':
                    entry = u'%s. %s %s %s %s' % (arabic2thai(unicode(i)),label1,arabic2thai(vol),label2,arabic2thai(page))
                else:
                    entry = u'%s. %s %s %s' % (arabic2thai(unicode(i)), FIVE_BOOKS_TITLES[int(vol)-1], label2, arabic2thai(page))
                    
                html_entry = u'''
                    <font size="4">
                        <a href="p:%s_%s_%s_%d_%d_%d_%d">%s</a>
                        <font color="red">%s</font><br>
                    </font>
                '''%(vol,page,self.lang,now,per,total,i,entry,read)
                text += u'<div>' + html_entry + html_excerpts + html_item + u'</div><br>'
                 
            keywords = self.keywords
            if self.lang == 'pali':
                keywords = self.keywords.replace(u'ฐ',u'\uf700').replace(u'ญ',u'\uf70f').replace(u'\u0e4d',u'\uf711')
            keywords = ' '.join(filter(lambda x:x.find('v:') != 0, keywords.split()))
                
            # Add more info about hit pages
            v_pages = self.group_results[0]
            s_pages = self.group_results[1]
            a_pages = self.group_results[2]
            
            if self.lang != 'thaibt':
                info = u'''
                    <div align="center">
                        <table cellpadding="0">
                            <tr>
                                <th align="center"><b><font color="#1e90ff">พระวินัยฯ</font></b></th>
                                <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                <th align="center"><b><font color="#ff4500">พระสุตตันตฯ</font></b></th>
                                <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                <th align="center"><b><font color="#a020f0">พระอภิธรรมฯ</font></b></th>                                                        
                            </tr>
                            <tr>
                                <td align="center">%s หน้า</td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                            
                                <td align="center">%s หน้า</td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                            
                                <td align="center">%s หน้า</td>                                                                                
                            </tr>
                        </table>
                    </div><br/><p/>
                ''' % (arabic2thai(unicode(v_pages)),arabic2thai(unicode(s_pages)),arabic2thai(unicode(a_pages)))
            else:
                info = u''
                
            header = u'''
                <div align="center">
                    <font size="3" color="brown">ผลการค้นหา %d - %d จากทั้งหมด %d หน้า สำหรับคำว่า "%s"</font>
                </div>''' % (p1+1,p2,self.total,keywords)
                
            suggests = self.DoSuggest(self.keywords)
            hint = u''
            if suggests != []:
                hint = u'<br><br><div align="right"><font size="3" color="red">หรือคุณหมายถึง: %s</font></div><br>'%(self.MakeUpSuggests(suggests))
            select_pages = self.MakeUpSelectPages(self.pages,now,per,total)
            self.resultWindow.SetPage(info + arabic2thai(header) + hint + text + '<br>' + select_pages)
            self.statusBar.SetStatusText(u'ผลการค้นหา %d - %d'%(p1+1,p2), 2)
            
        if now == 1:
            self.btnPrev.Disable()          
        if now == pages:
            self.btnNext.Disable()
        if now > 1:
            self.btnPrev.Enable()
        if now < pages:
            self.btnNext.Enable()
Пример #8
0
    def __init__(self, checkedItems=(), lang='thai'):
        self.lang = lang
        w, h = wx.GetDisplaySize()
        self.margin = 150
        wx.Dialog.__init__(self,
                           None,
                           -1,
                           u'โปรดเลือกเล่มที่ต้องการค้นหา',
                           size=(w - self.margin, h - self.margin - 30),
                           pos=(self.margin / 2, self.margin / 2))
        f = open(os.path.join('resources', 'book_name.pkl'), 'rb')
        db = cPickle.load(f)
        f.close()
        if lang == 'thai' or lang == 'pali' or lang == 'thaiwn' or lang == 'thaimc':
            self.checklist = wx.CheckListBox(
                self,
                -1,
                choices=[
                    arabic2thai(
                        u'พระไตรปิฎกเล่มที่ %d %s' %
                        (x, db['thai_' + str(x)].decode('utf8', 'ignore')))
                    for x in range(1, 46)
                ])
        elif lang == 'thaimm':
            self.checklist = wx.CheckListBox(
                self,
                -1,
                choices=[
                    arabic2thai(
                        u'พระไตรปิฎกเล่มที่ %d %s' %
                        (x, db['thaimm_' + str(x)].decode('utf8', 'ignore')))
                    for x in range(1, 92)
                ])

        for i in checkedItems:
            self.checklist.Check(i, True)

        self.checklist.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckListBox)

        leftSizer = wx.BoxSizer(wx.VERTICAL)
        self.btnFirst = wx.Button(self, -1, u'พระวินัยปิฎก')
        self.btnSecond = wx.Button(self, -1, u'พระสุตตันตปิฎก')
        self.btnThird = wx.Button(self, -1, u'พระอภิธรรมปิฎก')
        self.btnSelAll = wx.Button(self, -1, u'เลือกทั้งหมด')
        self.btnDelAll = wx.Button(self, -1, u'ลบทั้งหมด')

        self.btnFirst.Bind(wx.EVT_BUTTON, self.OnClickFirst)
        self.btnSecond.Bind(wx.EVT_BUTTON, self.OnClickSecond)
        self.btnThird.Bind(wx.EVT_BUTTON, self.OnClickThird)
        self.btnSelAll.Bind(wx.EVT_BUTTON, self.OnClickSelAll)
        self.btnDelAll.Bind(wx.EVT_BUTTON, self.OnClickDelAll)

        self.btnOk = wx.Button(self, wx.ID_OK, u'ตกลง')
        self.btnOk.SetDefault()
        self.btnCancel = wx.Button(self, wx.ID_CANCEL, u'ยกเลิก')

        if len(checkedItems) == 0:
            self.btnOk.Disable()

        leftSizer.Add(self.btnFirst, flag=wx.EXPAND)
        leftSizer.Add(self.btnSecond, flag=wx.EXPAND)
        leftSizer.Add(self.btnThird, flag=wx.EXPAND)
        leftSizer.Add((-1, 30), flag=wx.EXPAND)
        leftSizer.Add(self.btnSelAll, flag=wx.EXPAND)
        leftSizer.Add(self.btnDelAll, flag=wx.EXPAND)
        leftSizer.Add((-1, -1), 1, flag=wx.EXPAND)
        leftSizer.Add(self.btnOk, flag=wx.EXPAND)
        leftSizer.Add(self.btnCancel, flag=wx.EXPAND)

        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(leftSizer, flag=wx.EXPAND)
        mainSizer.Add(self.checklist, 1, flag=wx.EXPAND)
        self.SetSizer(mainSizer)
Пример #9
0
    def UpdateResults(self,now,per,total):
        text = u''
        label1 = u'พระไตรปิฎก เล่มที่'
        label2 = u'หน้าที่'
        
        p2 = now * per
        p1 = p2 - per
        
        pages = total/per
        if total % 10:
            pages += 1
        
        if p2 > total:
            p2 = total

        if p1 >= 0:            
            key = '%d:%d'%(p1,p2)
            for i,vol,page,items,excerpts in dataModel[key]:
                labelItems = items.split()
                if len(items.split()) == 1:
                    labelItems = labelItems[0]
                else:
                    labelItems = u'%s - %s'%(labelItems[0],labelItems[-1])
                read = u''
                if i in self.read:
                    read = u'(อ่านแล้ว)'

                if int(vol) <= 8:
                    ccode ="#1e90ff"
                elif int(vol) <= 33:
                    ccode ="#ff4500"
                else:
                    ccode ="#a020f0"

                if self.lang != 'thaibt':
                    bookname = self.bookNames['%s_%s'%(self.lang,vol.encode('utf8','ignore'))].decode('utf8','ignore')
                    html_item = u'<font size="4" color="%s">%s ข้อที่ %s</font>'%(ccode, bookname, arabic2thai(labelItems))
                else:
                    bookname, html_item = u'', u''
                
                html_excerpts = u'<font size="4">%s</font><br>'%(excerpts) 
                if self.lang != 'thaibt':
                    entry = u'%s. %s %s %s %s' % (arabic2thai(unicode(i)),label1,arabic2thai(vol),label2,arabic2thai(page))
                else:
                    entry = u'%s. %s %s %s' % (arabic2thai(unicode(i)), FIVE_BOOKS_TITLES[int(vol)-1], label2, arabic2thai(page))
                    
                html_entry = u'''
                    <font size="4">
                        <a href="p:%s_%s_%s_%d_%d_%d_%d">%s</a>
                        <font color="red">%s</font><br>
                    </font>
                '''%(vol,page,self.lang,now,per,total,i,entry,read)
                text += u'<div>' + html_entry + html_excerpts + html_item + u'</div><br>'
                 
            keywords = self.keywords
            if self.lang == 'pali':
                keywords = self.keywords.replace(u'ฐ',u'\uf700').replace(u'ญ',u'\uf70f').replace(u'\u0e4d',u'\uf711')
            keywords = ' '.join(filter(lambda x:x.find('v:') != 0, keywords.split()))
                
            # Add more info about hit pages
            v_pages = self.group_results[0]
            s_pages = self.group_results[1]
            a_pages = self.group_results[2]
            
            if self.lang != 'thaibt':
                info = u'''
                    <div align="center">
                        <table cellpadding="0">
                            <tr>
                                <th align="center"><b><font color="#1e90ff">พระวินัยฯ</font></b></th>
                                <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                <th align="center"><b><font color="#ff4500">พระสุตตันตฯ</font></b></th>
                                <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                <th align="center"><b><font color="#a020f0">พระอภิธรรมฯ</font></b></th>                                                        
                            </tr>
                            <tr>
                                <td align="center">%s หน้า</td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                            
                                <td align="center">%s หน้า</td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>                            
                                <td align="center">%s หน้า</td>                                                                                
                            </tr>
                        </table>
                    </div><br/><p/>
                ''' % (arabic2thai(unicode(v_pages)),arabic2thai(unicode(s_pages)),arabic2thai(unicode(a_pages)))
            else:
                info = u''
                
            header = u'''
                <div align="center">
                    <font size="3" color="brown">ผลการค้นหา %d - %d จากทั้งหมด %d หน้า สำหรับคำว่า "%s"</font>
                </div>''' % (p1+1,p2,self.total,keywords)
                
            suggests = self.DoSuggest(self.keywords)
            hint = u''
            if suggests != []:
                hint = u'<br><br><div align="right"><font size="3" color="red">หรือคุณหมายถึง: %s</font></div><br>'%(self.MakeUpSuggests(suggests))
            select_pages = self.MakeUpSelectPages(self.pages,now,per,total)
            self.resultWindow.SetPage(info + arabic2thai(header) + hint + text + '<br>' + select_pages)
            self.statusBar.SetStatusText(u'ผลการค้นหา %d - %d'%(p1+1,p2), 2)
            
        if now == 1:
            self.btnPrev.Disable()          
        if now == pages:
            self.btnNext.Disable()
        if now > 1:
            self.btnPrev.Enable()
        if now < pages:
            self.btnNext.Enable()