def do_import(self): version = self.version_select.currentText() cat_name = self.cat_name cat_id = self.cat_id import_type = self.import_type db_path = self.db_select.value() db_extension = db_path.split(".")[-1] if version == "V2": MessageBoxes.warning_message( "Not Available", "importing from version 2 is not available yet.") return if db_extension != "db": MessageBoxes.warning_message( "Not Database", "Please choose target database file.") return db = RemoteDatabase(db_path) remote_docs = db.get_docs_for_category(cat_name) remote_tags = db.get_all_tags() local_docs = Database().get_detailed_docs_for_category(cat_id) local_tags = Database().get_all_tags() if import_type == "merge": SharedFunctions.merge_import_docs(local_docs, remote_docs, local_tags, remote_tags) MessageBoxes.success_message("Imported", "Import documents Done") self.result = "Done" self.accept() elif import_type == "skip": SharedFunctions.skip_import_docs(local_docs, remote_docs, local_tags, remote_tags) MessageBoxes.success_message("Imported", "Import documents Done") self.result = "Done" self.accept()
def delete_cat(self, cat_name): ask = MessageBoxes.confirm_message( "Are you sure to delete this category and all the documents under it ?" ) if ask: cat_id = self.categories_by_name[cat_name]['id'] SharedFunctions.delete_cat(cat_id) self.refresh_data()
def __init__(self, parent, **kwargs): super().__init__() self.setObjectName("documents_page") self.parent = parent self.pc_width = SessionWrapper.get_dimension('main_window_width') self.pc_height = SessionWrapper.get_dimension('main_window_height') user_id = SessionWrapper.user_id categories = Database().get_all_categories(user_id) self.selected_doc_id = 0 self.selected_doc_name = "" self.categories_by_id, self.categories_by_name = SharedFunctions( ).format_categories(categories) self.selected_cat_id = kwargs['selected_cat_id'] self.selected_cat_name = kwargs['selected_cat_name'] if not self.selected_cat_id: default_cat = Database().get_default_cat(user_id) if default_cat is not None: self.selected_cat_id = default_cat['id'] self.selected_cat_name = default_cat['cat_name'] self.docs_layout = QHBoxLayout() self.docs_layout.setContentsMargins(0, 0, 0, 0) #(left, top, right, bottom) self.docs_layout.setSpacing(0) self.pc_width = SessionWrapper.get_dimension('main_window_width') self.pc_height = SessionWrapper.get_dimension('main_window_height') self.initUI()
def do_import(self): version = self.version_select.currentText() db_path = self.db_select.value() db_extension = db_path.split(".")[-1] if version == "V2": MessageBoxes.warning_message("Not Available", "importing from version 2 is not available yet.") return if db_extension != "db": MessageBoxes.warning_message("Not Database", "Please choose target database file.") return db = RemoteDatabase(db_path) remote_cat = db.get_all_categories() user_id = SessionWrapper.user_id local_cat = Database().get_all_categories(user_id) SharedFunctions.import_all_together(local_cat, remote_cat, user_id, db_path) MessageBoxes.success_message("Imported", "Data Import Done") self.result = "Done" self.accept()
def document_selected(self, which): doc_details = Database().get_doc_details(self.selected_cat_id, which) doc_id = doc_details['id'] doc_tags = Database().get_tags_by_doc(doc_id) tags = SharedFunctions.make_tags_text(doc_tags) self.document_name.setText(doc_details['doc_name']) self.document_desc.setText(doc_details['details']) self.document_tags.setText(tags) self.selected_doc_id = doc_id self.selected_doc_name = doc_details['doc_name']
def refresh_data(self, data=None): if data is None: user_id = SessionWrapper.user_id data = Database().get_all_categories(user_id) self.categories_by_id, self.categories_by_name = SharedFunctions( ).format_categories(data) categories_options = [] for opt in self.categories_by_name: categories_options.append(opt) self.categories_list.only_update_options(categories_options) self.reset_inputs()
def add_new_note(self): note_date=self.date_select.value() note_details="" current_date = SharedFunctions.get_current_date_str() the_new_note = Database().insert_note(note_date, note_details, current_date) test_input = DraggableTextArea(self) test_input.setObjectName(str(the_new_note)) test_input.setGeometry(QRect(400, self.y() + 250, 300, 45)) # (x, y, width, height) test_input.setParent(None) self.layout().addChildWidget(test_input) test_input.moved.connect(self.note_moved) test_input.lost_focus.connect(self.note_lost_focus)
def __init__(self, parent, **kwargs): super().__init__() self.setObjectName("category_page") self.parent = parent user_id = SessionWrapper.user_id categories = Database().get_all_categories(user_id) self.categories_by_id, self.categories_by_name = SharedFunctions( ).format_categories(categories) self.selected_cat_id = 0 self.selected_cat_name = "" self.landing_layout = QHBoxLayout() self.landing_layout.setContentsMargins(0, 0, 0, 0) #(left, top, right, bottom) self.landing_layout.setSpacing(0) self.pc_width = SessionWrapper.get_dimension('main_window_width') self.pc_height = SessionWrapper.get_dimension('main_window_height') self.initUI()
def __init__(self, text, title, limit=100): super().__init__() self.limit = limit self.the_title = title text = str(text) self.text = text full_text = text.strip() short_text = SharedFunctions.format_text(full_text, self.limit, True) self.main_layout = QHBoxLayout() self.main_layout.setSpacing(0) self.the_label = RegularLabel(short_text) self.main_layout.addWidget(self.the_label) if len(full_text) > limit: self.icon_label = IconicQLabel() self.icon_label.clicked.connect(self.show_full_text) self.main_layout.addWidget(self.icon_label) self.setLayout(self.main_layout) self.setLayoutDirection(Qt.RightToLeft)
def setText(self, text): text = str(text) self.text = text full_text = text.strip() short_text = SharedFunctions.format_text(full_text, self.limit, True) self.the_label.setText(short_text) if len(full_text) > self.limit: try: p = QPixmap('resources/assets/images/see_more.png') self.icon_label.setPixmap(p) except AttributeError: self.icon_label = IconicQLabel() self.icon_label.clicked.connect(self.show_full_text) self.main_layout.addWidget(self.icon_label) else: try: p = QPixmap() self.icon_label.setPixmap(p) except AttributeError: pass
def update_or_add_cat(self): cat_id = self.selected_cat_id cat_name = self.category_name.text() cat_desc = self.category_desc.text() user_id = SessionWrapper.user_id current_dat = SharedFunctions.get_current_date_str() if cat_id: Database().update_cat(cat_id, cat_name, cat_desc, current_dat) MessageBoxes.success_message("Done", "Category Updated") self.refresh_data() else: if len(cat_name) >= 2: cat_id = Database().insert_cat(cat_name, cat_desc, user_id, current_dat) MessageBoxes.success_message("Done", "Category saved") self.selected_cat_id = cat_id self.selected_cat_name = cat_name self.refresh_data() else: MessageBoxes.warning_message( "invalid", "Category name can not be less than two characters")
def do_registration(self, firstName, lastName, email, password, password_2): for check, message in [ Validator.validate_name(firstName), Validator.validate_name(lastName), Validator.validate_username(email), Validator.validate_passwords(password, password_2) ]: if not check: MessageBoxes.warning_message("Error", message) return created_at = SharedFunctions.get_current_date_str() #first_name, last_name = SharedFunctions.split_the_name(name) enc_pass = do_encrypt(password) Database().register_user(firstName, lastName, email, enc_pass, created_at) MessageBoxes.success_message( "Done!", "You singed up successfully now you can sign in") self.result = "Done" self.registered_username = email self.registered_password = password self.accept()
def calculate_date_time_difference(self): first_date_time = self.first_date_time.value() second_date_time = self.second_date_time.value() try: first_date_time_object = datetime.strptime(first_date_time, "%Y-%m-%d %H:%M:%S") second_date_time_object = datetime.strptime( second_date_time, "%Y-%m-%d %H:%M:%S") if first_date_time_object > second_date_time_object: MessageBoxes.warning_message( "Error", "Start Time can not be after End Time !") return except ValueError as e: MessageBoxes.warning_message("Error", "Incorrect Date format ! " + str(e)) return if self.result_type == "In Details": other_diff = SharedFunctions.date_diff(first_date_time_object, second_date_time_object) elif self.result_type == "In Days": other_diff = SharedFunctions.date_diff_days( first_date_time_object, second_date_time_object) elif self.result_type == "In Hours": other_diff = SharedFunctions.date_diff_hours( first_date_time_object, second_date_time_object) elif self.result_type == "In Minutes": other_diff = SharedFunctions.date_diff_minutes( first_date_time_object, second_date_time_object) elif self.result_type == "In Seconds": other_diff = SharedFunctions.date_diff_seconds( first_date_time_object, second_date_time_object) else: other_diff = SharedFunctions.date_diff(first_date_time_object, second_date_time_object) MessageBoxes.success_message("Result", "The difference is: " + str(other_diff))
def note_lost_focus(self): note_id = self.sender().objectName() note_details = self.sender().toPlainText() current_date = SharedFunctions.get_current_date_str() Database().update_note_details(note_id, note_details, current_date)
def note_moved(self): note_id = self.sender().objectName() x_pos = self.sender().x() y_pos = self.sender().y() current_date = SharedFunctions.get_current_date_str() Database().update_note_pos(note_id, x_pos, y_pos, current_date)
def make_date_time_section(self): date_time_diff_section = QWidget() date_time_diff_section.setFixedWidth(550) date_time_diff_section.setFixedHeight(300) date_time_diff_label = RegularLabel("DateTime Difference : ") date_time_diff_layout = QVBoxLayout() first_date_time_line = QHBoxLayout() first_date_time_label = RegularLabel("From : ") yesterday = SharedFunctions.get_yesterday_date_str() self.first_date_time = DateTimeWidget(-600, 600, value=yesterday) first_date_time_line.addWidget(first_date_time_label) first_date_time_line.addWidget(self.first_date_time) second_date_time_line = QHBoxLayout() second_date_time_label = RegularLabel("To : ") self.second_date_time = SecondDateTimeWidget(-600, 600) second_date_time_line.addWidget(second_date_time_label) second_date_time_line.addWidget(self.second_date_time) calculation_options_line = QHBoxLayout() self.calculation_options_group = QButtonGroup() # Number group r1 = QRadioButton("In Details") r1.setChecked(True) r1.toggled.connect(lambda: self.set_result_type(r1, "In Details")) r2 = QRadioButton("In Days") r2.toggled.connect(lambda: self.set_result_type(r2, "In Days")) r3 = QRadioButton("In Hours") r3.toggled.connect(lambda: self.set_result_type(r3, "In Hours")) r4 = QRadioButton("In Minutes") r4.toggled.connect(lambda: self.set_result_type(r4, "In Minutes")) r5 = QRadioButton("In Seconds") r5.toggled.connect(lambda: self.set_result_type(r5, "In Seconds")) self.calculation_options_group.addButton(r1) self.calculation_options_group.addButton(r2) self.calculation_options_group.addButton(r3) self.calculation_options_group.addButton(r4) self.calculation_options_group.addButton(r5) calculation_options_line.addWidget(r1) calculation_options_line.addWidget(r2) calculation_options_line.addWidget(r3) calculation_options_line.addWidget(r4) calculation_options_line.addWidget(r5) date_time_btn_line = QHBoxLayout() date_time_btn_line.setContentsMargins(450, 0, 0, 0) date_time_btn = RegularButton("Calculate") date_time_btn.clicked.connect(self.calculate_date_time_difference) date_time_btn_line.addWidget(date_time_btn) date_time_diff_layout.addWidget(date_time_diff_label) date_time_diff_layout.addLayout(first_date_time_line) date_time_diff_layout.addLayout(second_date_time_line) date_time_diff_layout.addLayout(calculation_options_line) date_time_diff_layout.addLayout(date_time_btn_line) date_time_diff_section.setLayout(date_time_diff_layout) return date_time_diff_section