Ejemplo n.º 1
0
 def open_help(self):
     # Opening messagebox with information
     choice = QtGui.QMessageBox.information(self, tekst('Menu2'), tekst('Menu2_text'), QtGui.QMessageBox.Ok)
     if choice == QtGui.QMessageBox.Ok:
         pass
     else:
         pass
Ejemplo n.º 2
0
 def clicked_Doner(self):
     try:
         webbrowser.open(tekst('www_Doner'))
         self.ui.actionFsa_format.triggered.connect(self.open_url)
         self.buttons_off()
     except:
         self.buttons_on()
         self.output_field.setText(tekst('Button4_error'))
Ejemplo n.º 3
0
    def home(self):

        # Creating a textfield for output
        self.output_field = QtGui.QTextEdit(self)

        # Disabling the textfield for user input,
        # making it a read only
        self.output_field.setReadOnly(True)

        # Creating a font
        font = QtGui.QFont()

        # Setting the font size to 10
        font.setPointSize(10)

        # Adding the font size to the textedit field
        self.output_field.setFont(font)

        # Setting the intro text
        self.output_field.setText(tekst('1'))
        self.output_field.append('\n' + tekst('2'))

        # Moving the textfield
        self.output_field.move(posisjoner('Marg_b'), posisjoner('Marg_topp'))

        # Setting the textfield size
        self.output_field.resize(posisjoner('Vindu_b') - posisjoner('Marg_b') * 2,
                                 posisjoner('Vindu_h') - posisjoner('Marg_h') * 3 - posisjoner('Knapp_h') * 2
                                 - posisjoner('Marg_topp'))

        # Creating buttons
        self.btn_calculateBallot = QtGui.QPushButton(tekst('Button1'), self)
        self.btn_createExample = QtGui.QPushButton(tekst('Button2'), self)
        self.btn_FAQ = QtGui.QPushButton(tekst('Button3'), self)
        self.btn_doner = QtGui.QPushButton(tekst('Button4'), self)

        # Set fixed size to buttons
        self.btn_FAQ.setFixedSize(posisjoner('Knapp_b'), posisjoner('Knapp_h'))
        self.btn_createExample.setFixedSize(posisjoner('Knapp_b'), posisjoner('Knapp_h'))
        self.btn_calculateBallot.setFixedSize(posisjoner('Knapp_b'), posisjoner('Knapp_h'))
        self.btn_doner.setFixedSize(posisjoner('Knapp_b'), posisjoner('Knapp_h'))

        # Move buttons
        self.btn_calculateBallot.move(posisjoner('Marg_b'),
                                      (posisjoner('Vindu_h') - posisjoner('Marg_h') * 2 - posisjoner('Knapp_h') * 2))
        self.btn_FAQ.move((posisjoner('Marg_b') * 2 + posisjoner('Knapp_b')),
                          (posisjoner('Vindu_h') - posisjoner('Marg_h') * 2 - posisjoner('Knapp_h') * 2))
        self.btn_createExample.move(posisjoner('Marg_b'),
                                    (posisjoner('Vindu_h') - posisjoner('Marg_h') - posisjoner('Knapp_h')))
        self.btn_doner.move((posisjoner('Marg_b') * 2 + posisjoner('Knapp_b')),
                            (posisjoner('Vindu_h') - posisjoner('Marg_h') - posisjoner('Knapp_h')))

        # Adding functions to buttons
        self.btn_doner.clicked.connect(self.clicked_Doner)
        self.btn_createExample.clicked.connect(self.predict_model)
        self.btn_calculateBallot.clicked.connect(self.clicked_run_count_votes)
        self.btn_FAQ.clicked.connect(self.clicked_FAQ)

        # Creating a progressbar to indicate
        # that a process is running
        self.progress = QtGui.QProgressBar(self)

        # Set max and min to zero: this make the progressbar
        # run even though it does not
        # know the length of the process
        self.progress.setMaximum(0)
        self.progress.setMinimum(0)

        # Set processbar size
        self.progress.setGeometry(350, 650, 500, 55)

        # Hide progress bar until it is needed
        self.progress.hide()

        # show all the buttons, gif and textedit fields
        # that has been created in this function
        self.show()
