Example #1
0
    def __init__(self, allDict, allParals):
        super(mainMenu, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.allDict = allDict
        self.allParals = allParals

        movenment.center(self)
        self.setWindowTitle('Byankin Aleksey')

        styles.setStylesForMainWindow(self)
        funcs.makeSurface(self)
        self.ui.gl.setBackgroundColor('#2b2b2b')

        self.ui.stepBackButton.clicked.connect(self.stepBackButton)
        self.ui.stepForwardButton.clicked.connect(self.stepForwardButton)
        self.ui.startButton.clicked.connect(self.startButton)

        self.ui.genes_number.setText('25')
        self.ui.ind_number.setText('15')
        self.ui.elite.setText('.1')
        self.ui.mutation_probability.setText('.001')
        self.ui.size_multiplier.setText('4')
        self.ui.xBorder.setText('10')
        self.ui.yBorder.setText('10')
        self.ui.zBorder.setText('10')
        self.ui.number_of_generations.setText('10')

        mainMenu.getAllData(self)
        funcs.makeBorders(self)
Example #2
0
    def test_defaults(self):
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow,app)

        self.assertEqual(ui.total_bins_text.text(), "0")
        self.assertEqual(ui.atten_events_text.text(), "0")
Example #3
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui=Ui_MainWindow()
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
        self.ui.setupUi(self)
        self.settingsMenu = Settings()
        self.gameMenu = GameMenu()

        # mainMenu Actions
        self.ui.pushButton.clicked.connect(self.start_game)
        self.ui.pushButton_2.clicked.connect(self.quit_game)
        self.ui.toolButton.clicked.connect(self.showDialog)

        # settingsMenu Actions
        self.settingsMenu.ui.pushButton.clicked.connect(self.update_vh)
        self.settingsMenu.ui.pushButton.clicked.connect(self.show_game)
        self.settingsMenu.ui.pushButton_2.clicked.connect(self.back_to_main)

        # gameMenu Actions
        self.gameMenu.ui.pushButton_Next.clicked.connect(self.next_feature)
        self.gameMenu.ui.pushButton_Quit.clicked.connect(self.back_to_main)
        self.gameMenu.ui.pushButton_Settings.clicked.connect(self.show_settings)
        self.gameMenu.ui.pushButton_Reload.clicked.connect(self.restart_game)
        self.show()
Example #4
0
class MainWindow(QtGui.QMainWindow):
    #def __init__(self, game):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui=Ui_MainWindow()
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
        self.ui.setupUi(self)
        self.settingsMenu = Settings()
        self.gameMenu = GameMenu()

        # mainMenu Actions
        self.ui.pushButton.clicked.connect(self.start_game)
        self.ui.pushButton_2.clicked.connect(self.quit_game)
        self.ui.toolButton.clicked.connect(self.showDialog)

        # settingsMenu Actions
        self.settingsMenu.ui.pushButton.clicked.connect(self.update_vh)
        self.settingsMenu.ui.pushButton.clicked.connect(self.show_game)
        self.settingsMenu.ui.pushButton_2.clicked.connect(self.back_to_main)

        # gameMenu Actions
        self.gameMenu.ui.pushButton_Next.clicked.connect(self.next_feature)
        self.gameMenu.ui.pushButton_Quit.clicked.connect(self.back_to_main)
        self.gameMenu.ui.pushButton_Settings.clicked.connect(self.show_settings)
        self.gameMenu.ui.pushButton_Reload.clicked.connect(self.restart_game)
        self.show()

    def autoset_game_mode(self):
        # check out selected mode and call SubClass accordingly
        if self.ui.radioButton.isChecked():
            self.game = GE_Game_random(npoints=self.ui.spinBox.value())
        elif (self.ui.radioButton_2.isChecked()) and (self.fname):
            self.game = GE_Game_Vector(self.fname)

    def back_to_main(self):
        self.game = None
        self.settingsMenu.hide()
        self.settingsMenu.ui.pushButton_2.setEnabled(False)
        self.gameMenu.hide()
        self.gameMenu.ui.pushButton_Next.setEnabled(True)
        self.gameMenu.ui.pushButton_Reload.setEnabled(False)
        self.show()

    def showDialog(self):
        self.fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                os.getcwd())
        self.ui.radioButton_2.setChecked(True)
        self.ui.radioButton.setChecked(False)
        self.ui.lineEdit_filePath.setText(self.fname)

    def show_settings_onstart(self):
        if self.ui.radioButton.isChecked():
            self.mode = 1
            self.game.vh = 100000
        elif self.ui.radioButton_2.isChecked():
            self.mode=2
            self.game.vh = 7000
        self.settingsMenu.show()
        self.hide()
        self.current_feature()

    def show_settings(self):
        self.settingsMenu.show()
        self.gameMenu.hide()

    def update_vh(self):
        self.game.vh = float(self.settingsMenu.ui.lineEdit.text())
        #self.game.reload() # needs some improvement

    def show_game(self):
        self.settingsMenu.hide()
        self.gameMenu.show()
        self.current_feature()

    def start_game(self):
        # check out selected mode and call SubClass accordingly
        self.autoset_game_mode()
        self.settingsMenu.ui.lineEdit.setText(str(self.game.vh))
        self.settingsMenu.show()
        self.hide()
        self.game.make_point_series()

    # TODO: Fix Bug - finished after 2 features after reload
    def restart_game(self):
        self.game.make_point_series()
        self.game.counter=0
        self.update_feature_counter()
        self.current_feature()
        self.gameMenu.ui.pushButton_Next.setEnabled(True)
        self.gameMenu.ui.pushButton_Reload.setEnabled(False)

    def file_loader(self):
        self.game.input_vector = str(QtGui.QFileDialog.getOpenFileName()) # Filename line
        print self.game.input_vector
        print os.path.exists(self.game.input_vector)
        self.ui.radioButton_2.setChecked(True)
        self.ui.radioButton.setChecked(False)

    def current_feature(self):
        self.game.call_current()
        self.update_feature_counter()

    def next_feature(self):
        self.game.call_next()
        self.update_feature_counter()
        if not self.game.active:
            self.gameMenu.ui.pushButton_Next.setEnabled(False)
            self.gameMenu.ui.pushButton_Reload.setEnabled(True)

    def quit_game(self):
        self.close()

    def update_feature_counter(self):
        self.gameMenu.ui.label.setText('Feature: {0} / {1}'.format(self.game.counter+1, self.game.nfeatures))
