コード例 #1
0
 def add_doc(self):
     if not self.selected_cat_id:
         msg = "No category selected"
         MessageBoxes.warning_message("Not Available", msg)
     else:
         imp = AddDocumentModal(self.selected_cat_id)
         imp_ex = imp.exec_()
         if imp_ex == QDialog.Accepted and imp.result == "Done":
             self.refresh_data()
コード例 #2
0
 def handle_login(self, username, password):
     remember_me = self.remember_me.checkState() == Qt.Checked
     login_try, msg = LoginModel.handle_login(username, password,
                                              remember_me)
     if login_try == "Okay" and msg == "Done":
         self.status = "Done"
         self.accept()
     elif login_try == "Okay" and msg == "new":
         self.status = "New"
         self.accept()
     else:
         MessageBoxes.warning_message(login_try, msg)
コード例 #3
0
 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()
コード例 #4
0
 def do_save(self):
     doc_type = self.doc_type_select.currentText()
     doc_name = self.document_name.text()
     doc_details = self.document_desc.text()
     doc_tags = self.document_tags.text()
     if doc_type != "Normal":
         msg = "adding %s documents is not available yet" % doc_type
         MessageBoxes.warning_message("Not Available", msg)
     else:
         doc_id = Database().insert_doc(self.cat_id, doc_name, doc_details,
                                        doc_type)
         Database().insert_tags(doc_tags, doc_id)
         MessageBoxes.success_message("Done", "Document Saved")
         self.result = "Done"
         self.accept()
コード例 #5
0
 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()
コード例 #6
0
 def delete_doc(self, doc_name):
     ask = MessageBoxes.confirm_message(
         "Are you sure to delete this Document?")
     if ask:
         doc_details = Database().get_doc_details(self.selected_cat_id,
                                                  doc_name)
         Database().delete_doc(doc_details['id'])
         self.refresh_data()
コード例 #7
0
 def generate_random(self):
     if not len(self.random_length_select.text()):
         MessageBoxes.warning_message("Error", "choose the length please !")
         return
     string_length = int(self.random_length_select.text())
     letters = ''
     if self.capital_etters.isChecked():
         letters += string.ascii_uppercase
     if self.small_letters.isChecked():
         letters += string.ascii_lowercase
     if self.numbers.isChecked():
         letters += string.digits
     if self.special_characters.isChecked():
         letters += string.punctuation
     if len(letters) == 0:
         MessageBoxes.warning_message("Error", "you have to choose one group at least !")
         return
     randd = ''.join(random.choice(letters) for i in range(string_length))
     self.random_string.setText(randd)
コード例 #8
0
 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()
コード例 #9
0
 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()
コード例 #10
0
 def open_word(path_to_file):
     try:
         if SharedFunctions.isWindows():
             path_to_word = SharedFunctions.get_word_path()
             if path_to_word:
                 # p = subprocess.Popen([path_to_word, path_to_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
                 p = subprocess.Popen([path_to_word, path_to_file])
             else:
                 MessageBoxes.warning_message(
                     "خطأ", "يبدوا ان مايكروسوفت اوفس غير مثبت على الجهاز")
                 return
         else:
             opener = "open" if sys.platform == "darwin" else "xdg-open"
             subprocess.call([opener, path_to_file])
     except Exception as e:
         MessageBoxes.warning_message("خطأ", path_to_file)
         MessageBoxes.warning_message("خطأ", str(e))
         return
コード例 #11
0
 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")
コード例 #12
0
 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))