예제 #1
0
 def _create_help_display(self):
     label = QLabel(self)
     label.setText('<b>this is doc</b>'
         '<table><tr><td>Example:</td><td>value</td></tr></table>')
     label.setStyleSheet("QLabel {background-color: yellow}")
     label.move(self._mouse_position)
     label.show()
     return label
예제 #2
0
class AdjacencyClueView(QFrame):  # Prolly could use a better name
    """ Represents the Adjacency Clue View """
    TRANSPARENCY = 100

    def __init__(self, adjacencyClue, fragilityClue, parent=None):
        """ Initialize the Adjacency Clue View """
        QFrame.__init__(self, parent)
        self.adjacencyClue = adjacencyClue
        self.fragilityClue = fragilityClue
        self.resize(34, 32)
        self.setupClueLabel()

    def setupFont(self):
        """ Setup the Font """
        self.font = QFont()
        self.font.setPointSize(15)

    def setupClueLabel(self):
        """ Setup the Clue Label """
        self.setupFont()
        self.clueLabel = QLabel('', self)
        self.clueLabel.setFont(self.font)
        self.clueLabel.move(0, 0)

    def updateView(self):
        """ Update the View """
        self.clueLabel.setText(self.getLabelText())
        self.setColorBasedOnFragility()
        self.clueLabel.resize(34, self.clueLabel.contentsRect().height())

    def getLabelText(self):
        """ Get the CLue Reading Text """
        adjacentMines = self.adjacencyClue.getAdjacentMinesClue()
        if adjacentMines == 0:
            return ''
        else:
            return str(adjacentMines)

    def setColorBasedOnFragility(self):
        """ Set color of the clue based on adjacency to Fragile Mines """
        color = "rgba({0}, {1}%)".format(self.getColor(), self.TRANSPARENCY)
        self.clueLabel.setStyleSheet("QLabel { color : %s }" % color)

    def getColor(self):
        """ Return color """
        if self.fragilityClue.distance is None:
            return "0, 0, 0"
        elif self.fragilityClue.distance <= 1:
            if self.fragilityClue.count == 1:
                return "227, 68, 20"
            else:
                return "196, 0, 0"
        elif self.fragilityClue.distance > 1 and self.fragilityClue.distance < 4:
            return "244, 244, 0"
        elif self.fragilityClue.distance >= 4:
            return "0, 154, 0"
예제 #3
0
class AdjacencyClueView(QFrame): # Prolly could use a better name
    """ Represents the Adjacency Clue View """
    TRANSPARENCY = 100
    
    def __init__(self, adjacencyClue, fragilityClue, parent=None):
        """ Initialize the Adjacency Clue View """
        QFrame.__init__(self, parent)
        self.adjacencyClue = adjacencyClue
        self.fragilityClue = fragilityClue
        self.resize(34, 32)
        self.setupClueLabel()
        
    def setupFont(self):
        """ Setup the Font """
        self.font = QFont()
        self.font.setPointSize(15)
        
    def setupClueLabel(self):
        """ Setup the Clue Label """
        self.setupFont()
        self.clueLabel = QLabel('', self)
        self.clueLabel.setFont(self.font)
        self.clueLabel.move(0, 0)
        
    def updateView(self):
        """ Update the View """
        self.clueLabel.setText(self.getLabelText())
        self.setColorBasedOnFragility()
        self.clueLabel.resize(34, self.clueLabel.contentsRect().height())
        
    def getLabelText(self):
        """ Get the CLue Reading Text """
        adjacentMines = self.adjacencyClue.getAdjacentMinesClue()
        if adjacentMines == 0:
            return ''
        else:
            return str(adjacentMines)
        
    def setColorBasedOnFragility(self):
        """ Set color of the clue based on adjacency to Fragile Mines """
        color = "rgba({0}, {1}%)".format(self.getColor(), self.TRANSPARENCY)
        self.clueLabel.setStyleSheet("QLabel { color : %s }" % color)
        
    def getColor(self):
        """ Return color """
        if self.fragilityClue.distance is None:
            return "0, 0, 0"
        elif self.fragilityClue.distance <= 1:
            if self.fragilityClue.count == 1:
                return "227, 68, 20"
            else:
                return "196, 0, 0"
        elif self.fragilityClue.distance > 1 and self.fragilityClue.distance < 4:
            return "244, 244, 0"
        elif self.fragilityClue.distance >= 4:
            return "0, 154, 0"
예제 #4
0
class PasteToUpload(QMainWindow):

    def __init__(self):
        super(PasteToUpload, self).__init__()
        self.initUI()

    def initUI(self):
        self.resize(290, 150)
        self.setWindowTitle('PasteToUpload')
        font = QFont('Helvetica', 16)
        self.label = QLabel('Ctrl+V', self)
        self.edit = QLineEdit(self)
        self.label.setFont(font)
        self.label.move(45, 25)
        self.edit.move(45, 85)
        self.label.setFixedWidth(250)
        self.edit.setFixedWidth(200)
        self.edit.setReadOnly(True)
        self.edit.setFocusPolicy(Qt.NoFocus)
        self.show()

    def __sendPost(self, base64):
        value = {
            'key': API_KEY,
            'image': base64
        }
        data = urllib.urlencode(value)
        f = urllib2.urlopen(
            url='http://api.imgur.com/2/upload.json',
            data=data
        )
        return json.load(f)

    def keyPressEvent(self, e):
        if e.matches(QKeySequence.Paste):
            clipboard = QApplication.clipboard()
            mimeData = clipboard.mimeData()
            if mimeData.hasImage():
                image = clipboard.image()
                byteArray = QByteArray()
                buf = QBuffer(byteArray)
                buf.open(QIODevice.WriteOnly)
                image.save(buf, "PNG")
                self.label.setText('Uploading')
                self.thread = NetThread(str(byteArray.toBase64()))
                self.thread.finished.connect(self.onThreadEnd)
                self.thread.start()
            else:
                self.label.setText('No picture in clipboard')

    def onThreadEnd(self):
        url = self.thread.getResult()
        self.edit.setText(url)
        QApplication.clipboard().setText(url)
        self.label.setText('Finish (URL in clipboard)')
예제 #5
0
 def setupRemainingDefensesLabels(self):
     """ Setup the Remaining Defenses Labels """
     self.remainingDefensesLabels = {}
     labelNumber = 1
     remainingDefenses = self.level.getRemainingDefenses()
     for defenseClass in remainingDefenses:
         label = QLabel("", self)
         label.move(32, 16 + 48 * (labelNumber + 1))
         label.setFont(self.font)
         self.remainingDefensesLabels[defenseClass] = label
         labelNumber += 1
예제 #6
0
 def setupRemainingDefensesLabels(self):
     """ Setup the Remaining Defenses Labels """
     self.remainingDefensesLabels = {}
     labelNumber = 1
     remainingDefenses = self.level.getRemainingDefenses()
     for defenseClass in remainingDefenses:
         label = QLabel("", self)
         label.move(32, 16+48*(labelNumber+1))
         label.setFont(self.font)
         self.remainingDefensesLabels[defenseClass] = label
         labelNumber += 1
예제 #7
0
 def setIconModes(self):
     myIcon1 = QIcon(self.icon)
     myLabel1 = QLabel('sample', self)
     pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On)
     myLabel1.setPixmap(pixmap1)
     myIcon2 = QIcon(self.icon)
     myLabel2 = QLabel('sample', self)
     pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off)
     myLabel2.setPixmap(pixmap2)
     myLabel2.move(50, 0)
     myIcon3 = QIcon(self.icon)
     myLabel3 = QLabel('sample', self)
     pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On)
     myLabel3.setPixmap(pixmap3)
     myLabel3.move(100, 0)
 def setIconModes(self):
    myIcon1 = QIcon( self.icon)
    myLabel1 = QLabel('sample', self)
    pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On)
    myLabel1.setPixmap(pixmap1)
    myIcon2 = QIcon( self.icon)
    myLabel2 = QLabel('sample', self)
    pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off)
    myLabel2.setPixmap(pixmap2)
    myLabel2.move(50, 0)
    myIcon3 = QIcon( self.icon)
    myLabel3 = QLabel('sample', self)
    pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On)
    myLabel3.setPixmap(pixmap3)
    myLabel3.move(100, 0)
 def __init__(self, imageList=[], showIndicator=False, parent=None):
   from visualscrape.ui.viewer.support import ImageWidget, OverlayContainer
   super(SlideshowWidget, self).__init__(parent)
   self._cur_widget_index = 0
   self._image_widgets = []
   for image in imageList: self._image_widgets.append(ImageWidget(image, fill=True, parent=self))
   # arrange a layout for the overlaid widgets
   self._overlay_container = OverlayContainer()
   self._overlay_container.left_clicked.connect(self.prevImage)
   self._overlay_container.right_clicked.connect(self.nextImage)
   self._overlay_container.hide()
   self.addWidget(self._overlay_container)
   self.setCurrentIndex(1) # or 0 ?
   if showIndicator: # currently shows at the wrong place. disabled
     indicator_label = QLabel()
     indicator_label.setPixmap(QPixmap("show_reel_32.png"))
     self.addWidget(indicator_label)
     indicator_label.move(0, 0)
     self.setCurrentWidget(indicator_label)
예제 #10
0
    def setIconModes(self):
        myIcon1 = QIcon('iconos/prueba.png')
        myLabel1 = QLabel('sample', self)
        pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On)
        myLabel1.setPixmap(pixmap1)
        myLabel1.setToolTip('Active Icon')

        myIcon2 = QIcon('iconos/prueba.png')
        myLabel2 = QLabel('sample', self)
        pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off)
        myLabel2.setPixmap(pixmap2)
        myLabel2.move(50, 0)
        myLabel2.setToolTip('Disabled Icon')

        myIcon3 = QIcon('iconos/prueba.png')
        myLabel3 = QLabel('sample', self)
        pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On)
        myLabel3.setPixmap(pixmap3)
        myLabel3.move(100, 0)
        myLabel3.setToolTip('Selected Icon')
