Exemplo n.º 1
0
    def history(self, c, args):
        history = History("history_sword")
        if len(args) < 1:
            result = history.historyReadAll()
        else:
            result = history.historyReadAllWithFilter(args[0])

        result_object = Result()
        result_object.payload = result[::-1]
        result_object.category = "list"
        return result_object
Exemplo n.º 2
0
	def __init__(self, Universe):#parent="MainCoreWindow", 
		createResultObject = CreateResultObject()
		self.ResultObject = createResultObject.getObject()
		#self.luther()
		BibleConfigFiles = Conf("./modules/biblereader/", "biblereader.conf")
		
		self.current_bible = BibleConfigFiles.readVar("biblereader", "standard_bible")#settings.standard_bible
		self.interpreter(self.current_bible, None)
		self.ResultObject.Payload.String = None
		
		self.SHOW_ANNOTATIONS = BibleConfigFiles.readBooleanVar("biblereader", "show_annotations")#settings.SHOW_ANNOTATIONS
		self.SHOW_VERSE_NUMBERS = BibleConfigFiles.readBooleanVar("biblereader", "show_verse_numbers") #settings.SHOW_VERSE_NUMBERS
		
		#self.history = History("./modules/biblereader/bible_history")
		#BibleConfigFiles = Conf("biblereader.conf")
		self.history = History("bible_history", Universe.ConfigFiles)
		
		#ConfigFIles
		#self.conf = Conf("biblereader.conf")
		
		self.os_name = platform.uname()[0]
Exemplo n.º 3
0
 def __init__(self, universe):
     self.Universe = universe
     
     #createResultObject = CreateResultObject()
     #self.ResultObject = createResultObject.getObject()
     
     self.Bituza = Bituza(self.Universe)
     self.booksDictOT = self.Bituza.booksDictOT()
     self.booksDictNT = self.Bituza.booksDictNT()
     
     self.SwordParser = SwordParser()
     
     self.history = History("sword_history", self.Universe.ConfigFiles)
     
     ConfigFile = Conf("./modules/sword/", "sword.conf")
     self.sword_module_name = ConfigFile.readVar("sword", "default_bible")
     self.language = ConfigFile.readVar("sword", "default_language")
     
     dir_path = ConfigFile.readVar("sword", "sword_directory")
     self.modules_path = dir_path + "/modules/texts/ztext"
     self.mods_d_path = dir_path + "/mods.d"
     
     self.ModsD = ModsD(self.mods_d_path)
Exemplo n.º 4
0
class QInputLine(QLineEdit):
    
    return_pressed = pyqtSignal(str, name='return_pressed')
    
    history = History("history")
    history_counter = 0
    search_pattern_prefix = ''
    
    def __init__(self):
        super().__init__()
        
    def appendText(self, text):
        prev_text = self.text()
        prev_text += text
        self.setText(prev_text)
        
    def keyPressEvent(self, e):
        #if (e.modifiers() & Qt.NoModifier):
        if e.key() == Qt.Key_Return:
            if not self.text() == '':
                self.history.historyWrite(self.text())
                self.return_pressed.emit(self.text())
                self.setText("")
                self.history_counter = 0
            
        elif e.key() == Qt.Key_Enter:
            if not self.text() == '':
                self.history.historyWrite(self.text())
                self.return_pressed.emit(self.text())
                self.setText("")
                self.history_counter = 0
            
        elif e.key() == Qt.Key_Up:
            history_size = self.history.getHistorySize()
            
            if self.history_counter < history_size:
                self.history_counter += 1
            
            if self.history_counter == 1:
                self.search_pattern_prefix = self.text()
                
            if self.text():
                entry = self.history.historyReadWithIndexAndPrefix(self.history_counter, self.search_pattern_prefix)
                if entry == '':
                    self.search_pattern_prefix = ''
                    self.history_counter = 0
            else:
                entry = self.history.historyReadAtIndex(self.history_counter)
            
            self.setText(entry)
        
        elif e.key() == Qt.Key_Down:
            self.history_counter -= 1
            if self.history_counter < 0:
                self.history_counter = 0
            
            if self.search_pattern_prefix:
                entry = self.history.historyReadWithIndexAndPrefix(self.history_counter, self.search_pattern_prefix)
            else:
                entry = self.history.historyReadAtIndex(self.history_counter)
            self.setText(entry)
        else:
            self.history_counter = 0
        
        if (e.modifiers() & Qt.ControlModifier):
            if e.key() == Qt.Key_C:
                self.history_counter = 0
                self.setText("")
        
        super().keyPressEvent(e)
Exemplo n.º 5
0
#!/usr/bin/env python

import sys, os

os.chdir("..")
sys.path.append(".")

from configs.history import History

history = History("history")

from interpreter.exceptions import ClearCalled, SnapshotCalled


def historyWrite(text):
    history.historyWrite(text)


def getHistorySize():
    return history.getHistorySize()


def historyReadWithIndexAndPrefix(history_counter, search_pattern_prefix):
    return history.historyReadWithIndexAndPrefix(history_counter,
                                                 search_pattern_prefix)