Example #5
0
class mainMenu(QtWidgets.QMainWindow):
    def __init__(self, allDict, allParals):
        super(mainMenu, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.allDict = allDict
        self.allParals = allParals

        movenment.center(self)
        self.setWindowTitle('Byankin Aleksey')

        styles.setStylesForMainWindow(self)
        funcs.makeSurface(self)
        self.ui.gl.setBackgroundColor('#2b2b2b')

        self.ui.stepBackButton.clicked.connect(self.stepBackButton)
        self.ui.stepForwardButton.clicked.connect(self.stepForwardButton)
        self.ui.startButton.clicked.connect(self.startButton)

        self.ui.genes_number.setText('25')
        self.ui.ind_number.setText('15')
        self.ui.elite.setText('.1')
        self.ui.mutation_probability.setText('.001')
        self.ui.size_multiplier.setText('4')
        self.ui.xBorder.setText('10')
        self.ui.yBorder.setText('10')
        self.ui.zBorder.setText('10')
        self.ui.number_of_generations.setText('10')

        mainMenu.getAllData(self)
        funcs.makeBorders(self)

    def textButton(self):
        if self.allDict['textBox']:
            extrafuncs.removeText(self)
        else:
            extrafuncs.addAllText(self)

    def stepBackButton(self):
        if self.allDict['parals']:  # если объекты есть на плоскости
            if self.allDict['currentParal'] > 0:
                if self.allDict['currentParal'] != len(
                        self.allDict['placedParals']):
                    self.allDict['currentParal'] = len(
                        self.allDict['placedParals']) - 1
                else:
                    self.allDict['currentParal'] -= 1
                w = self.ui.gl
                print(self.allDict['currentParal'])

                w.removeItem(
                    self.allDict['placedParals'][self.allDict['currentParal']])

                if len(self.allDict['placedParals']) > 1:
                    i, currentJ, z = self.allDict['allTranslations'][
                        self.allDict['placedParals'][-1]]

                    self.allDict['placedParals'][-1].translate(
                        -i, -currentJ, -z)

                self.allDict['placedParals'].pop()
                self.allDict['matrixOfMatrices'].pop()

                self.allDict['matrices'] = [] if len(self.allDict['matrixOfMatrices']) == 0 else \
                    self.allDict['matrixOfMatrices'][-1]

    def stepForwardButton(self):
        # print(self.allDict['currentParal'])
        # if not self.allDict['parals']:
        #     funcs.randGenes(self, self.allDict['k'])
        #     preparingForFF(self, False)
        #     firstFit(self, True)
        # else:
        #     self.allDict['is_show_parals'] = True
        #     firstFit(self, False)
        #     self.allDict['is_show_parals'] = False

        print('Будет доступна в следующей версии')

        pass

    def startButton(self):
        w = self.ui.gl
        for paral in self.allDict['placedParals']:
            w.removeItem(paral)

        clearAll(self)
        self.allDict['parals'] = []

        mainMenu.getAllData(self)
        funcs.makeBorders(self)

        funcs.randGenes(self, self.allDict['k'])
        preparingForFF(self, False)
        ga = Generic_Algorithm(
            self.allDict,
            self.allParals,
            number_of_generations=self.number_of_generations,
            ind_number=self.ind_number,
            elite=self.elite,
            mutation_probability=self.mutation_probability)
        ga_best_value, ga_best_solution, _ = ga.main()

        self.allDict['parals'] = ga_best_solution
        self.allDict['is_show_parals'] = True
        preparingForFF(self, False)
        clearAll(self)
        firstFit(self, False)
        self.allDict['is_show_parals'] = False

        self.ui.best_value.setText(str(ga_best_value * 100)[:2] + '%')
        print('Готово!')

    def getAllData(self):
        self.genes_number = int(self.ui.genes_number.text())
        self.ind_number = int(self.ui.ind_number.text())
        self.elite = float(self.ui.elite.text())
        self.mutation_probability = float(self.ui.mutation_probability.text())
        self.size_multiplier = self.allDict['k'] = int(
            self.ui.size_multiplier.text())
        self.allDict['xBorder'] = int(self.ui.xBorder.text()) + 1
        self.allDict['yBorder'] = int(self.ui.yBorder.text()) + 1
        self.allDict['zBorder'] = int(self.ui.zBorder.text())
        self.number_of_generations = int(self.ui.number_of_generations.text())

        self.allDict['maxSpace'] = self.allDict['xBorder'] * self.allDict[
            'yBorder'] * self.allDict['zBorder']