예제 #11
0
    def setIconMode(self):

        myIcon1 = QIcon('pyside_logo.png')
        myLabel1 = QLabel('sample', self)
        pixmap1 = myIcon1.pixmap(50, 50, QIcon.Active, QIcon.On)
        myLabel1.setPixmap(pixmap1)
        myLabel1.setToolTip('Active')

        myIcon2 = QIcon('pyside_logo.png')
        myLabel2 = QLabel('sample', self)
        pixmap2 = myIcon2.pixmap(50, 50, QIcon.Disabled, QIcon.Off)
        myLabel2.setPixmap(pixmap2)
        myLabel2.move(50, 0)
        myLabel2.setToolTip('Disabled')

        myIcon3 = QIcon('pyside_logo.png')
        myLabel3 = QLabel('sample', self)
        pixmap3 = myIcon3.pixmap(50, 50, QIcon.Selected, QIcon.On)
        myLabel3.setPixmap(pixmap3)
        myLabel3.move(100, 0)
        myLabel3.setToolTip('Selected')
예제 #12
0
 def __init__(self, imageList=[], showIndicator=False, parent=None):
     from visualscrape.ui.viewer.support import ImageWidget, OverlayContainer
     super(SlideshowWidget, self).__init__(parent)
     self._cur_widget_index = 0
     self._image_widgets = []
     for image in imageList:
         self._image_widgets.append(
             ImageWidget(image, fill=True, parent=self))
     # arrange a layout for the overlaid widgets
     self._overlay_container = OverlayContainer()
     self._overlay_container.left_clicked.connect(self.prevImage)
     self._overlay_container.right_clicked.connect(self.nextImage)
     self._overlay_container.hide()
     self.addWidget(self._overlay_container)
     self.setCurrentIndex(1)  # or 0 ?
     if showIndicator:  # currently shows at the wrong place. disabled
         indicator_label = QLabel()
         indicator_label.setPixmap(QPixmap("show_reel_32.png"))
         self.addWidget(indicator_label)
         indicator_label.move(0, 0)
         self.setCurrentWidget(indicator_label)
예제 #13
0
class SuitButton(QWidget):
    clicked = Signal(int)
    def __init__(self, resource_path, suit, parent=None):
        super(SuitButton, self).__init__(parent)

        self.suit = suit

        pip_source = PipSource(resource_path)
        pip_pixels = pip_source.get_pip(suit)

        self.img = QLabel(self)
        self.img.setPixmap(pip_pixels)
        self.img.setFixedSize(50, 50)
        self.img.move(0, 0)

    def sizeHint(self):
        return self.minimumSizeHint()

    def minimumSizeHint(self):
        return QSize(50, 50)

    def mousePressEvent(self, event):
        self.clicked.emit(self.suit)
예제 #14
0
class AeneidWindow(QMainWindow):
    def __init__(self):
        super(AeneidWindow, self).__init__()
        self.initGui()

    def initGui(self):
        self.setWindowTitle("Aeneid Window")
        self.setGeometry(200, 100, 400, 200)
        # label
        self.label1 = QLabel('today me, tomorrow the world!', self)
        self.label1.setFont('Arial')
        self.label1.move(20, 10)
        # check box creation
        self.checkbox1 = QCheckBox('OK', self)
        self.checkbox1.clicked.connect(self.onCheckBox1)
        self.checkbox1.toggle()

        # Radio buttons
        self.radioButton = QRadioButton('click me', self)
        self.radioButton.clicked.connect(self.onRadioButton)

        # ok cancel button
        self
        self.show()
예제 #15
0
class GameStatusView(QFrame):
    """ It's the game status view """
    
    def __init__(self, level, width, height, parent=None):
        """  """
        QFrame.__init__(self, parent)
        self.level = level
        
        self.setup()
        
        self.updateView()
        self.color = QColor(200, 200, 200)
        self.setStyleSheet("QFrame { background-color: %s }" % self.color.name()) 
        self.resize(width, height)
        
    def setup(self):
        """ Setup the View """
        self.setupFont()
        self.setupPowerLabel()
        self.setupMovesLabel()
        self.setupRemainingDefensesLabels()
        
    def setupFont(self):
        """ Setup the Font """
        self.font = QFont()
        self.font.setPointSize(14)
        
    def setupPowerLabel(self):
        """ Setup the Power Label """
        self.powerLabel = QLabel("", self)
        self.powerLabel.move(32, 16)
        self.powerLabel.setFont(self.font)
        
    def setupMovesLabel(self):
        """ Setup the Moves Label """
        self.movesLabel = QLabel("", self)
        self.movesLabel.move(32, 16+48)
        self.movesLabel.setFont(self.font)
        
    def setupRemainingDefensesLabels(self):
        """ Setup the Remaining Defenses Labels """
        self.remainingDefensesLabels = {}
        labelNumber = 1
        remainingDefenses = self.level.getRemainingDefenses()
        for defenseClass in remainingDefenses:
            label = QLabel("", self)
            label.move(32, 16+48*(labelNumber+1))
            label.setFont(self.font)
            self.remainingDefensesLabels[defenseClass] = label
            labelNumber += 1
        
    def updateView(self):
        """ Update the View """
        self.updatePowerLabel()
        self.updateMovesLabel()
        self.updateRemainingDefensesLabels()
        
    def updatePowerLabel(self):
        """ Update the Power Label """
        self.powerLabel.setText("Power: {0}".format(self.level.drone.powerRating.power))
        
    def updateMovesLabel(self):
        """ Update the Moves Label """
        self.movesLabel.setText("Moves: {0}".format(self.level.moveRating.moveCount))
        self.movesLabel.resize(self.movesLabel.contentsRect().width(), self.movesLabel.contentsRect().height())
        
    def updateRemainingDefensesLabels(self):
        """ Update the Remaining Mines Label """
        remainingDefenses = self.level.getRemainingDefenses()
        
        for defenseClass in remainingDefenses:
            label = self.remainingDefensesLabels[defenseClass]
            label.setText("{0} Left: {1}".format(defenseClass.friendlyName, remainingDefenses[defenseClass]))
예제 #16
0
class LevelCompletionView(QFrame):
    """ View of the Level Completion Status """
    
    def __init__(self, level, width, height, parent=None):
        """ Initialize the Level Completion View """
        QFrame.__init__(self, parent)
        self.level = level
        
        self.setup()
        self.updateView()
        
        self.color = QColor(200, 200, 200)
        self.setStyleSheet("QFrame { background-color: %s }" % self.color.name()) 
        self.resize(width, height)
        
    def setup(self):
        """ Setup the View """
        self.setupFont()
        self.setupLevelCompletionLabel()
        self.setupCompletionDetailsLabel()
        
    def setupFont(self):
        """ Setup the Font """
        self.font = QFont()
        self.font.setPointSize(32)
        
    def setupLevelCompletionLabel(self):
        """ Setup the Power Label """
        self.font = QFont()
        self.font.setPointSize(32)
        
        self.levelCompletionLabel = QLabel("You Won!", self)
        self.levelCompletionLabel.move(32, 16)
        self.levelCompletionLabel.setFont(self.font)
        self.levelCompletionLabel.setVisible(False)
        
    def setupCompletionDetailsLabel(self):
        """ Setup the Remaining Mines Label """
        self.font = QFont()
        self.font.setPointSize(24)
        
        self.completionDetailsLabel = QLabel("Destroyed!", self)
        self.completionDetailsLabel.move(32, 64)
        self.completionDetailsLabel.setFont(self.font)
        self.completionDetailsLabel.setVisible(False)
        
    def updateView(self):
        """ Update the View """
        self.updateLevelCompletionLabel()
        self.updateCompletionDetailsLabel()
        
    def updateLevelCompletionLabel(self):
        """ Update the Power Label """
        if self.level.won():
            self.levelCompletionLabel.setText("You Won!")
            self.levelCompletionLabel.setVisible(True)
        elif self.level.lost():
            self.levelCompletionLabel.setText("Game Over!")
            self.levelCompletionLabel.setVisible(True)
        
    def updateCompletionDetailsLabel(self):
        """ Update the Remaining Mines Label """
        if self.level.destroyed():
            self.completionDetailsLabel.setText("Destroyed")
            self.completionDetailsLabel.setVisible(True)
        elif self.level.noPower() and not self.level.won():
            self.completionDetailsLabel.setText("Insufficient Power")
            self.completionDetailsLabel.setVisible(True)
        elif self.level.won():
            text = ""
            if self.level.completionRating.awarded:
                text += "C"
            if self.level.moveRating.awarded:
                text += "M"
            if self.level.powerRating.awarded:
                text += "P"
            self.completionDetailsLabel.setText(text)
            self.completionDetailsLabel.setVisible(True)
예제 #17
0
class GameStatusView(QFrame):
    """ It's the game status view """
    def __init__(self, level, width, height, parent=None):
        """  """
        QFrame.__init__(self, parent)
        self.level = level

        self.setup()

        self.updateView()
        self.color = QColor(200, 200, 200)
        self.setStyleSheet("QFrame { background-color: %s }" %
                           self.color.name())
        self.resize(width, height)

    def setup(self):
        """ Setup the View """
        self.setupFont()
        self.setupPowerLabel()
        self.setupMovesLabel()
        self.setupRemainingDefensesLabels()

    def setupFont(self):
        """ Setup the Font """
        self.font = QFont()
        self.font.setPointSize(14)

    def setupPowerLabel(self):
        """ Setup the Power Label """
        self.powerLabel = QLabel("", self)
        self.powerLabel.move(32, 16)
        self.powerLabel.setFont(self.font)

    def setupMovesLabel(self):
        """ Setup the Moves Label """
        self.movesLabel = QLabel("", self)
        self.movesLabel.move(32, 16 + 48)
        self.movesLabel.setFont(self.font)

    def setupRemainingDefensesLabels(self):
        """ Setup the Remaining Defenses Labels """
        self.remainingDefensesLabels = {}
        labelNumber = 1
        remainingDefenses = self.level.getRemainingDefenses()
        for defenseClass in remainingDefenses:
            label = QLabel("", self)
            label.move(32, 16 + 48 * (labelNumber + 1))
            label.setFont(self.font)
            self.remainingDefensesLabels[defenseClass] = label
            labelNumber += 1

    def updateView(self):
        """ Update the View """
        self.updatePowerLabel()
        self.updateMovesLabel()
        self.updateRemainingDefensesLabels()

    def updatePowerLabel(self):
        """ Update the Power Label """
        self.powerLabel.setText("Power: {0}".format(
            self.level.drone.powerRating.power))

    def updateMovesLabel(self):
        """ Update the Moves Label """
        self.movesLabel.setText("Moves: {0}".format(
            self.level.moveRating.moveCount))
        self.movesLabel.resize(self.movesLabel.contentsRect().width(),
                               self.movesLabel.contentsRect().height())

    def updateRemainingDefensesLabels(self):
        """ Update the Remaining Mines Label """
        remainingDefenses = self.level.getRemainingDefenses()

        for defenseClass in remainingDefenses:
            label = self.remainingDefensesLabels[defenseClass]
            label.setText("{0} Left: {1}".format(
                defenseClass.friendlyName, remainingDefenses[defenseClass]))