def historyReadAtIndex(history_counter):
    return history.historyReadAtIndex(history_counter)

Exemplo n.º 6
0
class Reader(object):
    def __init__(self, universe):
        self.Universe = universe
        
        #createResultObject = CreateResultObject()
        #self.ResultObject = createResultObject.getObject()
        
        self.Bituza = Bituza(self.Universe)
        self.booksDictOT = self.Bituza.booksDictOT()
        self.booksDictNT = self.Bituza.booksDictNT()
        
        self.SwordParser = SwordParser()
        
        self.history = History("sword_history", self.Universe.ConfigFiles)
        
        ConfigFile = Conf("./modules/sword/", "sword.conf")
        self.sword_module_name = ConfigFile.readVar("sword", "default_bible")
        self.language = ConfigFile.readVar("sword", "default_language")
        
        dir_path = ConfigFile.readVar("sword", "sword_directory")
        self.modules_path = dir_path + "/modules/texts/ztext"
        self.mods_d_path = dir_path + "/mods.d"
        
        self.ModsD = ModsD(self.mods_d_path)
    
    def readBible(self, c, a):
        try:
            book = a[0]
            print "BOOK ", book
        except IndexError:
            self.ResultObject.Error.Message = "Bitte Buchname angeben"
            return self.ResultObject
        else:
            if book.isdigit():
                book_id = int(book)
            else:
                book_id = self.getBookID(book)
            if not book_id:
                self.ResultObject.Error.Message = "Buch nicht gefunden"
                return self.ResultObject
            
        try:
            chapter = a[1]
        except IndexError:
            #self.ResultObject.Error.Message = "Bitte Kapitel angeben"
            #return self.ResultObject
            chapter = 1
        
        try:
            verse = a[2]
            verse = verse.split("-")
        except:
            pass
            "EXAMPLE: 1mose 1"
            #self.history.historyWrite(book + " " + chapter)
            return self.readWholeChapter(book_id, chapter)
        else:
            if len(verse) == 1:
                "EXAMPLE: 1mose 1 2"
                return self.readOneVerse(book_id, chapter, verse[0])
            elif len(verse) == 2:
                "EXAMPLE: 1mose 1 2-4"
                return self.readVerseRange(book_id, chapter, verse)
            
    def readOneVerse(self, book_number, chapter, verse):
        book_names = self.bookNamesDict()
        print "BOOK NUMBER", book_number
        if book_number:
            book_name = book_names[int(book_number)]
        else:
            self.ResultObject.Error.Message = "Buch nicht gefunden"
            return self.ResultObject
        
        module = ZModule(self.sword_module_name, self.modules_path)
        try:
            try:
                result = module.text_for_ref(book_name, chapter, verse)
            except ValueError:
                "EXAMPLE: 1mose 1-4"
                self.ResultObject.Error.Message = "Bitte nur ein Kapitel angeben"
                return self.ResultObject
            except TypeError:
                self.ResultObject.Error.Message = "ausgewaehltes Bibelmodul nicht verfuegbar. Versuchen Sie es evtl. klein zu schreiben."
                return self.ResultObject
            
        except IndexError:
            self.ResultObject.Error.Message = "Kapitel existiert nicht"
            return self.ResultObject
        else:
            self.history.historyWrite(str(book_number) + " " + str(chapter) )
            
            "ensure correct character encoding"
            try:
                #print "sword -> result: ", result
                result = result.decode("utf8")
            except:
                result = result.decode("iso-8859-1")
            
            try:
                bible_text, title_text, note_text = self.SwordParser.feed(result)
            except Exception, e:
                print "ERROR WHILE PARSING: ", e
            
            metaData = MetaData()
            metaData.Language = self.language
            
            #self.ResultObject.Payload.String = bible_text
            #self.ResultObject.Description.MetaData = metaData
            #return self.ResultObject
            return bible_text