Ejemplo n.º 4
0
    def __init__(self):
        #Starting the main window (QtGui.QMainWindow)
        super(Window, self).__init__()

        # Setting the geometry of the window
        # and moving it to a fixed area when started
        self.setGeometry(400, 200, 1200, 800)

        # Locking the size to (1200, 800)
        self.setFixedSize(posisjoner('Vindu_b'), posisjoner('Vindu_h'))

        # Setting the title of the window
        self.setWindowTitle("Preferansevalg")

        # Setting the GUI icon
        self.setWindowIcon(QtGui.QIcon('VT vest logo.png'))

        # Setting the style of the GUI.
        # Other alternatives: Plastique, Windows etc.
        QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("CleanLooks"))

        # Creating a exit function
        extract_action = QtGui.QAction("&Exit", self)

        # Setting a exit shortcut
        extract_action.setShortcut("Ctrl+Q")

        # Close the GUI if shortcut is used
        extract_action.triggered.connect(self.close_application)



        # Code for picture, can be used if needed
        """picture = QtGui.QPixmap("tf.jpg")
        picture_label = QtGui.QLabel(self)
        picture_label.setPixmap(picture)
        picture_label.setVisible(True)
        picture_label.move(400, 200)"""


        # Creating the menubar and adding a filemenu
        main_menu = self.menuBar()

        # Adding 'File' to the menu
        file_menu = main_menu.addMenu(tekst('Menu1'))

        # Connecting function to 'File'
        file_menu.addAction(extract_action)

        # Creating an 'Help' box
        open_help_box = QtGui.QAction(tekst('Menu2'), self)

        # Setting a shortcut for 'Help'
        open_help_box.setShortcut("Ctrl+H")

        # Open 'Help' window when shortcut is used
        open_help_box.triggered.connect(self.open_help)

        # Adding 'Help' to menu
        help_menu = main_menu.addMenu(tekst('Menu2'))

        # Connecting function to 'Help'
        help_menu.addAction(open_help_box)

        # Creating an 'About' box
        open_about_box = QtGui.QAction(tekst('Menu3'), self)

        # Setting a shortcut for 'About'
        open_about_box.setShortcut("Ctrl+E")

        # Open 'About' window when shortcut is used
        open_about_box.triggered.connect(self.open_about)

        # Adding 'About' to menu
        about_menu = main_menu.addMenu(tekst('Menu3'))

        # Connecting function to 'About'
        about_menu.addAction(open_about_box)

        # Starting the home function that creates buttons
        # texteditor, toolbar and progress bar
        self.home()