class Deformation_GUI(QWidget):
    #Initialize the variable
    def __init__(self, oriPath, protoPath, oriPointsPath, protoPointsPath,
                 regionsPath):
        super(Deformation_GUI, self).__init__()
        localParas, points = preprocess(oriPath, protoPath, oriPointsPath,
                                        protoPointsPath, regionsPath, 'L2')
        self.oriImg, self.protoImg, self.regionsPoints, self.is_in_regions_fun, self.distance_funs, self.affine_funs = localParas
        self.oriPlotDict, self.protoPlotDict, self.oriPoints, self.protoPoints = points
        self.oriPoints = np.array(self.oriPoints)
        self.protoPoints = np.array(self.protoPoints)
        self.e = 2
        self.alpha = 1
        self.oriPath = oriPath
        self.protoPath = protoPath
        self.oriPointsPath = ''
        self.protoPointsPath = ''
        self.regionsPath = regionsPath
        self.transform = 'Morphing'
        self.newImg = None
        self.initUI()

    #Initialize the GUI
    def initUI(self):
        #Set Window
        QToolTip.setFont(QFont('Serif', 10))
        self.setGeometry(280, 210, 800, 450)
        self.setWindowTitle('Image Registration Based on Control Points')
        #Set Algorithm
        self.comboAffineLabel = QLabel(self)
        self.comboAffineLabel.setText('Algorithm:')
        self.comboAffineLabel.setGeometry(60, 270, 230, 30)
        self.comboAffine = QComboBox(self)
        self.comboAffine.addItem("Morphing")
        self.comboAffine.addItem("Local Affine Transformation")
        self.comboAffine.addItem("Moving Least Squares")
        self.comboAffine.setGeometry(22, 290, 225, 30)
        self.comboAffine.activated[str].connect(self.affineChoiceChange)
        #Choose Human Face Image
        self.oriBtn = QPushButton('Human Face Image', self)
        self.oriBtn.setToolTip('Human Face Image')
        self.oriBtn.setGeometry(20, 330, 230, 30)
        self.oriBtn.clicked.connect(self.showOriDialog)
        #Choose Ape or another Human image
        self.protoBtn = QPushButton('Ape or Human image', self)
        self.protoBtn.setToolTip('Ape or Human image')
        self.protoBtn.setGeometry(310, 330, 230, 30)
        self.protoBtn.clicked.connect(self.showProtoDialog)
        #parameter e
        self.eLabel = QLabel(self)
        self.eLabel.setText('E Value:0.00')
        self.eLabel.setGeometry(550, 300, 200, 30)
        self.eSld = QSlider(Qt.Horizontal, self)
        self.eSld.setRange(0, 10**5)
        self.eSld.setFocusPolicy(Qt.NoFocus)
        self.eSld.setGeometry(550, 330, 120, 30)
        self.eSld.valueChanged[int].connect(self.changeEValue)
        #parameter alpha
        self.aLabel = QLabel(self)
        self.aLabel.setText('Alpha Value:0.00')
        self.aLabel.setGeometry(680, 300, 200, 30)
        self.aSld = QSlider(Qt.Horizontal, self)
        self.aSld.setRange(0, 10**5)
        self.aSld.setFocusPolicy(Qt.NoFocus)
        self.aSld.setGeometry(680, 330, 100, 30)
        self.aSld.valueChanged[int].connect(self.changeAlphaValue)
        # The Image
        self.oriTextLabel = QLabel(self)
        self.protoTextLabel = QLabel(self)
        self.transTextLabel = QLabel(self)
        self.oriTextLabel.setText('The Human Image')
        self.protoTextLabel.setText('The Ape or another Human Image')
        self.transTextLabel.setText('Deformation Image')
        self.oriTextLabel.move(70, 5)
        self.protoTextLabel.move(350, 5)
        self.transTextLabel.move(580, 5)
        self.oriLabel = QLabel(self)
        self.protoLabel = QLabel(self)
        self.transLabel = QLabel(self)
        pixmap = QPixmap(self.oriPath)
        pixmap2 = QPixmap(self.protoPath)
        self.oriLabel.setPixmap(pixmap)
        self.protoLabel.setPixmap(pixmap2)
        self.transLabel.setPixmap(pixmap)
        #Set Position
        self.oriLabel.setGeometry(20, 20, 230, 230)
        self.protoLabel.setGeometry(290, 20, 230, 230)
        self.transLabel.setGeometry(560, 20, 230, 230)
        self.oriLabel.setScaledContents(True)
        self.protoLabel.setScaledContents(True)
        self.transLabel.setScaledContents(True)
        #import points
        self.loadOriBtn = QPushButton('Deformed Points', self)
        self.loadOriBtn.setToolTip('Load Control Points From Txt File')
        self.loadOriBtn.setGeometry(20, 365, 230, 30)
        self.loadOriBtn.clicked.connect(self.showLoadOriDialog)
        self.loadProtoBtn = QPushButton('Control Points', self)
        self.loadProtoBtn.setToolTip('Load Control Points From Txt File')
        self.loadProtoBtn.setGeometry(310, 365, 230, 30)
        self.loadProtoBtn.clicked.connect(self.showLoadProtoDialog)
        #Deformed
        self.confirmBtn = QPushButton('Deformed', self)
        self.confirmBtn.setToolTip('Deformed')
        self.confirmBtn.setGeometry(580, 365, 150, 30)
        self.confirmBtn.clicked.connect(self.transformAction)
        self.show()

    #Deformed Generate
    def transformAction(self):

        try:
            #three algorithm
            if self.transform == 'Morphing':
                self.oriImg = np.array(Image.open(self.oriPath))
                self.protoImg = np.array(Image.open(self.protoPath))
                newImg = morphingAction((self.oriPath).encode('utf-8'),
                                        self.protoPath.encode('utf-8'),
                                        self.oriPointsPath.encode('utf-8'),
                                        self.protoPointsPath.encode('utf-8'),
                                        self.alpha)
            else:
                localParas, points = preprocess(self.oriPath, self.protoPath,
                                                self.oriPointsPath,
                                                self.protoPointsPath,
                                                self.regionsPath, 'L2')
                if points == None:
                    QtGui.QMessageBox.information(self, "Error", localParas)
                    return
                self.oriImg, self.protoImg, self.regionsPoints, self.is_in_regions_fun, self.distance_funs, self.affine_funs = localParas
                self.oriPlotDict, self.protoPlotDict, self.oriPoints, self.protoPoints = points
                if self.oriImg.shape[len(self.oriImg.shape) -
                                     1] != self.protoImg.shape[
                                         len(self.protoImg.shape) - 1]:
                    QtGui.QMessageBox.information(
                        self, "Error",
                        "The type of the figures is not the same, please choose another figure"
                    )
                    return
                if self.transform == 'Local Affine Transformation':
                    newImg = local_affine(self.oriImg, self.protoImg, self.e,
                                          self.regionsPoints,
                                          self.is_in_regions_fun,
                                          self.distance_funs, self.affine_funs)
                elif self.transform == "Moving Least Squares":
                    newImg = MLS(self.oriImg, self.protoImg, self.oriPoints,
                                 self.protoPoints, self.alpha)
        except BaseException:
            QtGui.QMessageBox.information(
                self, "Error",
                "There are error in the point choice or other things.")
            newImg = morphingAction((self.oriPath).encode('utf-8'),
                                    self.protoPath.encode('utf-8'),
                                    self.oriPointsPath.encode('utf-8'),
                                    self.protoPointsPath.encode('utf-8'),
                                    self.alpha)

        self.newImg = np.uint8(newImg)
        newImg = rgb2bgr(np.uint8(newImg))
        qimage = QImage(newImg, newImg.shape[1], newImg.shape[0],
                        QImage.Format_ARGB32)
        pixmap_array = QPixmap.fromImage(qimage)
        self.transLabel.setPixmap(pixmap_array)

    def showProtoDialog(self):
        fname, _ = QtGui.QFileDialog.getOpenFileName(
            self, 'Open file', '/home', "Image Files (*.png *.jpg *.bmp)")
        if fname != None and fname != '':
            self.protoPath = fname
            self.protoLabel.setPixmap(QPixmap(self.protoPath))

    def showLoadOriDialog(self):
        fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home',
                                                     "Text files (*.txt)")
        if fname != None and fname != '':
            self.oriPointsPath = fname

    def showLoadProtoDialog(self):
        fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home',
                                                     "Text files (*.txt)")
        if fname != None and fname != '':
            self.protoPointsPath = fname
        else:
            self.protoPointsPath = ''

    def showOriDialog(self):
        fname, _ = QtGui.QFileDialog.getOpenFileName(
            self, 'Open file', '/home', "Image Files (*.png *.jpg *.bmp)")
        if fname != None and fname != '':
            self.oriPath = fname
            print(self.oriPath)
            self.oriLabel.setPixmap(QPixmap(self.oriPath))

    #e value in Local Affine Algorithm
    def changeEValue(self, x):
        self.e = 4.0 * x / 10**5
        self.eLabel.setText('E Value:' + str('%.2f' % self.e))

    #alpha value in MLS and Morphing Algorithm
    #the alpha range is  different
    def changeAlphaValue(self, x):
        if self.transform == 'Moving Least Squares':
            self.alpha = 2.0 * x / 10**5
        elif self.transform == 'Morphing':
            self.alpha = 1.0 * x / 10**5
        self.aLabel.setText('Alpha Value:' + str('%.2f' % self.alpha))

    # 3 Algorithm
    def affineChoiceChange(self, item):
        if self.transform in ['Moving Least Squares', 'Morphing'] and item in [
                'Moving Least Squares', 'Morphing'
        ] and item != self.transform:
            self.alpha = 0.0
            self.aSld.setValue(self.alpha)
        self.transform = item