Exemplo n.º 7
0
class QSwordGui(QWidget):

    interpreter = Interpreter()
    queue = queue.Queue()

    sword = Sword()

    config = ConfigFile(os.path.join('modules', 'sword'), 'sword.conf')
    history = History("history_sword")

    set_tab_text = pyqtSignal(str)

    def __init__(self):
        super().__init__()

        self.unicode_fonts = UnicodeFonts()
        self.default_bible = self.config.readVar('global', 'default_bible')

        self.grid = QGridLayout()
        self.grid.setContentsMargins(0, 0, 0, 6)
        self.setLayout(self.grid)

        self.text_edit = QTextEditEnhanced()

        self.combo_language = QComboBox()
        self.combo_translation = QComboBox()
        self.combo_book = QComboBox()
        self.combo_chapter = QComboBox()

        self.combo_language.currentTextChanged.connect(self.languageChanged)
        self.combo_translation.currentTextChanged.connect(
            self.translationChanged)
        self.combo_book.currentTextChanged.connect(self.bookChanged)

        self.prev_verse_button = QPushButton("<")
        self.prev_verse_button.setMaximumSize(25, 25)
        self.next_verse_button = QPushButton(">")
        self.next_verse_button.setMaximumSize(25, 25)

        self.prev_verse_button.clicked.connect(self.prevChapter)
        self.next_verse_button.clicked.connect(self.nextChapter)

        self.grid.addWidget(QLabel("Language"), 0, 0)
        self.grid.addWidget(QLabel("Translation"), 0, 1)
        self.grid.addWidget(QLabel("Book"), 0, 2)
        self.grid.addWidget(QLabel("Chapter"), 0, 3)

        self.grid.addWidget(self.combo_language, 1, 0)
        self.grid.addWidget(self.combo_translation, 1, 1)
        self.grid.addWidget(self.combo_book, 1, 2)
        self.grid.addWidget(self.combo_chapter, 1, 3)
        self.grid.addWidget(self.prev_verse_button, 1, 4)
        self.grid.addWidget(self.next_verse_button, 1, 5)

        zoom_in_button = QPushButton(self)
        zoom_in_button.setIcon(QIcon.fromTheme('zoom-in'))
        zoom_in_button.clicked.connect(self.onZoomInClicked)
        zoom_in_button.setMaximumSize(25, 25)

        zoom_out_button = QPushButton(self)
        zoom_out_button.setIcon(QIcon.fromTheme('zoom-out'))
        zoom_out_button.clicked.connect(self.onZoomOutClicked)
        zoom_out_button.setMaximumSize(25, 25)

        zoom_reset_button = QPushButton(self)
        zoom_reset_button.setIcon(QIcon.fromTheme('zoom-original'))
        zoom_reset_button.clicked.connect(self.onZoomResetClicked)
        zoom_reset_button.setMaximumSize(25, 25)

        self.grid.addWidget(zoom_out_button, 1, 6)
        self.grid.addWidget(zoom_reset_button, 1, 7)
        self.grid.addWidget(zoom_in_button, 1, 8)

        self.grid.addWidget(self.text_edit, 2, 0, 1000, 9)

        self.getLanguagesForDropdown()
        self.getBooksForDropdown()

        self.setDefaultBible()
        self.restoreLastBookAndChapter()
        """ this has to be after setting the default values to avoid spamming the history on init and to avoid to much gui-updates on init """
        self.combo_chapter.currentTextChanged.connect(self.chapterChanged)

    def languageChanged(self, language):
        self.getTranslationsForDropdown(language)

    def translationChanged(self, translation):
        self.showText()

    def bookChanged(self, book):
        self.getChaptersForDropdown(book)

    def chapterChanged(self, chapter):
        self.showText()

    def prevChapter(self):
        chapter = self.combo_chapter.currentText()
        self.combo_chapter.setCurrentText(str(int(chapter) - 1))

        self.showText()

    def nextChapter(self):
        chapter = self.combo_chapter.currentText()
        self.combo_chapter.setCurrentText(str(int(chapter) + 1))

        self.showText()

    def getLanguagesForDropdown(self):
        #result = self.interpreter.interpreter('sword.languages', self.queue).payload
        result = self.sword.listLanguages(None, []).payload
        if result is None:
            self.text_edit.clear()
            self.text_edit.setText(
                "no sword modules (=bibles) installed. please install some using the \"Sword->Module Manager\" menu entry."
            )
        else:
            self.combo_language.clear()
            self.combo_language.insertItems(0, result)

    def getTranslationsForDropdown(self, language):
        #result = self.interpreter.interpreter('sword.modules '+language, self.queue).payload
        result = self.sword.listModules(None, [language]).payload

        translations = []
        for translation in result:
            translations.append(translation[0])

        self.combo_translation.clear()
        self.combo_translation.insertItems(0, translations)

    def setDefaultBible(self):
        #sword_modules = self.interpreter.interpreter('sword.modules', self.queue).payload
        sword_modules = self.sword.listModules(None, []).payload

        for module in sword_modules:
            if module[0] == self.default_bible:
                self.combo_language.setCurrentText(module[1])
                self.combo_translation.setCurrentText(self.default_bible)

    def restoreLastBookAndChapter(self):
        last = self.history.historyReadAtIndex(3)
        try:
            translation, book, chapter = last.split(" ")

            self.combo_book.setCurrentText(book)
            self.combo_chapter.setCurrentText(chapter)

            self.showText()
        except ValueError:
            # probably we have an empty history-file
            pass

    def getBooksForDropdown(self):
        #books = self.interpreter.interpreter('sword.books', self.queue).payload
        books = self.sword.books(None, []).payload

        self.combo_book.clear()
        self.combo_book.insertItems(0, books)

    def getChaptersForDropdown(self, book):
        books = self.sword.canons()

        for testament in books:
            for _b in books[testament]:
                if _b[0] == book:
                    chapters = []
                    for i, length in enumerate(_b[3]):
                        chapters.append(str(i + 1))

                    self.combo_chapter.clear()
                    self.combo_chapter.insertItems(0, chapters)
                    break

            # if the inner 'break' was executed, we also want to break the outer loop:
            else:
                continue  # executed if the loop ended normally (no break)
            break  # executed if 'continue' was skipped (break)

    def showText(self):
        current_translation = self.interpreter.interpreter(
            'sword.getModule', self.queue).payload

        translation = self.combo_translation.currentText()
        book = self.combo_book.currentText()
        chapter = self.combo_chapter.currentText()

        if translation:
            self.interpreter.interpreter('sword.setModule ' + translation,
                                         self.queue)
            text = self.interpreter.interpreter(
                'sword.word "' + book + '" ' + chapter, self.queue)
            text = text.toString()
            self.interpreter.interpreter(
                'sword.setModule ' + current_translation, self.queue)

            self.text_edit.clear()
            self.text_edit.setText(text)
            self.text_edit.append("\nEND")
            self.text_edit.setReadOnly(True)

            self.text_edit.setTextInteractionFlags(
                self.text_edit.textInteractionFlags()
                | Qt.TextSelectableByKeyboard)

            self.unicode_fonts.applyFontAndSizeToQWidget(text, self.text_edit)

            if book and chapter:
                self.set_tab_text.emit(translation + ": " + book + " " +
                                       chapter)
                self.history.historyWrite(translation + ": " + book + " " +
                                          chapter)

    def onZoomInClicked(self):
        self.text_edit.zoomIn()

    def onZoomOutClicked(self):
        self.text_edit.zoomOut()

    def onZoomResetClicked(self):
        self.text_edit.zoomReset()
