def __init__(self, name, room): self.action_index = ACTION_INDEX self.base_defense = 10 self.attack = 0.01 self.xp = 0 self.level = 1 self.xp_to_level = self.set_xp_to_level() self.constitution = 10 self.dexterity = 10 self.intelligence = 10 self.strength = 10 self.find_traps = 50 self.turn_counter = 1 self.max_hp = self.set_max_hp() # TODO: Figure out how to calculate Stamina and Mana; # TODO: Implement stamina and mana drain from certain abilities. # TODO: Implement stamina and mana regen during advance_turn(). self.stamina = 0 self.mana = 0 self.inventory = Inventory() self.journal = Journal() self.explored_rooms = dict() self.cooldowns = dict() self.messages = None super().__init__(name, room, max_hp=self.max_hp) self.assign_room(room)
def test_Journal(): j = Journal() e = loadfromjson(sample_json) j.append(e) dr, cr = j.getTAccount(u"現金") assert cr[1439517320] == 100000
def test_journal_add_new_content(): if os.path.exists(file_path): os.remove(file_path) entry_1 = 'This is my first entry journal entry' expected = 'Your 1 journal entry\n\n1. {}\n'.format(entry_1) journal = Journal() journal.add(entry_1) actual = journal.list() assert expected == actual
def main(): # def __init__(self, title, call_no, author, num_copies): # issue, publisher): # def __init__(self, title, call_no, author, num_copies, name, # issue, publisher): b1 = Book("Provenance", "342.2", "Anne Leckie", 20) b2 = Book("Ancillary Justice", "342.2A", "Anne Leckie", 1) j1 = Journal("Individual Psychology", "123.4", "Gabriela Pap", 1, "Journal of Psychology", 23, "SAGE Publications") d1 = Dvd("Mad Max: Fury Road", "789.0", "George Miller", 8, "May 15, 2015", "1") cat = Catalogue({ "342.2": Book("Provenance", "342.2", "Anne Leckie", 20), "342.2A": Book("Ancillary Justice", "342.2A", "Anne Leckie", 1), "123.4": Journal("Individual Psychology", "123.4", "Gabriela Pap", 1, "Journal of Psychology", 23, "SAGE Publications"), "789.0": Dvd("Mad Max: Fury Road", "789.0", "George Miller", 8, "May 15, 2015", "1") }) vpl = Library(cat) display_menu = True while display_menu: print("What would you like to do?") print("1. Find item by title (String)") print("2. Add item to catalogue") print("3. Remove item from catalogue (call no)") print("4. Check out a copy (call no)") print("5. Return your copy (call no)") print("6. Display library catalogue") print("7. Quit menu") choice = int(input("Select action: ")) if choice == 2: vpl.get_cat().add_item() elif choice == 6: vpl.display_available_books() elif choice == 7: display_menu = False elif choice not in range(1, 6): print("\nInvalid input. Try again.\n") else: par = input("Enter parameter: ") input_dict = { 1: vpl.search, 3: cat.remove_item, 4: vpl.check_out, 5: vpl.return_item } print(input_dict.get(choice)(par))
def loadJournals(self): journalList = [] first = True with open(self._journalCsv, 'rb') as csvfile: journalReader = csv.reader(csvfile) for row in journalReader: if first: first = False continue journal = Journal(self._xLen, self._yLen, self._zLen) print "{} {} {} {} {} {} {} {}".format( \ row[0], row[1], row[2], row[3], \ row[4], row[5], row[6], row[7]) # Timestamp = row[0] journal.work_text = row[1].strip() journal.misc_text = row[2].strip() journal.eventful = int(row[3]) journal.moods = self.parseMoodList(row[4], journal) date = row[5] time = row[6] journal.setTimeSec(self.parseDateTime(date, time)) journal.weights = [int(w) for w in row[7].split(",")] journalList.append(journal) self._journalList = journalList print "list: " + str(len(journalList)) + " self: " + str(len(self._journalList)) return journalList
def __init__(self, xLen, yLen, zLen, journalCsv): self._xLen = xLen self._yLen = yLen self._zLen = zLen self._journalCsv = journalCsv self._moodFactory = MoodFactory(self._xLen, self._yLen, self._zLen) self._journalList = [] self._testJournal = Journal(self._xLen, self._yLen, self._zLen, 0) self._testJournal.addMood(self._moodFactory.makeMood("TestMood"), 100)
def loadgame(self, slot): self.setsavedir(slot) self.player = Player(load_yaml('player','player.yaml')) debug(self.player.get_hash()) self.journal = Journal(json.loads(open(file_path('journal', 'journal.yaml')).read())) self._rmtemp()
def test_journal_save(): if os.path.exists(file_path): os.remove(file_path) expected = True Journal().save() actual = os.path.exists(file_path) assert expected == actual
def generate_item(call_num): user_input = None # If entered invalid option, loops user back to choices below while user_input != 4: print("What type of item would you like to add") print("1. Book") print("2. DVD") print("3. Journal") print("4. Back") string_input = input("Please enter your choice (1-4)") user_input = int(string_input) title = input("Enter title: ") num_copies = int(input("Enter number of copies (positive number): ")) item_data = (call_num, title, num_copies) # creates the item object of input choice if user_input == 1: author = input("Enter Author Name: ") return Book(item_data[0], item_data[1], item_data[2], author) if user_input == 2: release_date = input("Enter release date (yyyy/mm/dd): ") code = input("Enter region code: ") return DVD(item_data[0], item_data[1], item_data[2], release_date, code) if user_input == 3: names = input("Enter names") issue_number = input("Please enter issue number") publisher = input("Enter publisher") return Journal(item_data[0], item_data[1], item_data[2], names, issue_number, publisher) # return to menu if user_input == 4: pass
def main(): """ Prints the app header, loads the journal and starts the program loop. """ ui.print_header() journal = Journal.load(journal_file_name) run_program_loop(journal)
def create_item(): """ Creates an item. :return: an item """ print( "What kind of items would you like to add to the library catalogue?" ) print("1. Book") print("2. DVD") print("3. Journal") option = int(input("Select type of item: ")) title = input("Enter title: ") call_num = input("Enter call number: ") author = input("Enter author name: ") num_copies = input("Enter the number of copies: ") if option == 1: return Book(call_num, title, num_copies, author) if option == 2: release_date = input("Enter release date: ") region_code = input("Enter region code: ") return Dvd(call_num, title, num_copies, author, release_date, region_code) if option == 3: names = input("Enter name: ") issue_number = input("Enter issue number: ") publisher = input("Enter publisher: ") return Journal(call_num, title, num_copies, author, names, issue_number, publisher)
def generate_test_items(): """ Return a list of items with dummy data. :return: a list """ kwargs1 = { "call_num": "100.200.300", "title": "Harry Potter 1", "num_copies": 2 } kwargs2 = { "call_num": "425.63.775", "title": "Toy Story", "num_copies": 2 } kwargs3 = { "call_num": "874.234.863", "title": "Science Journal", "num_copies": 5 } item_list = [ Book("J K Rowling", **kwargs1), Dvd("10-10-2004", "NA", **kwargs2), Journal("Dr. Smart", 7, "Pearsons", **kwargs3) ] return item_list
def get_fresh_journal_list(scenario, my_jwt): from package import Package my_package = Package.query.filter( Package.package_id == scenario.package_id).scalar() journals_to_exclude = ["0370-2693"] issn_ls = scenario.data["unpaywall_downloads_dict"].keys() issnls_to_build = [ issn_l for issn_l in issn_ls if issn_l not in journals_to_exclude ] # only include things in the counter file if my_package.is_demo: issnls_to_build = [ issn_l for issn_l in issnls_to_build if issn_l in scenario.data[DEMO_PACKAGE_ID]["counter_dict"].keys() ] package_id = DEMO_PACKAGE_ID else: issnls_to_build = [ issn_l for issn_l in issnls_to_build if issn_l in scenario.data[ scenario.package_id]["counter_dict"].keys() ] package_id = scenario.package_id journals = [ Journal(issn_l, package_id=package_id) for issn_l in issnls_to_build if issn_l ] for my_journal in journals: my_journal.set_scenario(scenario) return journals
def create_item(): """ Create Item based on user input. :return: as Item """ print("What type of item would you like to add to" "the library catalogue?") print("1. Book") print("2. DVD") print("3. Scientific Journal") choice = int(input("Select type of item: ")) title = input("Enter title: ") call_no = input("Enter call number: ") author = input("Enter author name: ") num_copies = input("Enter the number of copies: ") if choice == 1: return Book(title, call_no, author, num_copies) if choice == 2: release = input("Enter release date: ") region = input("Enter region code: ") return Dvd(title, call_no, author, num_copies, release, region) if choice == 3: name = input("Enter name of publication: ") issue = input("Enter issue number: ") publisher = input("Enter publisher: ") return Journal(title, call_no, author, num_copies, name, issue, publisher)
def __init__(self, sanityModel, startSimThread=True): self.journal = Journal(sanityModel) self.simulation = Simulation(sanityModel, startSimThread) self.localTargets = { 'simulation': marshal.channel(self.simulation), 'journal': marshal.channel(self.journal), }
def create_journal(item_info: dict) -> Journal: """ Creates a Journal. """ issue_number = input("Enter Issue Number: ") publisher = input("Enter Publisher Name: ") item_info["issue_number"] = issue_number item_info["publisher"] = publisher return Journal(**item_info)
def run_event_loop(): my_journal = Journal('personal') command = query_user() while command != 'x': if command == 'l': my_journal.list() elif command == 'a': my_journal.add(input('Enter your journal entry:\n')) command = query_user() my_journal.save()
def __init__(self, frontend): self.frontend = frontend Tempsprites.__init__(self) self.homedir = os.path.join(os.getenv('HOME'), '.mirthless') self.player = Player({}) self.cleanuplist = [] template = load_yaml('rules','template_character.yaml') self.portrait = template['personal/portrait'] self.journal = Journal() characters = []
def create_journal() -> Journal: """ Creates a Journal. """ call_number = input("Enter Call Number: ") title = input("Enter Journal Name: ") num_copies = int(input("Enter Number of Copies: ")) issue_number = input("Enter Issue Number: ") publisher = input("Enter Publisher Name: ") return Journal(call_number, title, num_copies, issue_number, publisher)
def find(_opts, _args): for d, b, q in Utils.iterate_dirs(_args, _dirs=False, _files=True): ## for p in _args: ## for t, d, f in os.walk(p): ## Utils.prune(d) ## for y in f: ## q = os.path.join(t, y) # skip files that are too large, or empty if _opts.maxsize and os.path.getsize(q) > _opts.maxsize \ or os.path.getsize(q) == 0 : logging.warn("Skipping %s %d" % (q, os.path.getsize(q))) continue # calculate checksum s = checksum(q) # remove entries for which the corresponding file is missing existing_entries = [] for p in Sums.find(s): # p is pathname (dirpath + filename) if p==q: continue if not os.path.isfile(p): Sums.remove(p) else: existing_entries.append(p) # if we actually found something existing if existing_entries: logging.debug("duplicate files:") logging.debug("\t%s" % (q)) for x in existing_entries: logging.debug("\t%s" % (x)) Counters.counts["bytes_saved"] += os.path.getsize(q) Journal.emit(Journal.Move(q, Utils.trashpath(q))) # remove the file (must be explicitly asked for) if _opts.delete: Utils.trash(q) Sums.remove(q) logging.info("%d bytes saved" % Counters.counts["bytes_saved"])
def create(): title = input("Enter a title: ") call_num = input("Enter a call number: ") num_copies = input("Enter number of copies: ") issue = input("Enter Issue Number: ") publisher = input("Enter Publisher Name: ") return Journal(title=title, call_num=call_num, num_copies=num_copies, issue_number=issue, publisher=publisher)
def run_program_loop(journal: Journal): """ Runs the program loop: asking the user what do to, until the user chooses to exit the app. :param journal: The Journal object to work with :return: """ cmd = "." while cmd and cmd != "x": cmd = ui.read_menu_input() if cmd == "l": ui.print_entries(journal.entries) elif cmd == "a": text = ui.read_add_entry_input() journal.add_entry(text) elif cmd == "x": journal.save(journal_file_name) exit(0)
def add_journal(self): """ Add a brand new journal to the library with a unique call number. :return: a Journal """ journal_data = self.add_basic_info() issue_number = input("Enter Issue Number: ") publisher = input("Enter publisher") new_journal = Journal(journal_data[0], journal_data[1], journal_data[2], issue_number, publisher) return new_journal
def create_journal(self): key = self.ui.linePassphrase.text() if len(key) <= 0: return self.ui.grpPassphrase.hide() self.ui.grpJournal.show() self.ui.toolBar.show() self._journal = Journal(key) self.fill_journal_list()
def test_journal_list(): if os.path.exists(file_path): os.remove(file_path) entry_1 = 'This is my first entry journal entry' entry_2 = 'Now we have excellent history features.' entry_3 = 'What a sunny Saturday. Time for some exercise!' entries = [entry_1, entry_2, entry_3] listing = '1. {}\n2. {}\n3. {}\n'.format(entry_3, entry_2, entry_1) expected = 'Your 3 journal entries\n\n{}'.format(listing) actual = Journal(entries).list() assert expected == actual
def create_item(self): call_number = input("Enter Call Number: ") title = input("Enter title: ") num_copies = int(input("Enter number of copies " "(positive number): ")) author = input("Enter Author Name: ") issue_number = input("Enter Issue Number: ") publisher = input("Enter Publisher: ") kwargs = {"call_num": call_number, "title": title, "num_copies": num_copies} new_journal = Journal(author, issue_number, publisher, kwargs) return new_journal
def generate_test_items(): """ Return a list of items with dummy data. :return: a list """ item_list = [ Book("100.200.300", "Harry Potter 1", 2, "J K Rowling"), Book("999.224.854", "Harry Potter 2", 5, "J K Rowling"), Journal("631.495.302", "Harry Potter 3", 4, "53434", "Router"), DVD("123.02.204", "The Cat in the Hat", 1, "2014-01-05", "342DV") ] return item_list
def create_journal(cls): """ Prompts user to create a dvd item :return: a dvd item """ title = input("input journal title\n") call_num = input("input journal call number\n") num_copies = input("input number of copies\n") issue_num = input("input issue number\n") publisher = input("input publisher\n") return Journal(title, call_num, int(num_copies), issue_num, publisher)
def main(): journal = Journal() menu = Menu() selection = menu.prompt() while selection != 'x': if selection == 'l': print(journal.list()) elif selection == 'a': journal.add(input('Enter your journal entry:\n')) selection = menu.prompt() journal.save()
def create_item(self): item_type = input("Enter an item type:\n1: Book\n2: Dvd\n3: Journal") item = "invalid input given" if item_type == "1": item = Book(self._title, input("Enter Authour name: "), self._call_num, self._num_copies) elif item_type == "2": item = DVD(self._title, input("Enter Release Date: "), input("Enter Region Code: "),\ self._call_num, self._num_copies) elif item_type == "3": item = Journal(self._title, input("Enter Issue Number: "), input("Enter Publisher Name: "), self._call_num, self._num_copies) return item
def generate_test_books() -> list: """ Return a list of books with dummy data. :return: a list """ book_list = [ Book("100.200.300", "Harry Potter 1", 2, "J K Rowling"), Book("999.224.854", "Harry Potter 2", 5, "J K Rowling"), Book("631.495.302", "Harry Potter 3", 4, "J K Rowling"), Book("123.02.204", "The Cat in the Hat", 1, "Dr. Seuss"), Journal("100.132.126", "My Travel", 5, "123.1231.614a", "Luke"), DVD("123.456.123", "My Dream", 10, "2020-03-10", "123") ] return book_list
def generate_test_items(): """ Return a list of items with dummy data. :return: a list """ item_list = [ Book("100.200.300", "Harry Potter 1", 2, "J K Rowling"), Book("999.224.854", "Harry Potter 2", 5, "J K Rowling"), Book("631.495.302", "Harry Potter 3", 4, "J K Rowling"), Book("123.02.204", "The Cat in the Hat", 1, "Dr. Seuss"), Dvd("425.63.775", "Toy Story", 2, "10-10-2004", "NA"), Journal("874.234.863", "Science Journal", 1, "Dr. Smart", 7, "Pearsons") ] return item_list
def test_journal_save_content(): if os.path.exists(file_path): os.remove(file_path) entry_1 = 'This is my first entry journal entry' expected = '{}\n'.format(entry_1) journal = Journal() journal.add(entry_1) journal.save() actual = open(file_path, 'r').read() assert expected == actual
def __create_journal(): """ Creates a journal :return: a journal """ call_number = input("Enter Call Number: ") title = input("Enter title: ") num_copies = int(input("Enter number of copies " "(positive number): ")) author = input("Enter Author Name: ") issue_number = input("Enter Issue Number: ") publisher = input("Enter Publisher: ") new_journal = Journal(call_number, title, num_copies, author, issue_number, publisher) return new_journal
def login(u_name, password): user_details = file_obj.readFile() print("Received Password") print(password) rec_password = crypto.decrypt(password) print("Decrypted Password") print(rec_password) print(type(password)) journal_flow = 0 for user in user_details: # if user["uname"] == u_name and user["password"] == password: f_uname = user['uname'] f_pass = user["password"] f_pass = crypto.decrypt(f_pass) if f_uname==u_name and f_pass==rec_password: print("Authentication Successful!") journal_flow = 1 break if journal_flow == 0: print("login failed") login_new() else: while journal_flow == 1: list_or_create = int(input("\n Press 1 for listing previous entries \n Press 2 for creating new entry \n Press 3 to login as new User \n Press 5 to exit application \n")) if list_or_create == 1: print("list codde") journal_obj = Journal(u_name) entries = journal_obj.read_journal() print("entries are ", entries) elif list_or_create == 2: print("create code") j_entry = str(input("\n Write an entry for the journal")) journal_obj = Journal(u_name) journal_obj.write_entry(j_entry) print("entry written") elif list_or_create == 3: journal_flow = 0 login_new() elif list_or_create == 5: break else: journal_flow = 1 print("invalid input")
class Game(Tempsprites): livecharacters = [] def __init__(self, frontend): self.frontend = frontend Tempsprites.__init__(self) self.homedir = os.path.join(os.getenv('HOME'), '.mirthless') self.player = Player({}) self.cleanuplist = [] template = load_yaml('rules','template_character.yaml') self.portrait = template['personal/portrait'] self.journal = Journal() characters = [] def mainwindow(self): rect = self.frontend.screensize self.main = FloatDialog(rect, self.frontend, layer=5) self._addtemp('MainMenu',self.main) self.cleanuplist = [] newgame = Button('New Game', self.newgame, [], self.frontend.eventstack, self.frontend.imagecache, pos=(20,20), layer=6, fontsize=16) self._addtemp('newgamebtn', newgame) loadgamelbl = Label('Load Game:',(20,50), layer=6) self._addtemp('loadgamelbl', loadgamelbl) rect = pygame.Rect(20,80, 300, 30) loadslots = Dropdown( self.frontend.eventstack, self.frontend.imagecache, 16, rect, os.listdir(self.homedir), layer=6, onselect=self.loadgame) self._addtemp('loadgame', loadslots) def setsavedir(self, slot): self.slot = slot self.savedir = os.path.join(self.homedir,slot) debug('Game save directory:', self.savedir) if not os.path.exists(self.savedir): os.makedirs(self.savedir) gamedir.insert(0,self.savedir) def clearwindow(self): for sprite in self.cleanuplist: if sprite in self.frontend.sprites: self.frontend.sprites[sprite].delete() del self.frontend.sprites[sprite] def _addtemp(self, title, obj): self.cleanuplist.append(title) Tempsprites._addtemp(self, title, obj) def newgame(self): self.clearwindow() self.player = Player({}) self.main.image.blit(render_text('Nyrac City Jail: Prisoner Record',64),(20,20)) firstnamelbl = Label('First name:', (20, 150), layer=6) self._addtemp('firstnamelbl', firstnamelbl) firstname = TextInput(pygame.Rect(100,150,100,30), 16, self.frontend.eventstack, layer=6) self._addtemp('firstname', firstname) lastnamelbl = Label('Last name:', (20, 190), layer=6) self._addtemp('lastnamelbl', lastnamelbl) lastname = TextInput(pygame.Rect(100,190,100,30), 16, self.frontend.eventstack, layer=6) self._addtemp('lastname', lastname) portrait = BlitButton( self.nextportrait, [], self.frontend.eventstack, self.frontend.imagecache, self.portrait, pos=(210,150), scale=128, layer=7 ) self._addtemp('portrait', portrait) sexlbl = Label('Sex', (20,230)) self._addtemp('sexlbl', sexlbl) sex = Dropdown(self.frontend.eventstack, self.frontend.imagecache, 16, pygame.Rect(100,230,100,30), ['male','female'], layer=18) self._addtemp('sex', sex) pclasslbl = Label('Class:',(340,150)) self._addtemp('pclasslbl', pclasslbl) playerclass = Dropdown(self.frontend.eventstack, self.frontend.imagecache, 16, pygame.Rect(420,150,200,30), PLAYER_CLASSES, layer=17) self._addtemp('playerclass', playerclass) racelbl = Label('Race:',(340,190)) self._addtemp('racelbl',racelbl) race = Dropdown(self.frontend.eventstack, self.frontend.imagecache, 16, pygame.Rect(420,190,200,30), ['human','elf','dwarf','half-elf','halfling','gnome','orc','goblin'], layer=16) self._addtemp('race', race) alignmentlbl = Label('Alignment', (340,230)) self._addtemp('alignmentlbl', alignmentlbl) alignment = Dropdown(self.frontend.eventstack, self.frontend.imagecache, 16, pygame.Rect(420,230,200,30), ['lawful-evil', 'neutral-evil', 'chaotic-evil'], layer=15) self._addtemp('alignment', alignment) create = Button('Create Character', self.createchar, [], self.frontend.eventstack, self.frontend.imagecache, pos=(210,350), layer=6, fontsize=16) self._addtemp('createchar', create) def createchar(self): def value(key): return self.frontend.sprites[key].value self.player.put('personal/name/first', value('firstname')) self.player.put('personal/name/last', value('lastname')) self.player.put('personal/portrait', self.portrait) self.player.put('personal/sex', value('sex')) playerclass = value('playerclass') or choice(PLAYER_CLASSES) playerclass = playerclass.split(':') debug(playerclass) self.player.put('class/parent', playerclass[0]) self.player.put('class/class', playerclass[1]) template = load_yaml('rules','template_character.yaml') for key in template: k = None if key.startswith('conditional/class.parent=%s/' %playerclass[0]): k = key.replace('conditional/class.parent=%s/' %playerclass[0],'') elif key.startswith('conditional/class.class=%s/' %playerclass[1]): k = key.replace('conditional/class.class=%s/' %playerclass[1],'') if k is not None and k != 'class.class': self.player.put(k, template[key]) if key.startswith('inventory'): self.player.put(key, template[key]) if key.startswith('__Yinventory'): k = key.replace('__Y', '') self.player.put(k, template[key]) slot = str(len(os.listdir(self.homedir))) self.setsavedir(slot) armor = Item(load_yaml('items', 'ab7ed2a7e93bae020aeaab893902702fc0727b0079ecd3a14aa4a57c.yaml')) armor = self.player.acquire_item(armor) self.player.equip_item(armor) debug(self.player()) firstmap = GameMap(load_yaml('maps', 'f1440bb0f6826a470c385218d19515ad937c1d7ab4ad3e0c71206238')) self.player.moveto(firstmap, 18, 1) firstmap.savetoslot('maps') animations = load_yaml('rules', 'default_sprites') for k,v in animations[playerclass[0]].items(): self.player.put(k, v) self.player.savetoslot() self.journal.write('Prison') self._rmtemp() def nextportrait(self): portraitlist = [i for i in self.frontend.imagecache.keys() if i.startswith('portrait_')] idx = portraitlist.index(self.portrait) idx += 1 if idx >= len(portraitlist) -1: idx = 0 self.portrait = portraitlist[idx] self.player.put('personal/portrait', self.portrait) self.newgame() def loadgame(self, slot): self.setsavedir(slot) self.player = Player(load_yaml('player','player.yaml')) debug(self.player.get_hash()) self.journal = Journal(json.loads(open(file_path('journal', 'journal.yaml')).read())) self._rmtemp()
class CryptJournal(QtGui.QMainWindow): def __init__(self): super(CryptJournal,self).__init__() self._journal = None self._editing = False self._editing_id = -1 self._loaded = -1 self.ui = Ui_CryptJournal() self.ui.setupUi(self) self.ui.grpJournal.hide() self.ui.grpEdit.hide() self.ui.textEntry.hide() self.ui.toolBar.addAction(self.ui.actionAdd) self.ui.toolBar.addAction(self.ui.actionEdit) self.ui.toolBar.addAction(self.ui.actionDelete) self.ui.toolBar.addAction(self.ui.actionHide) self.ui.toolBar.hide() self.ui.linePassphrase.returnPressed.connect(self.create_journal) self.ui.actionAdd.triggered.connect(self.add) self.ui.actionDelete.triggered.connect(self.delete) self.ui.actionEdit.triggered.connect(self.edit) self.ui.buttonBox.clicked.connect(self.handle_add_buttons) self.ui.listEntries.itemDoubleClicked.connect(self.load_journal_entry) self.ui.listEntries.itemActivated.connect(self.load_journal_entry) self.show() def create_journal(self): key = self.ui.linePassphrase.text() if len(key) <= 0: return self.ui.grpPassphrase.hide() self.ui.grpJournal.show() self.ui.toolBar.show() self._journal = Journal(key) self.fill_journal_list() def fill_journal_list(self): self.ui.listEntries.clear() for entry in self._journal: item = QtGui.QListWidgetItem() item.setSizeHint(QtCore.QSize(0,65)); self.ui.listEntries.addItem(item) self.ui.listEntries.setItemWidget(item, JournalEntry(data=entry)) def load_journal_entry(self, entry): data = self.ui.listEntries.itemWidget(entry).data() if self.ui.textEntry.isVisible() and self._loaded == data["id"]: self._loaded = -1 self.ui.textEntry.hide() return html = "<h1>"+data["title"]+"</h1>\n" html += "<h3><i>Last modified: "+data["date"]+"</i></h3>" html += self.parse_text(data["data"]) self.ui.textEntry.setHtml(html) self.ui.textEntry.show() self._loaded = data["id"] def parse_text(self, text): parts = docutils.core.publish_parts(text, writer_name="html") html = parts['body'] return html def add(self): self.ui.grpEdit.show() self.ui.lineTitle.setFocus() def delete(self): entry = self.ui.listEntries.currentItem() if entry is None: return res = QtGui.QMessageBox.question(self,"Are you sure?",\ "Are you sure you want to delete this entry?",\ QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if res != QtGui.QMessageBox.Yes: return data = self.ui.listEntries.itemWidget(entry).data() self._journal.remove(data["id"]) self.fill_journal_list() def edit(self): entry = self.ui.listEntries.currentItem() if entry is None: return self.ui.textEntry.hide() data = self.ui.listEntries.itemWidget(entry).data() self._editing = True self._editing_id = data["id"] self.ui.lineTitle.setText(data["title"]) self.ui.textData.setPlainText(data["data"]) self.ui.grpEdit.show() self.fill_journal_list() def handle_add_buttons(self, button): if button.text() == "Save": if self._editing and self._editing_id > -1: self._journal.edit(self._editing_id,\ self.ui.lineTitle.text(),\ self.ui.textData.toPlainText()) else: self._journal.add(self.ui.lineTitle.text(),\ self.ui.textData.toPlainText()) self._editing = False self._editing_id = -1 self.ui.lineTitle.clear() self.ui.textData.clear() self.ui.grpEdit.hide() self.fill_journal_list()