예제 #19
0
class TransformationFaceUI(QWidget):
    def __init__(self, oriPath, protoPath, oriPointsPath, protoPointsPath,
                 regionsPath):
        super(TransformationFaceUI, self).__init__()
        #Initialize the data or object we need

        localParas, points = preprocess(oriPath, protoPath, oriPointsPath,
                                        protoPointsPath, regionsPath, 'L2')
        self.oriImg, self.protoImg, self.regionsPoints, self.is_in_regions_fun, self.distance_funs, self.affine_funs = localParas
        self.oriPlotDict, self.protoPlotDict, self.oriPoints, self.protoPoints = points
        self.oriPoints = np.array(self.oriPoints)
        self.protoPoints = np.array(self.protoPoints)
        self.e = 2
        self.alpha = 1
        self.oriPath = oriPath
        self.protoPath = protoPath
        self.oriPointsPath = oriPointsPath
        self.protoPointsPath = protoPointsPath
        self.regionsPath = regionsPath
        self.transform = 'Local Affine Transformation'
        self.newImg = None
        self.initUI()

    def initUI(self):
        QToolTip.setFont(QFont('SansSerif', 10))
        self.setGeometry(300, 200, 810, 430)
        self.setWindowTitle('Transformation on Human Face')

        #Method choose combobox
        self.comboAffineLabel = QLabel(self)
        self.comboAffineLabel.setText('Transformation Method:')
        self.comboAffineLabel.setGeometry(60, 270, 230, 30)

        self.comboAffine = QComboBox(self)
        self.comboAffine.addItem("Local Affine Transformation")
        self.comboAffine.addItem("Moving Least Squares")
        self.comboAffine.addItem("Morphing")
        self.comboAffine.setGeometry(22, 290, 225, 30)
        self.comboAffine.activated[str].connect(self.affineChoiceChange)

        #The button to choose the original figure
        self.oriBtn = QPushButton('Choose Original Picture', self)
        self.oriBtn.setToolTip('Choose Original Picture')
        self.oriBtn.setGeometry(20, 330, 230, 30)
        self.oriBtn.clicked.connect(self.showOriDialog)

        #The button to choose the proto figure
        self.protoBtn = QPushButton('Choose Proto Picture', self)
        self.protoBtn.setToolTip('Choose Proto Picture')
        self.protoBtn.setGeometry(20, 365, 230, 30)
        self.protoBtn.clicked.connect(self.showProtoDialog)

        #The distance function choose combobox
        self.comboLabel = QLabel(self)
        self.comboLabel.setText('Distance Fun:')
        self.comboLabel.setGeometry(310, 280, 200, 30)

        self.comboDis = QComboBox(self)
        self.comboDis.addItem("L2")
        self.comboDis.addItem("L1")
        self.comboDis.setGeometry(410, 280, 80, 30)

        self.comboDis.activated[str].connect(self.distanceChoiceChange)

        #E choose slider

        self.eLabel = QLabel(self)
        self.eLabel.setText('E Value:0.00')
        self.eLabel.setGeometry(310, 320, 200, 30)
        self.eSld = QSlider(Qt.Horizontal, self)
        self.eSld.setRange(0, 10**5)
        self.eSld.setFocusPolicy(Qt.NoFocus)
        self.eSld.setGeometry(390, 320, 120, 30)
        self.eSld.valueChanged[int].connect(self.changeEValue)

        #alpha choose slider
        self.aLabel = QLabel(self)
        self.aLabel.setText('Alpha Value:0.00')
        self.aLabel.setGeometry(310, 360, 200, 30)
        self.aSld = QSlider(Qt.Horizontal, self)
        self.aSld.setRange(0, 10**5)
        self.aSld.setFocusPolicy(Qt.NoFocus)
        self.aSld.setGeometry(410, 360, 100, 30)
        self.aSld.valueChanged[int].connect(self.changeAlphaValue)

        # Picture show
        self.oriTextLabel = QLabel(self)
        self.protoTextLabel = QLabel(self)
        self.transTextLabel = QLabel(self)
        self.oriTextLabel.setText('The Orginal Picture')
        self.protoTextLabel.setText('The Proto Picture')
        self.transTextLabel.setText('The Picture after Transformation')

        self.oriTextLabel.move(70, 5)
        self.protoTextLabel.move(350, 5)
        self.transTextLabel.move(580, 5)

        self.oriLabel = QLabel(self)
        self.protoLabel = QLabel(self)
        self.transLabel = QLabel(self)

        pixmap = QPixmap(self.oriPath)
        pixmap2 = QPixmap(self.protoPath)
        self.oriLabel.setPixmap(pixmap)
        self.protoLabel.setPixmap(pixmap2)
        self.transLabel.setPixmap(pixmap)

        #Position setting
        self.oriLabel.setGeometry(20, 20, 230, 230)
        self.protoLabel.setGeometry(290, 20, 230, 230)
        self.transLabel.setGeometry(560, 20, 230, 230)
        self.oriLabel.setScaledContents(True)
        self.protoLabel.setScaledContents(True)
        self.transLabel.setScaledContents(True)
        #Load button
        self.loadOriBtn = QPushButton('Load Ori Points', self)
        self.loadOriBtn.setToolTip('Load Control Points From Txt File')
        self.loadOriBtn.setGeometry(550, 280, 130, 30)
        self.loadOriBtn.clicked.connect(self.showLoadOriDialog)

        self.loadProtoBtn = QPushButton('Load Proto Points', self)
        self.loadProtoBtn.setToolTip('Load Control Points From Txt File')
        self.loadProtoBtn.setGeometry(680, 280, 130, 30)
        self.loadProtoBtn.clicked.connect(self.showLoadProtoDialog)
        #Face ++ button
        self.faceBtn = QPushButton('Face++ Keypoint', self)
        self.faceBtn.setToolTip('Save the Face++ Keypoints')
        self.faceBtn.setGeometry(550, 315, 130, 30)
        self.faceBtn.clicked.connect(self.detectKeyPoints)
        #Load region Button
        self.loadRegionBtn = QPushButton('Load Regions', self)
        self.loadRegionBtn.setToolTip('Load Regions From Txt File')
        self.loadRegionBtn.setGeometry(680, 315, 130, 30)
        self.loadRegionBtn.clicked.connect(self.showLoadRegionDialog)

        #Save Button setting
        self.saveBtn = QPushButton('Save', self)
        self.saveBtn.setToolTip(
            'Transform this picture to the shape of Baboon')
        self.saveBtn.setGeometry(560, 350, 110, 40)
        self.saveBtn.clicked.connect(self.saveImg)

        #Transform action button
        self.confirmBtn = QPushButton('Generate', self)
        self.confirmBtn.setToolTip('Generate')
        self.confirmBtn.setGeometry(680, 350, 110, 40)
        self.confirmBtn.clicked.connect(self.transformAction)

        self.show()

    #Invoke face++ and save which is connected to the facebtn
    def detectKeyPoints(self):
        print(self.oriPath)
        save_points('face_keypoints_ori.txt',
                    detect((self.oriPath).encode('utf-8')))

    #Save img connected to the save button
    def saveImg(self):
        if self.newImg == None:
            QtGui.QMessageBox.information(self, "Error",
                                          "There is not transformed figure")
        result = Image.fromarray(self.newImg)
        filenames = self.oriPath.split('/')
        filenames[len(filenames) -
                  1] = 'trans_' + filenames[len(filenames) - 1]
        newPath = '/'.join(filenames)
        result.save(newPath)

    #Connected to the transform button did the deformation and show it
    def transformAction(self):

        try:
            #For different methods have different solution
            if self.transform == 'Morphing':
                self.oriImg = np.array(Image.open(self.oriPath))
                self.protoImg = np.array(Image.open(self.protoPath))
                if self.oriImg.shape != self.protoImg.shape:
                    QtGui.QMessageBox.information(
                        self, "Error",
                        "It is image morphing and required the same size of two images,please choose other images"
                    )
                    return
                newImg = morphingAction((self.oriPath).encode('utf-8'),
                                        self.protoPath.encode('utf-8'),
                                        self.protoPointsPath.encode('utf-8'),
                                        self.alpha)
            else:
                localParas, points = preprocess(self.oriPath, self.protoPath,
                                                self.oriPointsPath,
                                                self.protoPointsPath,
                                                self.regionsPath, 'L2')
                if points == None:
                    QtGui.QMessageBox.information(self, "Error", localParas)
                    return
                self.oriImg, self.protoImg, self.regionsPoints, self.is_in_regions_fun, self.distance_funs, self.affine_funs = localParas
                self.oriPlotDict, self.protoPlotDict, self.oriPoints, self.protoPoints = points
                if self.oriImg.shape[len(self.oriImg.shape) -
                                     1] != self.protoImg.shape[
                                         len(self.protoImg.shape) - 1]:
                    QtGui.QMessageBox.information(
                        self, "Error",
                        "The type of the figures is not the same, please choose another figure"
                    )
                    return
                if self.transform == 'Local Affine Transformation':
                    newImg = local_affine_transformation(
                        self.oriImg, self.protoImg, self.e, self.regionsPoints,
                        self.is_in_regions_fun, self.distance_funs,
                        self.affine_funs)
                elif self.transform == "Moving Least Squares":
                    newImg = affine_points_MLS(self.oriImg, self.protoImg,
                                               self.oriPoints,
                                               self.protoPoints, self.alpha)
        except BaseException:

            QtGui.QMessageBox.information(
                self, "Error",
                "There are error in the point choice or other things.")
            newImg = morphingAction((self.oriPath).encode('utf-8'),
                                    self.protoPath.encode('utf-8'),
                                    self.protoPointsPath.encode('utf-8'),
                                    self.alpha)

        self.newImg = np.uint8(newImg)
        newImg = rgb2bgr(np.uint8(newImg))

        qimage = QImage(newImg, newImg.shape[1], newImg.shape[0],
                        QImage.Format_ARGB32)
        pixmap_array = QPixmap.fromImage(qimage)
        self.transLabel.setPixmap(pixmap_array)