Exemplo n.º 8
0
class Biblereader(object):
	def __init__(self, Universe):#parent="MainCoreWindow", 
		createResultObject = CreateResultObject()
		self.ResultObject = createResultObject.getObject()
		#self.luther()
		BibleConfigFiles = Conf("./modules/biblereader/", "biblereader.conf")
		
		self.current_bible = BibleConfigFiles.readVar("biblereader", "standard_bible")#settings.standard_bible
		self.interpreter(self.current_bible, None)
		self.ResultObject.Payload.String = None
		
		self.SHOW_ANNOTATIONS = BibleConfigFiles.readBooleanVar("biblereader", "show_annotations")#settings.SHOW_ANNOTATIONS
		self.SHOW_VERSE_NUMBERS = BibleConfigFiles.readBooleanVar("biblereader", "show_verse_numbers") #settings.SHOW_VERSE_NUMBERS
		
		#self.history = History("./modules/biblereader/bible_history")
		#BibleConfigFiles = Conf("biblereader.conf")
		self.history = History("bible_history", Universe.ConfigFiles)
		
		#ConfigFIles
		#self.conf = Conf("biblereader.conf")
		
		self.os_name = platform.uname()[0]
	
	def getBookList(self):
		book_list = ["1mose", "2mose", "3mose", "4mose", "5mose", "josua", "richter", "rut", "1samuel", "2samuel", u"1könige", u"2könige", "1chronik", "2chronik", "esra", "nehemia", "ester", "hiob", "psalm", u"sprüche", "prediger", "hohelied", "jesaja", "jeremia", "klagelieder", "hesekiel", "daniel", "hosea", "joel", "amos", "obadja", "jona", "micha", "nahum", "habakuk", "zefanja", "haggai", "sacharja", "maleachi", u"matthäus", "markus", "lukas", "johannes", "apostelgeschichte", u"römer", "1korinther", "2korinther", "galater", "epheser", "philipper", "kolosser", "1thessalonicher", "2thessalonicher", "1timotheus", "2timotheus", "titus", "philemon", u"hebräer", "jakobusbrief", "1petrus", "2petrus", "1johannes", "2johannes", "3johannes", "judas", "offenbarung" ]
		
		return book_list
	
	def getMose(self):
		return ["1mose", "2mose", "3mose", "4mose", "5mose"]
	
	def getHistory(self):
		return ["josua", "richter", "rut", "1samuel", "2samuel", "1k�nige", "2k�nige", "1chronik", "2chronik", "esra", "nehemia", "ester"]
	
	def getTeaching(self):
		return ["hiob", "psalm", "spr�che", "prediger", "hohelied"]
	
	def getProphets(self):
		return ["jesaja", "jeremia", "klagelieder", "daniel", "hosea", "joel", "amos", "obadja", "jona", "micha", "nahum", "habakuk", "zefanja", "haggai", "sacharja", "maleachi"]
	
	def getGospel(self):
		return ["matth�us", "markus", "lukas", "johannes"]
	
	def getMail(self):
		return ["r�mer", "1korinther", "2korinther", "galater", "epheser", "philipper", "kolosser", "1thessalonicher", "2thessalonicher", "1timotheus", "2timotheus", "titus", "philemon", "hebr�er", "jakobusbrief", "1petrus", "2petrus", "1johannes", "2johannes", "3johannes", "judas"]
	
	def getBookListNumbers(self):
		return [50, 40, 27, 36, 34, 24, 21, 4, 31, 24, 22, 25, 29, 36, 10, 13, 10, 42, 150, 31, 12, 8, 66, 52, 5, 48, 12, 14, 3, 9, 1, 4, 7, 3, 3, 3, 2, 14, 4, 28, 16, 24, 21, 28, 16, 16, 13, 6, 6, 4, 4, 5, 3, 6, 4, 3, 1, 13, 5, 5, 3, 5, 1, 1, 1, 22] 
	
	def getBookDict(self):
		books_dict = {
			"1mose"		: 50,
			"2mose"		: 40,
			"3mose"		: 27,
			"4mose"		: 36,
			"5mose"		: 34,
			"josua"		: 24,
			"richter"	: 21,
			"rut"		: 4,
			"1samuel"	: 31,
			"2samuel"	: 24,
			"1könige"	: 22,
			"2könige"	: 25,
			"1chronik"	: 29,
			"2chronik"	: 36,
			"esra"		: 10,
			"nehemia"	: 13,
			"ester"		: 10,
			"hiob"		: 42,
			"psalm"	: 150,
			"sprüche"	: 31,
			"prediger"	: 12,
			"hohelied"	: 8,
			"jesaja"	: 66,
			"jeremia"	: 52,
			"klagelieder"	: 5,
			"hesekiel"	: 48,
			"daniel"	: 12,
			"hosea"		: 14,
			"joel"		: 3,
			"amos"		: 9,
			"obadja"	: 1,
			"jona"		: 4,
			"micha"		: 7,
			"nahum"		: 3,
			"habakuk"	: 3,
			"zefanja"	: 3,
			"haggai"	: 2,
			"sacharja"	: 14,
			"maleachi"	: 4,
			
			"matthäus"	: 28,
			"markus"	: 16,
			"lukas"		: 24,
			"johannes"	: 21,
			"apostelgeschichte"	: 28,
			"römer"		: 16,
			"1korinther"	: 16,
			"2korinther"	: 13,
			"galater"	: 6,
			"epheser"	: 6,
			"philipper"	: 4,
			"kolosser"	: 4,
			"1thessalonicher"	: 5,
			"2thessalonicher"	: 3,
			"1timotheus"	: 6,
			"2timotheus"	: 4,
			"titus"		: 3,
			"philemon"	: 1,
			"hebräer"	: 13,
			"jakobusbrief"	: 5,
			"1petrus"	: 5,
			"2petrus"	: 3,
			"1johannes"	: 5,
			"2johannes"	: 1,
			"3johannes"	: 1,
			"judas"		: 1,
			"offenbarung"	: 22
			}
		
		return books_dict
	
	def getBooks(self):
		books = ["genesis", "exodus", "leviticus", "numbers", "deuteronomy", "joshua", "judges", "ruth", "1samuel", "2samuel", "1kings", "2kings", "1chronicles", "2chronicles", "ezra", "nehemiah", "esther", "job", "psalms", "proverbs", "ecclesiastes", "solomon", "isaiah", "jeremiah", "lamentations", "ezekiel", "daniel", "hosea", "joel", "amos", "obadiah", "jonah", "micah", "nahum", "habakkuk", "zephaniah", "haggai", "zechariah", "malachi", "matthew", "mark", "luke", "john", "acts", "romans", "1corinthians", "2corinthians", "galatians", "ephesians", "philippians", "colossians", "1thessalonians", "2thessalonians", "1timothy", "2timothy", "titus", "philemon", "hebrews", "james", "1peter", "2peter", "1john", "2john", "3john", "jude", "revelation"]
		
		books_dict2 = {
			"1mose"		: "1_mose",
			"2mose"		: "2_mose",
			"3mose"		: "3_mose",
			"4mose"		: "4_mose",
			"5mose"		: "5_mose",
			"josua"		: "josua",
			"richter"	: "richter",
			"rut"		: "rut",
			"1samuel"	: "1_samuel",
			"2samuel"	: "2_samuel",
			"1könige"	: "1_koenige",
			"2könige"	: "2_koenige",
			"1chronik"	: "1_chronik",
			"2chronik"	: "2_chronik",
			"esra"		: "esra",
			"nehemia"	: "nehemia",
			"ester"		: "ester",
			"hiob"		: "hiob",
			"psalm"	: "psalm",
			"sprüche"	: "sprueche",
			"prediger"	: "prediger",
			"hohelied"	: "hohelied",
			"jesaja"	: "jesaja",
			"jeremia"	: "jeremia",
			"klagelieder"	: "klagelieder",
			"hesekiel"	: "hesekiel",
			"daniel"	: "daniel",
			"hosea"		: "hosea",
			"joel"		: "joel",
			"amos"		: "amos",
			"obadja"	: "obadja",
			"jona"		: "jona",
			"micha"		: "micha",
			"nahum"		: "nahum",
			"habakuk"	: "habakuk",
			"zefanja"	: "zephanja",
			"haggai"	: "haggai",
			"sacharja"	: "sacharja",
			"maleachi"	: "maleachi",
			
			"matthäus"	: "matthaeus",
			"markus"	: "markus",
			"lukas"		: "lukas",
			"johannes"	: "johannes",
			"apostelgeschichte"	: "apostelgeschichte",
			"römer"		: "roemer",
			"1korinther"	: "1_korinther",
			"2korinther"	: "2_korinther",
			"galater"	: "galater",
			"epheser"	: "epheser",
			"philipper"	: "philipper",
			"kolosser"	: "kolosser",
			"1thessalonicher"	: "1_thessalonicher",
			"2thessalonicher"	: "2_thessalonicher",
			"1timotheus"	: "1_timotheus",
			"2timotheus"	: "2_timotheus",
			"titus"		: "titus",
			"philemon"	: "philemon",
			"hebräer"	: "hebraeer",
			"jakobusbrief"	: "jakobus",
			"1petrus"	: "1_petrus",
			"2petrus"	: "2_petrus",
			"1johannes"	: "1_johannes",
			"2johannes"	: "2_johannes",
			"3johannes"	: "3_johannes",
			"judas"		: "judas",
			"offenbarung"	: "offenbarung" 
			}
		
		return books_dict2
	
	def writeToBibleHistory(self, command, args):
		hist_string = command + " " + unicode(args)
		#bible_history.historyWrite(str(str(hist_string).decode("utf8")))
		#bible_history.historyWrite(str(hist_string))
		
		self.history.historyWrite(hist_string)
	
	def readBible(self, command, args):
		books = self.getBooks()
		book = books[command]
		#book = command
		chapter = args[0]
		
		dict = self.getBookDict()
		max_num = dict[command]
		if int(chapter) > int(max_num):
			self.ResultObject.Error.Message = "Dieses Kapitel existiert nicht"
			return self.ResultObject
		
		try:
			verse = args[1].split("-")
		except:
			"EXAMPLE: 1mose 1"
			self.writeToBibleHistory(command, chapter)
			return self.readWholeChapter(book, chapter)
		else:
			if len(verse) == 1:
				"EXAMPLE: 1mose 1 2"
				return self.readOneVerse(book, chapter, verse[0])
			elif len(verse) == 2:
				"EXAMPLE: 1mose 1 2-4"
				return self.readVerseRange(book, chapter, verse)
			
		#return "dummy", "dummy"
	
	def readWholeChapter(self, book, chapter):
		query = "SELECT verse, content FROM content WHERE book=? AND chapter=? AND content NOT NULL"
		values = str(book), str(chapter)
		
		self.cursor.execute(query, values)
		result = self.cursor.fetchall()
		
		result_list = []
		mime_list = []
		for item in result:
			result_list.append( unicode(item[0]) +" "+ unicode(item[1]) )
			mime_list.append("bla")
			
		#print result_list
		self.ResultObject.Payload.List = result_list
		return self.ResultObject
		
		#return result_list, mime_list
			
	def readOneVerse(self, book, chapter, verse):
		query = "SELECT verse, content FROM content WHERE book=? AND chapter=? AND verse=? AND content NOT NULL"
		values = str(book), str(chapter), str(verse)
		
		self.cursor.execute(query, values)
		result = self.cursor.fetchall()
		
		result_string = unicode(result[0][0]) + " " + unicode(result[0][1])
		
		#result = Result()
		#payload = Payload()
		#mimeData = MimeData()
		
		#result.Payload = payload
		self.ResultObject.Payload.String = result_string
		return self.ResultObject
		#return result_string, "bla"
	
	def readVerseRange(self, book, chapter, verses):
		start_verse, stop_verse = verses[0], verses[1]
		
		query = "SELECT verse, content FROM content WHERE book=? AND chapter=? AND verse>=? AND verse<=? AND content NOT NULL"
		values = str(book), str(chapter), str(start_verse), str(stop_verse)
		
		self.cursor.execute(query, values)
		result = self.cursor.fetchall()
		
		result_list = []
		mime_list = []
		for item in result:
			result_list.append( unicode(item[0]) + " " + unicode(item[1]) )
			mime_list.append("bla")
			
		self.ResultObject.Payload.List = result_list
		return self.ResultObject	
		
		#return result_list, mime_list
	
	def isGivenPosExsistent(self, book, chapter):
		books = self.getBooks()
		dict = self.getBookDict()
		
		max_num = dict[self.command]
		
		if int(chapter) > int(max_num):
			return False
		else:
			return True
	
	def readChapter(self, command, args):
		#print args
		args1 = args[0]
			
		self.writeToBibleHistory(command, args1)
		
		books = self.getBooks()
		dict = self.getBookDict()
			
		max_num = dict[command]
		
		if int(args1) > int(max_num):
			return "Dieses Kapitel existiert nicht", "msg/else"
		
		command = books[str(command)]
		
		if self.SHOW_ANNOTATIONS:
			q1 = ", annotations "
			q3 = " verse!='-1'"
		else:
			q1 = " "
			q3 = " content NOT NULL"
		
		if self.SHOW_VERSE_NUMBERS:
			q2 = " verse, "
		else:
			q2 = " "
			
		try:
			args2 = args[1]
		except IndexError:
			query = "SELECT"+q2+"content"+q1+"FROM content WHERE book=? AND chapter=? AND"+q3
			value = str(command), str(args1)
		else:
			if str(args2)[1] == "-":
				query = "SELECT"+q2+"content"+q1+"FROM content WHERE book=? AND chapter=? AND verse>=? AND verse<=? AND"+q3
				splitted = args2.split("-")
				range_start, range_end = splitted[0], splitted[1]
				value = str(command), str(args1), range_start, range_end
				#print value
			else:
				query = "SELECT"+q2+"content"+q1+"FROM content WHERE book=? AND chapter=? AND verse=? AND"+q3
				value = str(command), str(args1), str(args2)
		
		#if self.SHOW_ANNOTATIONS:
		#	query = "SELECT verse, content, annotations FROM content WHERE book=? and chapter=? and verse!='-1'"
		#else:
		#	query = "SELECT verse, content FROM content WHERE book=? and chapter=? and content not null"
			
		
		self.cursor.execute(query, value)
		result = self.cursor.fetchall()
		
		result_list = []
		mime_list = []
		for i in range(0, len(result)):
			if self.SHOW_VERSE_NUMBERS:
				if self.SHOW_ANNOTATIONS:
					if unicode(result[i][1]) == "None":
						result_list.append( unicode(result[i][2]) )
						mime_list.append( "bible/annotation" )
					else:
						result_list.append( unicode(result[i][0]) +" "+ unicode(result[i][1]) )
				else:
					result_list.append( unicode(result[i][0]) +" "+ unicode(result[i][1]) )
					mime_list.append("data/text")
			else:
				if self.SHOW_ANNOTATIONS:
					if unicode(result[i][0]) == "None":
						result_list.append( unicode(result[i][1]) )
						mime_list.append("bible/annotation")
					else:
						result_list.append( unicode(result[i][0]) )
						mime_list.append("data/text")
					
				else:
					result_list.append(unicode(result[i][0]))
					mime_list.append("data/text")
		
		return result_list, mime_list
	
	
	
	def commandNotFound(self):
		#return "-1", "error/not_found"
		raise CommandNotInThisModule("command not found in the module biblereader.py")
	
	def getCommands(self):
		commands =  {
				"bible" : self.retBible,
				"getCurrentBible" : self.retCurrentBible,
				"bible.history" : self.retHistory,
				
				"elberfelder" : self.elberfelder,
				"luther" : self.luther,
				"evangelistische" : self.evangelistische,
				"schlachter" : self.schlachter,
				
				"books" : self.books,
				"next" : self.next,
				"n" : self.next,
				"prev" : self.prev,
				"self" : self.retSelf,
				"search" : self.search,
				
				"annotations": self.annotations,
				"versenumbers" : self.versenums,
				
				"commands" : self.printCommands,
				}
		
		return commands
	
	def interpreter(self, command, args):
		#command = command.lower()
		books = self.getBooks()
		self.args = args
		
		try:
			if command.lower() in books:
				return self.readBible(command, args)
		except IndexError:
			self.ResultObject.Error.Message = "Parameter inakzeptabel, bitte Kapitel angeben"
			return self.ResultObject
		
		else:
			commands = self.getCommands()
			return commands.get(command, self.commandNotFound)()
	
	def printCommands(self):
		dict = self.getCommands()
		
		
		commands = sorted(dict.items())
		
		all_commands2 = []
		mime_list = []
		line = ""
		for key in commands:
			line = str(key).split(",")[0]
			all_commands2.append(str(line[2:-1]))
			mime_list.append("command/default")
			
		return all_commands2, mime_list
	
	def elberfelder(self):
		self.connection = sqlite3.connect("./modules/biblereader/elberfelder_1905.db")
		self.cursor = self.connection.cursor()
		self.current_bible = "elberfelder"
		self.ResultObject.Payload.String = "elberfelder aktiviert"
		return self.ResultObject
	def luther(self):
		self.connection = sqlite3.connect("./modules/biblereader/lutherbibel_1912.db")
		self.cursor = self.connection.cursor()
		self.current_bible = "luther"
		self.ResultObject.Payload.String = "lutherbibel aktiviert"
		return self.ResultObject
	def evangelistische(self):
		self.connection = sqlite3.connect("./modules/biblereader/neue_evangelistische.db")
		self.cursor = self.connection.cursor()
		self.current_bible = "evangelistische"
		self.ResultObject.Payload.String = "neue evangelistische aktiviert"
		return self.ResultObject
	def schlachter(self):
		self.connection = sqlite3.connect("./modules/biblereader/schlachter_1951.db")
		self.cursor = self.connection.cursor()
		self.current_bible = "schlachter"
		self.ResultObject.Payload.String = "schlachter aktiviert"
		return self.ResultObject
	def retBible(self):
		self.ResultObject.Payload.List = ["elberfelder", "luther", "evangelistische", "schlachter"]
		return self.ResultObject
	def retCurrentBible(self):
		self.ResultObject.Payload.String = self.current_bible
		return self.ResultObject
	
	def books(self):
		books = self.getBookList()
		numbers = self.getBookListNumbers()
		
		output = []
		metaData_list = []
		for i in range (0, len(books)):
			output.append( unicode( books[i] ) + " " + unicode( numbers[i] ) )
			#mime_list.append("command/bible")
			
			metaData = MetaData()
			metaData.Language = "default"
			metaData.ExecuteCommand = "%CONTENT%"
			
			metaData_list.append(metaData)
			
		#books = self.getBookList()
		
		self.ResultObject.Payload.List = output
		self.ResultObject.Description.List = metaData_list
		return self.ResultObject
	
	def next(self):
		return self.nextSelfPrevHelper(1)
		
	def prev(self):
		return self.nextSelfPrevHelper(-1)
		
	def retSelf(self):
		return self.nextSelfPrevHelper(0)
	
	def nextSelfPrevHelper(self, index):
		hist = self.history.history(1, None)
		
		#print hist
		
		splitted = hist.split(" ")
		book = splitted[0]
		try:
			chapter = int( splitted[1] )
		except IndexError:
			self.ResultObject.Error.Message = "biblereader -> Interpreter -> IndexError"
			return self.ResultObject
		
		resultObject = self.readBible(book, [chapter+index])
		
		result_list = resultObject.Payload.List
		if result_list != None:
			result_list.insert(0, book.decode("utf8") + " " + str(int(chapter)+index))
			resultObject.Payload.List = result_list
		
		return resultObject
	
	def searchWholeBible(self):
		#print "biblereader/search2: ", self.args[0]
		query = "SELECT book, chapter, verse, content FROM content WHERE content like '%"+self.args[0]+"%'"
		
		self.cursor.execute(query)
		result = self.cursor.fetchall()
		
		return self.searchResultFormatter(result)
	
	def searchInOneBook(self, book_to_search_in, format_result):
		
		book_list = self.getBookList()
		
		if book_to_search_in in book_list:
			books = self.getBooks()
			book = books[book_to_search_in]
			query = "SELECT book, chapter, verse, content FROM content WHERE content like '%"+self.args[0]+"%' AND book='"+book+"'"
			#print "search3 query: ", query
			self.cursor.execute(query)
			result = self.cursor.fetchall()
			
			if format_result:
				return self.searchResultFormatter(result)
			else:
				return result
	
	def searchResultFormatter(self, result):
		metaData = MetaData()
		metaData_list = []
		result_list = [str(len(result)) + " Ergebnisse gefunden"]
		metaData.Language = "de"
		metaData_list.append(metaData)
		
		for i in range (0, len(result)):
			metaData1 = MetaData()
			metaData2 = MetaData()
			
			res1 = unicode(result[i][0])
			
			d = self.getBooks()
			for k in d:
				if d[k] == res1:
					res1 = k#.decode("utf8")
					
			res2 = unicode(result[i][1])
			res3 = unicode(result[i][2])
			result_helper = unicode(result[i][3])
			result_list.append(res1 + " " + res2 + "," + res3)
			metaData1.ExecuteCommand = "%CONTENT%"
			metaData_list.append(metaData1)
			#mime_list.append("bible/pos")
			#result_list.append(res1 + " kapitel " + res2 + " vers " + res3)
			result_list.append(result_helper)
			
			metaData_list.append(metaData2)
				
		self.ResultObject.Payload.List = result_list
		self.ResultObject.Description.List = metaData_list
		return self.ResultObject
	
	def searchInBookRange(self, book_start, book_end):
		book_list = self.getBookList()
		try:
			book_start_index = book_list.index(book_start)
		except ValueError:
			self.ResultObject.Error.Message = "Buch '" + str(book_start) + "' konnte nicht als Buch der Bibel identifiziert werden"
			return self.ResultObject
		try:
			book_end_index = book_list.index(book_end)
		except ValueError:
			self.ResultObject.Error.Message = "Buch '" + str(book_end) + "' konnte nicht als Buch der Bibel identifiziert werden"
			return self.ResultObject
		
		result_list = []
		i = book_start_index -1
		while i < book_end_index:
			i += 1
			
			current_book = book_list[i]
			#books_to_search_in.append(current_book)
			
			result = self.searchInOneBook(current_book, False)
			result_list.append(result)
			
		format_list = []
		for item in result_list:
			for item2 in item:
				format_list.append(item2)
		
		return self.searchResultFormatter(format_list)
	
	def search(self):
		
		if len(self.args) == 1:
			return self.searchWholeBible()
		
		elif len(self.args) == 3:
			if self.args[1] == "in":
				
				if self.args[2].find("-") > -1:
					splitted = self.args[2].split("-")
					return self.searchInBookRange(splitted[0], splitted[1])
				
				else:
					return self.searchInOneBook(self.args[2], True)
		
	def retHistory(self):
		try:
			count = self.args[0]
		except IndexError:
			count = 20
			
		result_list, mime_list = self.history.history_inverted(count)
		
		self.ResultObject.Payload.List = result_list
		return self.ResultObject
				
	def annotations(self):
		if self.SHOW_ANNOTATIONS:
			self.SHOW_ANNOTATIONS = False
			self.ResultObject.Payload.String = "verweise deaktiviert"
			return self.ResultObject
		else:
			self.SHOW_ANNOTATIONS = True
			self.ResultObject.Payload.String = "verweise aktiviert"
			return self.ResultObject
		
	def versenums(self):
		if self.SHOW_VERSE_NUMBERS:
			self.SHOW_VERSE_NUMBERS = False
			self.ResultObject.Payload.String = "versnummern deaktiviert"
			return self.ResultObject
		else:
			self.SHOW_VERSE_NUMBERS = True
			self.ResultObject.Payload.String = "versnummern aktiviert"
			return self.ResultObject