Ejemplo n.º 5
0
    def clicked_run_count_votes(self):
        # .ckpt-fil
        file_name = ""
        iteration_number = 0
        self.output_field.setText(tekst('Button1_clicked'))

        new_train_feature = []
        new_train_label = []
        new_test_feature = []
        new_test_label = []
        batch_split_percent = 0.85

        class_gradient_length = 0.000001  # Change to change to
                                          # the learningsteps
        class_feature = []
        class_label = []

        class_print_intermidiate_values_train = False
        class_print_intermidiate_values_test = False
        class_print_error_rate = True
        class_print_graph = True
        class_new_file = False  # False = create new file
                                # True  = load old file
                                # with name 'file_name'

        indent_gradient_length = 0.00001
        indent_feature = []
        indent_label = []

        indent_print_intermidiate_values_train = False
        indent_print_intermidiate_values_test = False
        indent_print_error_rate = True
        indent_print_graph = True
        indent_new_file = False  # False = create new file
                                 # True  = load old file
                                 # with name 'file_name'

        # Creating buttons
        button_classification = QtGui.QPushButton("Classification")
        button_indent = QtGui.QPushButton("Indentation")
        button_cancel_model = QtGui.QPushButton("Cancel")
        button_inner = QtGui.QPushButton("Innerring")
        button_outer = QtGui.QPushButton("Outerring")
        button_ball = QtGui.QPushButton("Ball")
        button_base = QtGui.QPushButton("No damage")
        button_cancel = QtGui.QPushButton("Cancel")
        button_yes = QtGui.QPushButton("Yes")
        button_no = QtGui.QPushButton("No")

        # Creating Messageboxes for user input
        choose_model_msgBox = QtGui.QMessageBox()
        choose_model_msgBox.setWindowTitle("Choose model")
        choose_model_msgBox.setIcon(QMessageBox.Question)
        choose_model_msgBox.setText('Which model would you like to train?')

        choose_model_msgBox.setDetailedText("To define the size of the"
                                            " damage to the ball "
                                            "bearing it is necessary to "
                                            "use two models. Firstly the "
                                            "classification model to "
                                            "determine if there is a "
                                            "damage, and which type "
                                            "it is most likely to be. "
                                            "Secondly the indentation"
                                            " model to determine the "
                                            "size of the indentation.")

        class_msgBox = QtGui.QMessageBox()
        class_msgBox.setText('Where is the damage located?')
        class_msgBox.setIcon(QMessageBox.Question)

        class_msgBox.setDetailedText("To train a model each sets of"
                                     " features in csv-format needs"
                                     " to add a label so to know what"
                                     " the correct results of the "
                                     "training.Each csv-file added "
                                     "to thetraining of the model "
                                     "needs a label.\n\nIt is "
                                     "necessary to add data sets"
                                     " of all the types of cases "
                                     "the model should be able "
                                     "to predict.")

        class_msgBox.setWindowTitle("Classification model")
        add_files_msgBox = QtGui.QMessageBox()
        add_files_msgBox.setWindowTitle("Add files")
        add_files_msgBox.setIcon(QMessageBox.Question)
        add_files_msgBox.setText('Do you wish to add another set of files')

        add_files_msgBox.setDetailedText("To train a model that are able "
                                         "to recognise every type of "
                                         "damage in a ball bearing "
                                         "it will be necessary to at "
                                         "least supply one data set"
                                         " representing each type"
                                         " of damage, and one to represent"
                                         " the no-damage baseline.")

        # Adding icon
        class_msgBox.setWindowIcon(QtGui.QIcon('tf.jpg'))
        choose_model_msgBox.setWindowIcon(QtGui.QIcon('tf.jpg'))
        add_files_msgBox.setWindowIcon(QtGui.QIcon('tf.jpg'))

        # Adding buttons to the different messageboxes
        class_msgBox.addButton(button_inner, QtGui.QMessageBox.YesRole)
        class_msgBox.addButton(button_outer, QtGui.QMessageBox.YesRole)
        class_msgBox.addButton(button_ball, QtGui.QMessageBox.YesRole)
        class_msgBox.addButton(button_base, QtGui.QMessageBox.YesRole)
        class_msgBox.addButton(button_cancel, QtGui.QMessageBox.RejectRole)
        add_files_msgBox.addButton(button_yes, QtGui.QMessageBox.YesRole)
        add_files_msgBox.addButton(button_no, QtGui.QMessageBox.YesRole)
        choose_model_msgBox.addButton(button_classification,
                                      QtGui.QMessageBox.YesRole)
        choose_model_msgBox.addButton(button_indent,
                                      QtGui.QMessageBox.YesRole)
        choose_model_msgBox.addButton(button_cancel_model,
                                      QtGui.QMessageBox.YesRole)

        # Starting the messagebox
        choose_model_msgBox.exec_()
        # Try/Except in case of errors
        try:
            self.buttons_off()
            if choose_model_msgBox.clickedButton() == button_cancel_model:
                self.output_field.setText("TRAIN MODEL\n\nCancelled.")
                self.buttons_on()

            if choose_model_msgBox.clickedButton() == button_classification:
                continue_append = True
                self.output_field.append("\nClassification model chosen")

                while continue_append:

                    file = QtGui.QFileDialog.getOpenFileName(self, "Open "
                                                                   "CSV "
                                                                   "file"
                                                                    , " ",
                                                                    "*."
                                                                    "csv")
                    if file is "":
                        self.buttons_on()
                        break
                    else:
                        class_feature.append(file)
                    # initize  classification messagebox
                    class_msgBox.exec_()
                    if class_msgBox.clickedButton() == button_inner:
                        class_label.append([0, 0, 1, 0])
                    if class_msgBox.clickedButton() == button_outer:
                        class_label.append([0, 1, 0, 0])
                    if class_msgBox.clickedButton() == button_ball:
                        class_label.append([0, 0, 0, 1])
                    if class_msgBox.clickedButton() == button_base:
                        class_label.append([1, 0, 0, 0])

                    if class_msgBox.clickedButton() == button_cancel:
                        self.progress.hide()
                        self.output_field.setText("TRAIN MODEL"
                                                  "\n\nCancelled")
                        # Cancel process and break from while loop
                        break
                    # initize add files messagebox
                    add_files_msgBox.exec_()
                    if add_files_msgBox.clickedButton() == button_no:
                        continue_append = False
                # show the progressbar
                self.progress.show()
                new_train_feature, new_train_label,\
                new_test_feature, new_test_label, info_string = \
                    import_csv_for_classification(class_feature,
                                                  class_label,
                                                  batch_split_percent)
                # Showing what parameters are being used
                self.output_field.append(info_string)
                # Create save file
                file_name = QtGui.QFileDialog.getSaveFileName(self, 'Save'
                                                                    ' File'
                                                                    ,'',
                                                                    '*.'
                                                                    'ckpt')
                print(file_name)
                # Add all components to tuplet
                class_train_tuplet = new_train_feature, new_train_label, \
                                     new_test_feature, new_test_label,\
                                     class_gradient_length, \
                                     class_print_intermidiate_values_train,\
                                     class_print_intermidiate_values_test, \
                                     class_print_error_rate, class_print_graph,\
                                     file_name, iteration_number, \
                                     class_new_file
                reset_tf()

                self.output_field.append("Training process started:"
                                         "\nThis can take minutes, hours "
                                         "or even days depending "
                                         "on your setup")
                show_result = train_model_classification(class_train_tuplet)
                self.output_field.append(show_result)
                self.buttons_on()
                self.progress.hide()

            elif choose_model_msgBox.clickedButton() == button_indent:
                continue_append = True
                self.output_field.append("\nIndentation model chosen")

                # While method to add more files
                # to the training process
                while continue_append:

                    file = QtGui.QFileDialog.getOpenFileName(self, "Open "
                                                                   "CSV "
                                                                   "file"
                                                                    ," ",
                                                                    "*."
                                                                    "csv")
                    if file is "":
                        self.buttons_on()
                        break
                    else:
                        indent_feature.append(file)
                    num, ok = QInputDialog.getDouble(self, "Damage", "Enter indent in millimeters", 0.0000, 0, 1000, 4)

                    if ok:
                        indent_label.append([num])
                        # intiate add files messagebox
                        add_files_msgBox.exec_()
                    else:
                        break

                    if add_files_msgBox.clickedButton() == button_no:
                        continue_append = False

                # Show the progressbar
                self.progress.show()

                new_train_feature, new_train_label, new_test_feature,\
                new_test_label, info_string =\
                    import_csv_for_indent(indent_feature,
                                          indent_label,
                                          batch_split_percent)

                self.output_field.append(info_string)
                self.output_field.append("Training process started:"
                                         "\nThis can take minutes or"
                                         " hours depending on your setup.")
                file_name = QtGui.QFileDialog.getSaveFileName(self, 'Save '
                                                                    'File'
                                                                     , '',
                                                                    '*.'
                                                                    'ckpt')
                indent_train_tuplet = new_train_feature, new_train_label,\
                                      new_test_feature, new_test_label,\
                                      indent_gradient_length,\
                                      indent_print_intermidiate_values_train,\
                                      indent_print_intermidiate_values_test,\
                                      indent_print_error_rate,\
                                      indent_print_graph, \
                                      file_name, iteration_number, \
                                      indent_new_file


                reset_tf()

                show_result = train_model_indent(indent_train_tuplet)

                # Hide progressbar, show result of training
                # and enable buttons
                self.output_field.append(show_result)

                self.progress.hide()
                self.buttons_on()

        except:
            # Exception that activates the buttons,
            # hides the progressbar
            # and resets the output text
            self.buttons_on()
            self.output_field.setText("TRAIN MODEL\n\nCancelled")
            self.progress.hide()