################################################################################################
################################################################################################
################################################################################################
################################################################################################
################################################################################################
################################################################################################
################################################################################################
################################################################################################

#The file chooser , all of the function begin with show is the same but for different parameter.

    def showProtoDialog(self):

        fname, _ = QtGui.QFileDialog.getOpenFileName(
            self, 'Open file', '/home', "Image Files (*.png *.jpg *.bmp)")
        if fname != None and fname != '':
            self.protoPath = fname
            self.protoLabel.setPixmap(QPixmap(self.protoPath))

    def showLoadOriDialog(self):

        fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home',
                                                     "Text files (*.txt)")
        if fname != None and fname != '':
            self.oriPointsPath = fname

    def showLoadRegionDialog(self):

        fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home',
                                                     "Text files (*.txt)")
        if fname != None and fname != '':
            self.regionsPath = fname

    def showLoadProtoDialog(self):

        fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
                                                     '/home',
                                                     "Text files (*.txt)")
        if fname != None and fname != '':
            self.protoPointsPath = fname

    def showOriDialog(self):

        fname, _ = QtGui.QFileDialog.getOpenFileName(
            self, 'Open file', '/home', "Image Files (*.png *.jpg *.bmp)")
        if fname != None and fname != '':
            self.oriPath = fname
            print(self.oriPath)
            self.oriLabel.setPixmap(QPixmap(self.oriPath))

    #Connected with eSld change the e value in LAT method
    def changeEValue(self, x):
        self.e = 4.0 * x / 10**5
        self.eLabel.setText('E Value:' + str('%.2f' % self.e))

    #Connected with aSld change the alpha value in MLS and Morphing method(but the alpha range is not the same)
    def changeAlphaValue(self, x):
        if self.transform == 'Moving Least Squares':
            self.alpha = 2.0 * x / 10**5
        elif self.transform == 'Morphing':
            self.alpha = 1.0 * x / 10**5
        self.aLabel.setText('Alpha Value:' + str('%.2f' % self.alpha))

    #Connected to the method combobox
    def affineChoiceChange(self, item):

        if self.transform in ['Moving Least Squares', 'Morphing'] and item in [
                'Moving Least Squares', 'Morphing'
        ] and item != self.transform:
            self.alpha = 0.0
            self.aSld.setValue(self.alpha)
        self.transform = item

    #Connected to the distance combobox
    def distanceChoiceChange(self, item):
        self.oriImg, self.protoImg, self.protoPoints, self.affine_funs = preprocess(
            oriPath, protoPath, oriPointsPath, protoPointsPath, item)
