def do_input(line): """ Input mode """ print("=== Input mode ===") card = ui_controller_main() card_type_by_id = dict([(card_type.id, card_type) \ for card_type in card_types()]) category_names_by_id = dict([(i, name) for (i, name) in \ enumerate(database().category_names())]) while True: # Select Card Type by user: print "Select Card Type:" print '\n'.join(["%s %s" % \ (type_id, card_type_by_id[type_id].name)\ for type_id in sorted(card_type_by_id.keys())]) while True: inp = \ raw_input(_("Enter number of Card Type or 'q' to quit ... ")) if inp in ("q", "Q"): return if inp in card_type_by_id: card_type = card_type_by_id[inp] break print(_("Input error, try again")) # Select the exist or Add the new Category print '\n'.join(["%s %s" % (cat_id, category_names_by_id[cat_id]) \ for cat_id in sorted(category_names_by_id.keys())]) inp = raw_input(_("Enter number of Category or "\ "enter new category or 'q' to quit ... ")) if inp in ("q", "Q"): return category_name = inp if inp in category_names_by_id: category_name = category_names_by_id[inp] # Enter all fields for the current type fact = {} for key, name in card_type.fields: print _("Enter field"), name inp = raw_input() if inp: fact[key] = inp # Check necesary fields and create new card for required in card_type.required_fields(): if required not in fact: print(_("Error.This card is not saved in a database !!!")) print(_("You didn't enter all necesary field(s) !!!")) break else: # Create new card card.create_new_cards(fact, card_type, 0, [category_name]) database().save(config()['path']) if raw_input(_("Do you want to add a new record? y/n ")) != "y": break
def __init__(self, parent=None): QDialog.__init__(self, parent) # TODO: modal, Qt.WStyle_MinMax | Qt.WStyle_SysMenu))? self.setupUi(self) # We calculate card_type_by_name here rather than in the component # manager, because these names can change if the user chooses another # translation. TODO: test. self.card_type_by_name = {} for card_type in card_types(): self.card_types.addItem(card_type.name) self.card_type_by_name[card_type.name] = card_type # TODO: sort card types by id. # TODO: remember last type. self.card_widget = None self.update_card_widget() self.update_combobox(config()["last_add_category"]) self.grades = QButtonGroup() self.grades.addButton(self.grade_0_button, 0) self.grades.addButton(self.grade_1_button, 1) self.grades.addButton(self.grade_2_button, 2) self.grades.addButton(self.grade_3_button, 3) self.grades.addButton(self.grade_4_button, 4) self.grades.addButton(self.grade_5_button, 5) self.connect(self.grades, SIGNAL("buttonClicked(int)"), self.new_cards)
def get_view(self, view_id): """Get view object by id.""" res = self.conn.execute("select name from views where id=?", (view_id, )).fetchone() fact_view = FactView(view_id, res["name"]) # Find fact view in registered card_types and copy # *fields attributes from it for card_type in card_types(): for view in card_type.fact_views: if view.name == res["name"]: fact_view.q_fields = view.q_fields fact_view.a_fields = view.a_fields fact_view.required_fields = view.required_fields return fact_view raise RuntimeError("Wrong view(id=%d) found in the database" % view_id)
def __init__(self, fact, parent=None): QDialog.__init__(self, parent) # TODO: modal, Qt.WStyle_MinMax | Qt.WStyle_SysMenu))? self.setupUi(self) self.fact = fact # We calculate card_type_by_name here rather than in the component # manager, because these names can change if the user chooses another # translation. TODO: test. self.card_type_by_name = {} for card_type in card_types(): self.card_types.addItem(card_type.name) self.card_type_by_name[card_type.name] = card_type # TODO: sort card types by id. # TODO: remember last type. self.card_widget = None self.update_card_widget() self.update_combobox(config()["last_add_category"])