예제 #20
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        #widnow setup
        resolution = QDesktopWidget().screenGeometry()
        self.screen_w = resolution.width()
        self.screen_h = resolution.height()
        self.setGeometry(0, 0, 650, 200)
        self.setWindowTitle('bento dumper' + mof.get_version_suffix())
        self.setWindowIcon(QIcon('icons/run.png'))

        #center window
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
        #adjust size
        self.resize(self.screen_w / 2, self.screen_h / 16)
        self.Menu()
        self.Layout()

        central_widget = QtGui.QWidget()
        central_widget.setLayout(self.main_layout)
        self.setCentralWidget(central_widget)

    def Menu(self):
        #this creates an action exit, a shortcut and status tip
        exitAction = QAction(QIcon('icons/exit.png'), '&Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)

        openFile = QAction(QIcon('icons/open.png'), '&Open', self)
        openFile.setShortcut('Ctrl+O')
        openFile.setStatusTip('Open new File')
        openFile.triggered.connect(self.browse)

        runAction = QAction(QIcon('icons/run.png'), '&Run', self)
        runAction.setShortcut('Ctrl+R')
        runAction.setStatusTip('Run Mars')
        runAction.triggered.connect(self.run_event)

    def Layout(self):
        #LAYOUT
        self.directory_prompt = QLabel(self)
        self.directory_prompt.setText("Directory Selected:")
        self.directory_prompt.move(25, 50)
        self.directory_prompt.resize(150, 30)

        self.browse_btn = QPushButton("Browse", self)
        self.browse_btn.move(130, 50)
        self.browse_btn.setStatusTip(" Browse Folder")
        # self.browse_btn.setStyleSheet("background-color: rgb(186, 186, 186); border-radius: 15px;border-style: solid;border-width: 2px;border-color: black;");
        self.browse_btn.clicked.connect(self.browse)

        self.dir_shower = QLabel(self)
        self.dir_shower.setText("Directory")

        self.run_mars = QPushButton("Dump BENTO", self)
        self.run_mars.setVisible(True)
        self.run_mars.move(25, 160)
        self.run_mars.resize(self.screen_w / 2 - 150, 50)
        self.run_mars.setStatusTip('')
        self.run_mars.setStyleSheet(
            "background-color: rgb(142, 229, 171); border-radius: 15px;")
        self.run_mars.clicked.connect(self.run_event)

        self.menu_layout = QtGui.QHBoxLayout()
        self.menu_layout.addWidget(self.browse_btn)
        self.menu_layout.addWidget(self.directory_prompt)
        self.menu_layout.addWidget(self.dir_shower)
        self.menu_layout.addStretch()

        self.run_layout = QtGui.QHBoxLayout()
        self.run_layout.addWidget(self.run_mars)

        self.main_layout = QtGui.QVBoxLayout()
        self.main_layout.addLayout(self.menu_layout)
        self.main_layout.addLayout(self.run_layout)

        self.main_layout.addStretch()

    def browse(self):
        # sender = self.sender()
        dialog = QtGui.QFileDialog()
        dialog.setFileMode(QtGui.QFileDialog.Directory)
        dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
        self.dirname = dialog.getExistingDirectory(self, 'Choose Directory',
                                                   os.path.curdir)
        if os.path.exists(self.dirname) and os.path.isdir(self.dirname):
            self.dir_shower.setText(self.dirname)
            return
        else:
            QMessageBox.information(self, " Wrong file selected",
                                    "Select a folder containing .seq files!")

    def run_event(self):
        self.genericThread = GenericThread(self.dirname)
        self.genericThread.start()
예제 #21
0
class Airport_project_UI(QWidget):

    airports = ['KRK', 'LA', 'LIS']

    elitism_possibly_values = ['true', 'false']

    max_flights_list = ['1', '2', '3', '4', '5']

    def __init__(self):
        QWidget.__init__(self)
        self.params = {}

        # self.setMinimumSize(600, 250)
        #self.setWindowTitle("Medody Optymalizacji - Projekt")
        # self.setIcon()

        self.start_airport_label = QLabel("Start airport:", self)
        self.start_airport_label.move(5, 10)
        self.start_airport = QLineEdit(self)
        self.start_airport.setText('1')
        #self.start_airport.addItems(self.airports)
        self.start_airport.setMinimumHeight(20)
        self.start_airport.setMaximumHeight(20)
        self.start_airport.setMinimumWidth(60)
        self.start_airport.setMaximumWidth(60)
        self.start_airport.move(150, 5)

        #TODO function to convert names of airport to indexes

        self.destination_airport_label = QLabel("Destination airport:", self)
        self.destination_airport_label.move(5, 40)
        self.destination_airport = QLineEdit(self)
        self.destination_airport.setText('2')
        # self.destination_airport.addItems(self.airports)
        self.destination_airport.setMinimumHeight(20)
        self.destination_airport.setMaximumHeight(20)
        self.destination_airport.setMaximumWidth(60)
        self.destination_airport.setMinimumWidth(60)
        self.destination_airport.move(150, 35)

        self.max_flights_label = QLabel("max number of flights:", self)
        self.max_flights_label.move(5, 70)
        self.max_flights = QLineEdit(self)
        self.max_flights.setText("3")
        #self.max_flights.addItems(self.max_flights_list)
        self.max_flights.setMaximumHeight(20)
        self.max_flights.setMinimumHeight(20)
        self.max_flights.setMaximumWidth(60)
        self.max_flights.setMinimumWidth(60)
        #self.max_flights.setMinimumWidth(60)
        self.max_flights.move(150, 65)

        self.cost_weight_label = QLabel("max cost weights:", self)
        self.cost_weight_label.move(5, 100)
        self.cost_weight = QLineEdit(self)
        self.cost_weight.setText("4")
        self.cost_weight.setMinimumWidth(60)
        self.cost_weight.setMaximumWidth(60)
        self.cost_weight.setMinimumHeight(20)
        self.cost_weight.setMaximumHeight(20)
        self.cost_weight.move(150, 95)

        self.time_weight_label = QLabel("time weight:", self)
        self.time_weight_label.move(5, 130)
        self.time_weight = QLineEdit(self)
        self.time_weight.setText("5")
        self.time_weight.setMinimumWidth(60)
        self.time_weight.setMaximumWidth(60)
        self.time_weight.setMinimumHeight(20)
        self.time_weight.setMaximumHeight(20)
        self.time_weight.move(150, 125)

        self.pop_size_label = QLabel("pop size:", self)
        self.pop_size_label.move(5, 160)  # +30

        self.pop_size = QLineEdit(self)
        self.pop_size.setText("6")
        self.pop_size.setMinimumWidth(60)
        self.pop_size.setMaximumWidth(60)
        self.pop_size.setMinimumHeight(20)
        self.pop_size.setMaximumHeight(20)
        self.pop_size.move(150, 155)  # +30

        self.generation_label = QLabel("generations:", self)
        self.generation_label.move(5, 190)  # +30

        self.generation = QLineEdit(self)
        self.generation.setText("7")
        self.generation.setMinimumWidth(60)
        self.generation.setMaximumWidth(60)
        self.generation.setMinimumHeight(20)
        self.generation.setMaximumHeight(20)
        self.generation.move(150, 185)  # +30

        self.mutation_rate_label = QLabel("mutation rate:", self)
        self.mutation_rate_label.move(5, 210)  # +30

        self.mutation_rate = QLineEdit(self)
        self.mutation_rate.setText("8")
        self.mutation_rate.setMinimumWidth(60)
        self.mutation_rate.setMaximumWidth(60)
        self.mutation_rate.setMinimumHeight(20)
        self.mutation_rate.setMaximumHeight(20)
        self.mutation_rate.move(150, 215)  # +30

        self.tournament_size_label = QLabel("tournament size:", self)
        self.tournament_size_label.move(5, 240)  # +30

        self.tournament_size = QLineEdit(self)
        self.tournament_size.setText("9")
        self.tournament_size.setMinimumWidth(60)
        self.tournament_size.setMaximumWidth(60)
        self.tournament_size.setMinimumHeight(20)
        self.tournament_size.setMaximumHeight(20)
        self.tournament_size.move(150, 245)  # +30

        self.elitism_label = QLabel("elitism:", self)
        self.elitism_label.move(5, 270)  # +30

        self.elitism = QComboBox(self)
        self.elitism.addItems(self.elitism_possibly_values)
        self.elitism.setMinimumWidth(60)
        self.elitism.setMaximumWidth(60)
        self.elitism.setMinimumHeight(20)
        self.elitism.setMaximumHeight(20)
        self.elitism.move(150, 275)  # +30

        self.destination_min_label = QLabel("dest min:", self)
        self.destination_min_label.move(5, 300)  # +30

        self.dest_min = QLineEdit(self)
        self.dest_min.setText("4")
        self.dest_min.setMinimumWidth(60)
        self.dest_min.setMaximumWidth(60)
        self.dest_min.setMinimumHeight(20)
        self.dest_min.setMaximumHeight(20)
        self.dest_min.move(150, 305)  # +30

        self.destination_max_label = QLabel("dest max:", self)
        self.destination_max_label.move(5, 330)  # +30

        self.dest_max = QLineEdit(self)
        self.dest_max.setText("10")
        self.dest_max.setMinimumWidth(60)
        self.dest_max.setMaximumWidth(60)
        self.dest_max.setMinimumHeight(20)
        self.dest_max.setMaximumHeight(20)
        self.dest_max.move(150, 335)  # +30

        self.generate_graph_button = QPushButton("Generate graph!", self)
        self.generate_graph_button.setMinimumWidth(170)
        self.generate_graph_button.move(25, 365)

        self.start_evolution_button = QPushButton("Start evolution!", self)
        self.start_evolution_button.setMinimumWidth(170)
        self.start_evolution_button.move(25, 395)

        self.start_evolution_button.clicked.connect(self.start_evolution)
        self.generate_graph_button.clicked.connect(self.generate_graph)
        #self.get_list_of_possibly_airports() #TODO to have full list of airports in QComboBox

    def generate_graph(self):
        self.params = {
            'graph': None,
            'start_idx': int(self.start_airport.text()),
            'end_idx': int(self.destination_airport.text()),
            'max_flights': int(self.max_flights.text()),
            'cost_weight': int(self.cost_weight.text()),
            'time_weight': int(self.time_weight.text()),
            'pop_size': int(self.pop_size.text()),
            'generations': int(self.generation.text()),
            'mutation_rate': float(self.mutation_rate.text()),
            'tournament_size': int(self.tournament_size.text()),
            'elitism': bool(self.elitism.currentText()),
            'dest_min': int(self.dest_min.text()),
            'dest_max': int(self.dest_max.text()),
            'max_flights': 4,
        }
        data = DataGenerator()
        DataGenerator.DESTINATIONS_MIN = self.params['dest_min']
        DataGenerator.DESTINATIONS_MAX = self.params['dest_max']

        # if input_graph_file is not None:
        #     data.load_saved_graph(input_graph_file)
        #
        # else:
        #TODO ilosc lotnisk
        data.load_new_data(10)
        data.create_graph()

        # if graph_save_file is not None:
        #     data.save_graph(graph_save_file)

        testsuite_airports = data.get_airports()
        testsuite_graph = data.get_graph()

        self.graph = GraphManager(self.params['max_flights'])
        self.graph.set_graph(testsuite_graph, testsuite_airports)

        airports_parser = Testsuite_airports_parser(testsuite_airports)

    def start_evolution(self):
        import pprint
        self.params = {
            'graph': self.graph,
            'start_idx': int(self.start_airport.text()),
            'end_idx': int(self.destination_airport.text()),
            'max_flights': int(self.max_flights.text()),
            'cost_weight': int(self.cost_weight.text()),
            'time_weight': int(self.time_weight.text()),
            'pop_size': int(self.pop_size.text()),
            'generations': int(self.generation.text()),
            'mutation_rate': float(self.mutation_rate.text()),
            'tournament_size': int(self.tournament_size.text()),
            'elitism': bool(self.elitism.currentText()),
            'dest_min': int(self.dest_min.text()),
            'dest_max': int(self.dest_max.text()),
        }
        # pprint.pprint(params)
        self.output_of_algorithm = sys.__stdout__
        GA.run_with_params(self.params)
        self.newwindow()

    def newwindow(self):
        import pprint
        print("##############")
        pprint.pprint(self.output_of_algorithm)
        print("##############")
        self.wid = QWidget()
        self.wid.resize(250, 150)
        self.wid.setWindowTitle('NewWindow')
        self.result = QTextEdit(self.wid)
        self.result.setText(str(self.output_of_algorithm))
        #self.start_airport.addItems(self.airports)
        self.result.setMinimumHeight(200)
        self.result.setMaximumHeight(200)
        self.result.setMinimumWidth(600)
        self.start_airport.setMaximumWidth(600)
        # self.start_airport.move(150, 5)
        self.output_of_algorithm = None
        self.wid.show()
예제 #22
0
    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        # Select analysis file button
        button = QPushButton('Select analysis file', self)
        button.setToolTip('*.inp CalculiX analysis file.')
        button.move(10, 10)
        button.clicked.connect(self.on_click)

        # Text box - file path and name
        self.textbox_file_name = QLineEdit(self)
        self.textbox_file_name.move(120, 15)
        self.textbox_file_name.resize(420, 20)
        self.textbox_file_name.setText("None analysis file selected")
        self.textbox_file_name.setToolTip('Analysis file.')

        # Update button
        button1 = QPushButton('Update domains', self)
        button1.setToolTip(
            'Update naming inputs and material data from FreeCAD.')
        button1.move(10, 50)
        button1.clicked.connect(self.on_click1)

        # Domains definition

        # Label above domains definition
        label21 = QLabel('Domain 0', self)
        label21.setStyleSheet("font-weight: bold")
        label21.move(120, 50)

        label21 = QLabel('Domain 1', self)
        label21.setStyleSheet("font-weight: bold")
        label21.move(260, 50)

        label21 = QLabel('Domain 2', self)
        label21.setStyleSheet("font-weight: bold")
        label21.move(400, 50)

        label24 = QLabel('Material object', self)
        label24.move(20, 80)

        label25 = QLabel('Thickness object', self)
        label25.move(20, 110)

        label26 = QLabel('As design domain', self)
        label26.move(20, 140)

        label27 = QLabel('Stress limit [MPa]', self)
        label27.move(20, 170)

        # Combo box - select domain by material object
        self.combo = QComboBox(self)
        self.combo.setToolTip('Material object to define the domain.')
        self.combo.move(120, 80)
        self.combo.resize(140, 30)
        self.combo.currentIndexChanged.connect(self.on_change)

        self.combo1 = QComboBox(self)
        self.combo1.setToolTip('Material object to define the domain.')
        self.combo1.move(260, 80)
        self.combo1.resize(140, 30)
        self.combo1.currentIndexChanged.connect(self.on_change1)

        self.combo2 = QComboBox(self)
        self.combo2.setToolTip('Material object to define the domain.')
        self.combo2.move(400, 80)
        self.combo2.resize(140, 30)
        self.combo2.currentIndexChanged.connect(self.on_change2)

        # Combo box - select thickness object
        self.combo0t = QComboBox(self)
        self.combo0t.setToolTip(
            'Thickness object to specify if domain is for shells.')
        self.combo0t.move(120, 110)
        self.combo0t.resize(140, 30)

        self.combo1t = QComboBox(self)
        self.combo1t.setToolTip(
            'Thickness object to specify if domain is for shells.')
        self.combo1t.move(260, 110)
        self.combo1t.resize(140, 30)

        self.combo2t = QComboBox(self)
        self.combo2t.setToolTip(
            'Thickness object to specify if domain is for shells.')
        self.combo2t.move(400, 110)
        self.combo2t.resize(140, 30)

        self.textbox3 = QLineEdit(self)
        self.textbox3.move(120, 170)
        self.textbox3.resize(40, 20)
        # self.textbox3.setText("")
        self.textbox3.setToolTip(
            'Thickness [mm] of shell elements in the domain.\n'
            'This value overwrites thickness defined in FreeCAD')

        self.textbox4 = QLineEdit(self)
        self.textbox4.move(260, 170)
        self.textbox4.resize(40, 20)
        # self.textbox4.setText("")
        self.textbox4.setToolTip(
            'Thickness [mm] of shell elements in the domain.\n'
            'This value overwrites thickness defined in FreeCAD')

        self.textbox5 = QLineEdit(self)
        self.textbox5.move(400, 170)
        self.textbox5.resize(40, 20)
        # self.textbox5.setText("")
        self.textbox5.setToolTip(
            'Thickness [mm] of shell elements in the domain.\n'
            'This value overwrites thickness defined in FreeCAD')

        # Check box - design or nondesign
        self.checkbox = QCheckBox('', self)
        self.checkbox.setChecked(True)
        self.checkbox.setToolTip('Check to be the design domain.')
        self.checkbox.move(120, 140)

        self.checkbox1 = QCheckBox('', self)
        self.checkbox1.setChecked(True)
        self.checkbox1.setToolTip('Check to be the design domain.')
        self.checkbox1.move(260, 140)

        self.checkbox2 = QCheckBox('', self)
        self.checkbox2.setChecked(True)
        self.checkbox2.setToolTip('Check to be the design domain.')
        self.checkbox2.move(400, 140)

        # Text box - stress limit
        self.textbox = QLineEdit(self)
        self.textbox.move(120, 170)
        self.textbox.resize(40, 20)
        # self.textbox.setText("")
        self.textbox.setToolTip(
            'Von Mises stress [MPa] limit, when reached, material removing will stop.'
        )

        self.textbox1 = QLineEdit(self)
        self.textbox1.move(260, 170)
        self.textbox1.resize(40, 20)
        # self.textbox1.setText("")
        self.textbox1.setToolTip(
            'Von Mises stress [MPa] limit, when reached, material removing will stop.'
        )

        self.textbox2 = QLineEdit(self)
        self.textbox2.move(400, 170)
        self.textbox2.resize(40, 20)
        # self.textbox2.setText("")
        self.textbox2.setToolTip(
            'Von Mises stress [MPa] limit, when reached, material removing will stop.'
        )

        # Filters

        # Label above filter definition
        label31 = QLabel('Filter 0', self)
        label31.setStyleSheet("font-weight: bold")
        label31.move(120, 210)

        label32 = QLabel('Filter 1', self)
        label32.setStyleSheet("font-weight: bold")
        label32.move(260, 210)

        label33 = QLabel('Filter 2', self)
        label33.setStyleSheet("font-weight: bold")
        label33.move(400, 210)

        label34 = QLabel('Type', self)
        label34.move(20, 240)

        label35 = QLabel('Range [mm]', self)
        label35.move(20, 270)

        label36 = QLabel('Direction vector', self)
        label36.move(20, 300)

        label37 = QLabel('Apply to', self)
        label37.move(20, 330)

        # Combo box - select filter type
        self.combo6 = QComboBox(self)
        self.combo6.setToolTip(
            'Filters:\n'
            '"simple" to suppress checkerboard effect,\n'
            '"casting" to prescribe casting direction (opposite to milling direction)\n'
            'Recommendation: for casting use as first "casting" and as second "simple"'
        )
        self.combo6.addItem("None")
        self.combo6.addItem("simple")
        self.combo6.addItem("casting")
        self.combo6.setCurrentIndex(1)
        self.combo6.move(120, 240)
        self.combo6.currentIndexChanged.connect(self.on_change6)

        self.combo7 = QComboBox(self)
        self.combo7.setToolTip(
            'Filters:\n'
            '"simple" to suppress checkerboard effect,\n'
            '"casting" to prescribe casting direction (opposite to milling direction)\n'
            'Recommendation: for casting use as first "casting" and as second "simple"'
        )
        self.combo7.addItem("None")
        self.combo7.addItem("simple")
        self.combo7.addItem("casting")
        self.combo7.move(260, 240)
        self.combo7.currentIndexChanged.connect(self.on_change7)

        self.combo8 = QComboBox(self)
        self.combo8.setToolTip(
            'Filters:\n'
            '"simple" to suppress checkerboard effect,\n'
            '"casting" to prescribe casting direction (opposite to milling direction)\n'
            'Recommendation: for casting use as first "casting" and as second "simple"'
        )
        self.combo8.addItem("None")
        self.combo8.addItem("simple")
        self.combo8.addItem("casting")
        self.combo8.move(400, 240)
        self.combo8.currentIndexChanged.connect(self.on_change8)

        # Text box - filter range
        self.textbox6 = QLineEdit(self)
        self.textbox6.move(120, 270)
        self.textbox6.resize(50, 20)
        # self.textbox6.setText("")
        self.textbox6.setToolTip(
            'Filter range [mm], recommended two times mesh size.')

        self.textbox7 = QLineEdit(self)
        self.textbox7.move(260, 270)
        self.textbox7.resize(50, 20)
        # self.textbox7.setText("")
        self.textbox7.setToolTip(
            'Filter range [mm], recommended two times mesh size.')
        self.textbox7.setEnabled(False)

        self.textbox8 = QLineEdit(self)
        self.textbox8.move(400, 270)
        self.textbox8.resize(50, 20)
        # self.textbox8.setText("")
        self.textbox8.setToolTip(
            'Filter range [mm], recommended two times mesh size.')
        self.textbox8.setEnabled(False)

        # Text box - casting direction
        self.textbox9 = QLineEdit(self)
        self.textbox9.move(120, 300)
        self.textbox9.resize(80, 20)
        self.textbox9.setText("0, 0, 1")
        self.textbox9.setEnabled(False)
        self.textbox9.setToolTip(
            'Casting direction vector, e.g. direction in z axis:\n'
            '0, 0, 1\n\n'
            'solid              void\n'
            'XXXXXX.................\n'
            'XXX........................\n'
            'XX...........................          --> z axis\n'
            'XXXXX....................\n'
            'XXXXXXXXXXX......')

        self.textbox10 = QLineEdit(self)
        self.textbox10.move(260, 300)
        self.textbox10.resize(80, 20)
        self.textbox10.resize(80, 20)
        self.textbox10.setText("0, 0, 1")
        self.textbox10.setEnabled(False)
        self.textbox10.setToolTip(
            'Casting direction vector, e.g. direction in z axis:\n'
            '0, 0, 1\n\n'
            'solid              void\n'
            'XXXXXX.................\n'
            'XXX........................\n'
            'XX...........................          --> z axis\n'
            'XXXXX....................\n'
            'XXXXXXXXXXX......')

        self.textbox11 = QLineEdit(self)
        self.textbox11.move(400, 300)
        self.textbox11.resize(80, 20)
        self.textbox11.setText("0, 0, 1")
        self.textbox11.setEnabled(False)
        self.textbox11.setToolTip(
            'Casting direction vector, e.g. direction in z axis:\n'
            '0, 0, 1\n\n'
            'solid              void\n'
            'XXXXXX.................\n'
            'XXX........................\n'
            'XX...........................          --> z axis\n'
            'XXXXX....................\n'
            'XXXXXXXXXXX......')

        # list widget - select domains
        self.widget = QListWidget(self)
        self.widget.setToolTip(
            'Domains affected by the filter.\n'
            'Select only from domains which you defined above.')
        self.widget.move(120, 330)
        self.widget.resize(140, 120)
        self.widget.setSelectionMode(QAbstractItemView.MultiSelection)

        self.widget1 = QListWidget(self)
        self.widget1.setToolTip(
            'Domains affected by the filter.\n'
            'Select only from domains which you defined above.')
        self.widget1.move(260, 330)
        self.widget1.resize(140, 120)
        self.widget1.setSelectionMode(QAbstractItemView.MultiSelection)
        self.widget1.setEnabled(False)

        self.widget2 = QListWidget(self)
        self.widget2.setToolTip(
            'Domains affected by the filter.\n'
            'Select only from domains which you defined above.')
        self.widget2.move(400, 330)
        self.widget2.resize(140, 120)
        self.widget2.setSelectionMode(QAbstractItemView.MultiSelection)
        self.widget2.setEnabled(False)

        # Other settings
        label40 = QLabel('Other settings', self)
        label40.setStyleSheet("font-weight: bold")
        label40.move(10, 470)

        # AR, RR slider
        label41 = QLabel('Change per iteration:   low', self)
        label41.setFixedWidth(150)
        label41.move(10, 500)
        label42 = QLabel('high', self)
        label42.move(240, 500)

        self.slider = QSlider(Qt.Horizontal, self)
        self.slider.setRange(1, 3)
        self.slider.setSingleStep(1)
        self.slider.setValue(2)
        self.slider.move(150, 500)
        self.slider.resize(80, 30)
        self.slider.setToolTip(
            'Sets mass change per iteration, which is controlled as\n'
            'slow:   mass_addition_ratio=0.01,  mass_removal_ratio=0.02\n'
            'middle: mass_addition_ratio=0.015, mass_removal_ratio=0.03\n'
            'fast:   mass_addition_ratio=0.03,  mass_removal_ratio=0.06')

        # optimization base combobox
        label51 = QLabel('Optimization base', self)
        label51.move(10, 530)
        self.combo51 = QComboBox(self)
        self.combo51.setToolTip(
            'Basic principle to determine if element should remain or be removed:\n'
            '"stiffness" to maximize stiffness (minimize compliance),\n'
            '"heat" to maximize heat flow.')
        self.combo51.addItem("stiffness")
        self.combo51.addItem("heat")
        self.combo51.move(120, 530)

        # mass goal ratio
        label52 = QLabel('Mass goal ratio', self)
        label52.move(10, 560)
        self.textbox52 = QLineEdit(self)
        self.textbox52.move(120, 560)
        self.textbox52.resize(50, 20)
        self.textbox52.setText("0.4")
        self.textbox52.setToolTip(
            'Fraction of all design domains masses to be achieved;\n'
            'between 0 and 1.')

        # generate conf. file button
        button21 = QPushButton('Generate conf. file', self)
        button21.setToolTip(
            'Writes configuration file with optimization parameters.')
        button21.move(10, 600)
        button21.clicked.connect(self.on_click21)

        # edit conf. file button
        button22 = QPushButton('Edit conf. file', self)
        button22.setToolTip('Opens configuration file for hand modifications.')
        button22.move(10, 630)
        button22.clicked.connect(self.on_click22)

        # run optimization button
        button23 = QPushButton('Run optimization', self)
        button23.setToolTip('Writes configuration file and runs optimization.')
        button23.move(10, 660)
        button23.clicked.connect(self.on_click23)

        # generate conf file and run optimization button
        button24 = QPushButton('Generate conf.\nfile and run\noptimization',
                               self)
        button24.setToolTip('Writes configuration file and runs optimization.')
        button24.move(120, 600)
        button24.resize(100, 90)
        button24.clicked.connect(self.on_click24)

        # help buttons
        label41 = QLabel('Help', self)
        label41.move(440, 560)

        button31 = QPushButton('Example', self)
        button31.setToolTip(
            'https://github.com/fandaL/beso/wiki/Example-4:-GUI-in-FreeCAD')
        button31.move(440, 590)
        # button31.resize(80, 50)
        button31.clicked.connect(self.on_click31)

        button32 = QPushButton('Conf. comments', self)
        button32.setToolTip(
            'https://github.com/fandaL/beso/blob/master/beso_conf.py')
        button32.move(440, 620)
        # button32.resize(80, 50)
        button32.clicked.connect(self.on_click32)

        button33 = QPushButton('Close', self)
        button33.move(440, 690)
        # button33.resize(80, 50)
        button33.clicked.connect(self.on_click33)

        # open log file
        button40 = QPushButton('Open log file', self)
        button40.setToolTip('Opens log file in your text editor.\n'
                            '(Does not refresh automatically.)')
        button40.move(10, 690)
        button40.clicked.connect(self.on_click40)

        self.on_click1()  # first update
        self.show()
예제 #23
0
class Airport_project_UI(QWidget):

    airports = [
        'KRK',
        'LA',
        'LIS'
    ]

    elitism_possibly_values = ['true', 'false']

    max_flights_list = ['1', '2', '3', '4', '5']

    def __init__(self):
        QWidget.__init__(self)
        self.params = {}

       # self.setMinimumSize(600, 250)
        #self.setWindowTitle("Medody Optymalizacji - Projekt")
       # self.setIcon()

        self.start_airport_label = QLabel("Start airport:", self)
        self.start_airport_label.move(5, 10)
        self.start_airport = QLineEdit(self)
        self.start_airport.setText('1')
        #self.start_airport.addItems(self.airports)
        self.start_airport.setMinimumHeight(20)
        self.start_airport.setMaximumHeight(20)
        self.start_airport.setMinimumWidth(60)
        self.start_airport.setMaximumWidth(60)
        self.start_airport.move(150, 5)

#TODO function to convert names of airport to indexes

        self.destination_airport_label = QLabel("Destination airport:", self)
        self.destination_airport_label.move(5, 40)
        self.destination_airport = QLineEdit(self)
        self.destination_airport.setText('2')
       # self.destination_airport.addItems(self.airports)
        self.destination_airport.setMinimumHeight(20)
        self.destination_airport.setMaximumHeight(20)
        self.destination_airport.setMaximumWidth(60)
        self.destination_airport.setMinimumWidth(60)
        self.destination_airport.move(150, 35)

        self.max_flights_label = QLabel("max number of flights:", self)
        self.max_flights_label.move(5, 70)
        self.max_flights = QLineEdit(self)
        self.max_flights.setText("3")
        #self.max_flights.addItems(self.max_flights_list)
        self.max_flights.setMaximumHeight(20)
        self.max_flights.setMinimumHeight(20)
        self.max_flights.setMaximumWidth(60)
        self.max_flights.setMinimumWidth(60)
        #self.max_flights.setMinimumWidth(60)
        self.max_flights.move(150, 65)

        self.cost_weight_label = QLabel("max cost weights:", self)
        self.cost_weight_label.move(5, 100)
        self.cost_weight = QLineEdit(self)
        self.cost_weight.setText("4")
        self.cost_weight.setMinimumWidth(60)
        self.cost_weight.setMaximumWidth(60)
        self.cost_weight.setMinimumHeight(20)
        self.cost_weight.setMaximumHeight(20)
        self.cost_weight.move(150, 95)


        self.time_weight_label = QLabel("time weight:", self)
        self.time_weight_label.move(5, 130)
        self.time_weight = QLineEdit(self)
        self.time_weight.setText("5")
        self.time_weight.setMinimumWidth(60)
        self.time_weight.setMaximumWidth(60)
        self.time_weight.setMinimumHeight(20)
        self.time_weight.setMaximumHeight(20)
        self.time_weight.move(150, 125)

        self.pop_size_label = QLabel("pop size:", self)
        self.pop_size_label.move(5, 160)  # +30

        self.pop_size = QLineEdit(self)
        self.pop_size.setText("6")
        self.pop_size.setMinimumWidth(60)
        self.pop_size.setMaximumWidth(60)
        self.pop_size.setMinimumHeight(20)
        self.pop_size.setMaximumHeight(20)
        self.pop_size.move(150, 155) # +30

        self.generation_label = QLabel("generations:", self)
        self.generation_label.move(5, 190)  # +30

        self.generation = QLineEdit(self)
        self.generation.setText("7")
        self.generation.setMinimumWidth(60)
        self.generation.setMaximumWidth(60)
        self.generation.setMinimumHeight(20)
        self.generation.setMaximumHeight(20)
        self.generation.move(150, 185) # +30

        self.mutation_rate_label = QLabel("mutation rate:", self)
        self.mutation_rate_label.move(5, 210)  # +30

        self.mutation_rate = QLineEdit(self)
        self.mutation_rate.setText("8")
        self.mutation_rate.setMinimumWidth(60)
        self.mutation_rate.setMaximumWidth(60)
        self.mutation_rate.setMinimumHeight(20)
        self.mutation_rate.setMaximumHeight(20)
        self.mutation_rate.move(150, 215) # +30


        self.tournament_size_label = QLabel("tournament size:", self)
        self.tournament_size_label.move(5, 240)  # +30

        self.tournament_size = QLineEdit(self)
        self.tournament_size.setText("9")
        self.tournament_size.setMinimumWidth(60)
        self.tournament_size.setMaximumWidth(60)
        self.tournament_size.setMinimumHeight(20)
        self.tournament_size.setMaximumHeight(20)
        self.tournament_size.move(150, 245) # +30

        self.elitism_label = QLabel("elitism:", self)
        self.elitism_label.move(5, 270)  # +30

        self.elitism = QComboBox(self)
        self.elitism.addItems(self.elitism_possibly_values)
        self.elitism.setMinimumWidth(60)
        self.elitism.setMaximumWidth(60)
        self.elitism.setMinimumHeight(20)
        self.elitism.setMaximumHeight(20)
        self.elitism.move(150, 275) # +30

        self.destination_min_label = QLabel("dest min:", self)
        self.destination_min_label.move(5, 300)  # +30

        self.dest_min = QLineEdit(self)
        self.dest_min.setText("4")
        self.dest_min.setMinimumWidth(60)
        self.dest_min.setMaximumWidth(60)
        self.dest_min.setMinimumHeight(20)
        self.dest_min.setMaximumHeight(20)
        self.dest_min.move(150, 305) # +30

        self.destination_max_label = QLabel("dest max:", self)
        self.destination_max_label.move(5, 330)  # +30

        self.dest_max = QLineEdit(self)
        self.dest_max.setText("10")
        self.dest_max.setMinimumWidth(60)
        self.dest_max.setMaximumWidth(60)
        self.dest_max.setMinimumHeight(20)
        self.dest_max.setMaximumHeight(20)
        self.dest_max.move(150, 335) # +30

        self.generate_graph_button = QPushButton("Generate graph!", self)
        self.generate_graph_button.setMinimumWidth(170)
        self.generate_graph_button.move(25, 365)

        self.start_evolution_button = QPushButton("Start evolution!", self)
        self.start_evolution_button.setMinimumWidth(170)
        self.start_evolution_button.move(25, 395)

        self.start_evolution_button.clicked.connect(self.start_evolution)
        self.generate_graph_button.clicked.connect(self.generate_graph)
        #self.get_list_of_possibly_airports() #TODO to have full list of airports in QComboBox

    def generate_graph(self):
        self.params = {
            'graph'           : None,
            'start_idx'       : int(self.start_airport.text()),
            'end_idx'         : int(self.destination_airport.text()),
            'max_flights'     : int(self.max_flights.text()),
            'cost_weight'     : int(self.cost_weight.text()),
            'time_weight'     : int(self.time_weight.text()),
            'pop_size'        : int(self.pop_size.text()),
            'generations'     : int(self.generation.text()),
            'mutation_rate'   : float(self.mutation_rate.text()),
            'tournament_size' : int(self.tournament_size.text()),
            'elitism'         : bool(self.elitism.currentText()),
            'dest_min'        : int(self.dest_min.text()),
            'dest_max'        : int(self.dest_max.text()),
            'max_flights'     : 4,
        }
        data = DataGenerator()
        DataGenerator.DESTINATIONS_MIN = self.params['dest_min']
        DataGenerator.DESTINATIONS_MAX = self.params['dest_max']

        # if input_graph_file is not None:
        #     data.load_saved_graph(input_graph_file)
        #
        # else:
        #TODO ilosc lotnisk
        data.load_new_data(10)
        data.create_graph()

        # if graph_save_file is not None:
        #     data.save_graph(graph_save_file)

        testsuite_airports = data.get_airports()
        testsuite_graph = data.get_graph()

        self.graph = GraphManager(self.params['max_flights'])
        self.graph.set_graph(testsuite_graph, testsuite_airports)

        airports_parser = Testsuite_airports_parser(testsuite_airports)


    def start_evolution(self):
        import pprint
        self.params = {
        'graph'           : self.graph,
        'start_idx'       : int(self.start_airport.text()),
        'end_idx'         : int(self.destination_airport.text()),
        'max_flights'     : int(self.max_flights.text()),
        'cost_weight'     : int(self.cost_weight.text()),
        'time_weight'     : int(self.time_weight.text()),
        'pop_size'        : int(self.pop_size.text()),
        'generations'     : int(self.generation.text()),
        'mutation_rate'   : float(self.mutation_rate.text()),
        'tournament_size' : int(self.tournament_size.text()),
        'elitism'         : bool(self.elitism.currentText()),
        'dest_min'        : int(self.dest_min.text()),
        'dest_max'        : int(self.dest_max.text()),
        }
        # pprint.pprint(params)
        self.output_of_algorithm = sys.__stdout__
        GA.run_with_params(self.params)
        self.newwindow()

    def newwindow(self):
        import pprint
        print("##############")
        pprint.pprint(self.output_of_algorithm)
        print("##############")
        self.wid = QWidget()
        self.wid.resize(250, 150)
        self.wid.setWindowTitle('NewWindow')
        self.result = QTextEdit(self.wid)
        self.result.setText(str(self.output_of_algorithm))
        #self.start_airport.addItems(self.airports)
        self.result.setMinimumHeight(200)
        self.result.setMaximumHeight(200)
        self.result.setMinimumWidth(600)
        self.start_airport.setMaximumWidth(600)
        # self.start_airport.move(150, 5)
        self.output_of_algorithm = None
        self.wid.show()