Пример #1
0
class StartQT4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.ui.clearButton.clicked.connect(self.clear)
        self.ui.goButton.clicked.connect(self.gocopy)

        self.kbd = PyKeyboard()

    def clear(self):
        self.ui.lineEdit.setText("")
        self.ui.spinBox.setProperty("value", 5)

    def gocopy(self):
        self.ui.goButton.setEnabled(False)
        self.ui.clearButton.setEnabled(False)
        QtGui.QApplication.processEvents()
        twait = self.ui.spinBox.value()
        #         print twait
        sleep(twait)
        text = self.ui.lineEdit.text()
        for c in text:
            sleep(0.3)
            #             self.kbd.press_key('q')
            #             self.kbd.release_key('q')
            self.kbd.tap_key(str(c), 1, 0)


#         self.kbd.type_string(text, 1)

        self.ui.goButton.setEnabled(True)
        self.ui.clearButton.setEnabled(True)
        QtGui.QApplication.processEvents()
Пример #2
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.ui.clearButton.clicked.connect(self.clear)
        self.ui.goButton.clicked.connect(self.gocopy)

        self.kbd = PyKeyboard()
Пример #3
0
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.statusBar = QtWidgets.QStatusBar()
        self.setStatusBar(self.statusBar)
        self.ui.memo_text_lb = QtWidgets.QLabel(self.ui.centralwidget, text='')
        self.statusBar.addWidget(self.ui.memo_text_lb)
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
        self.ui.actionLayer.setChecked(True)
        self.task_started = False
        self.timer_start = 0
        self.cur_task, self.cur_task_id = NULL_TASK, -1
        self.cur_period = TP_DEF
        self.cur_dialog = None
        prepare_db()
        self.saved_states = retrieve_saved_state()
        all_time_start = float(self.saved_states.get('all_time_start', '0'))
        # TODO correct it when manually added/edited time reports
        self.task_combo_init()
        self.tp_combo_init()
        self.timer = QtCore.QTimer()

        self.timer.timeout.connect(self.tick)
        self.ui.startStop_btn.clicked.connect(self.start_btn_clicked)
        self.ui.task_combo.currentIndexChanged.connect(self.new_task_selected)
        self.ui.tp_combo.currentIndexChanged.connect(self.new_period_selected)

        self.ui.actionAddTask.triggered.connect(partial(self.open_dialog, 'AddTaskDialog'))
        self.ui.actionAddMemo.triggered.connect(partial(self.open_dialog, 'MemoDialog'))
        self.ui.actionPeriodReport.triggered.connect(partial(self.open_dialog, 'ReportMainWindow', TIME_REPORT))
        self.ui.actionTaskReport.triggered.connect(partial(self.open_dialog, 'ReportMainWindow', TASK_REPORT))
        self.ui.actionLayer.triggered.connect(self.toggle_ontop)
Пример #4
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self) 
        
        # move to screen center
        screen = QtGui.QDesktopWidget().screenGeometry()
        windowsize = self.geometry()
        xcenter = (screen.width()  - windowsize.width())/2
        ycenter = (screen.height() - windowsize.height() - windowsize.height())/2
        self.move(xcenter, ycenter)
        
        # Attributes
        self.G = Graph(0, np.zeros((0,0), dtype = np.int32) )   # input graph
        self.p = [] # coordinates of the nodes
        self.pnew = []  # coordinates of the nodes after applying Force-Directed Graph Drawing Algorithm
        self.dist = np.zeros((0,0), dtype = np.int32)   # distance matrix of the graph
        self.step = 0   # iteration step
        
        # constants
        self.paramKK = sparamKK(1,1, 0.0001) # K, L0, eps
        self.paramHK = sparamHK(1, 7, 4, 3, 10) # L, Rad, It, Ratio, Minsize
        self.maxit = 1000
        
        self.k = np.zeros((0,0), dtype = np.int32)
        self.l = np.zeros((0,0), dtype = np.int32)
        
        # Methods        
        # initialise graph
        self.ui.pButton_generateG.clicked.connect(self.pButton_generateG_clicked)
        # run complete algorithm
        self.ui.pbuttonStart.clicked.connect(self.pButtonStart_clicked)
        # make one step of the algorithm
        self.ui.pbuttonStep.clicked.connect(self.pButtonStep_clicked)
        # run till the end from the current position
        self.ui.pbuttonContinue.clicked.connect(self.pButtonContinue_clicked)

        # plot labels
        self.showLabels = True
        self.ui.cBox_ShowLabels.clicked.connect(self.cBox_ShowLabels_clicked)
        # save current graph image
        self.ui.pbuttonSave_InitialG.clicked.connect(self.pButtonSaveImage1_clicked)
        self.ui.pbuttonSave.clicked.connect(self.pButtonSaveImage2_clicked)
    
        # delete result of algorithms 
        self.ui.pbuttonReset.clicked.connect(self.pButtonReset_clicked)     
        
        # hard coded examples
        self.connect(self.ui.actionExample_1, QtCore.SIGNAL('triggered()'), self.startExample_1)
        self.connect(self.ui.actionExample_2, QtCore.SIGNAL('triggered()'), self.startExample_2)
        self.connect(self.ui.actionExample_3, QtCore.SIGNAL('triggered()'), self.startExample_3)  

        self.readFromFile = False
        self.connect(self.ui.action_3eltGraph, QtCore.SIGNAL('triggered()'), self.startExample_3elt)
#        self.connect(self.ui.actionExample_2, QtCore.SIGNAL('triggered()'), self.startExample_2)
#        self.connect(self.ui.actionExample_3, QtCore.SIGNAL('triggered()'), self.startExample_3)  
        
        self.connect(self.ui.action_16x16, QtCore.SIGNAL('triggered()'), self.startExample_grid_16)
        self.connect(self.ui.action_grid32x32, QtCore.SIGNAL('triggered()'), self.startExample_grid_32)
        self.connect(self.ui.action_grid55x55, QtCore.SIGNAL('triggered()'), self.startExample_grid_55)
        
        self.connect(self.ui.action_sgrid16x16, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_16)
        self.connect(self.ui.action_sgrid32x32, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_32)
        self.connect(self.ui.action_sgrid40x40, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_40)
        
        # on parameter changed
        self.ui.textEdit_h.textChanged.connect(self.h_changed)
        self.ui.textEdit_eps.textChanged.connect(self.eps_changed)
        self.ui.textEdit_K.textChanged.connect(self.K_changed)
        self.ui.textEdit_L0.textChanged.connect(self.L0_changed)
        self.ui.textEdit_maxit.textChanged.connect(self.maxit_changed)
        
        self.ui.textEdit_l.textChanged.connect(self.L_changed)
        self.ui.textEdit_radius.textChanged.connect(self.Radius_changed)
        self.ui.textEdit_iterator.textChanged.connect(self.It_changed)
        self.ui.textEdit_ratio.textChanged.connect(self.Ratio_changed)
        self.ui.textEdit_minsize.textChanged.connect(self.Minsize_changed)
        
        # select Algorithm
        self.Alg_KamadaKawai = True
        self.Alg_HarelKoren = False
        self.connect(self.ui.rB_KamadaKawai, QtCore.SIGNAL('toggled(bool)'), self.select_Alg_KamadaKawai)
        self.connect(self.ui.rB_HarelKoren, QtCore.SIGNAL('toggled(bool)'), self.select_Alg_HarelKoren)
Пример #5
0
class MyWindowClass(QtGui.QMainWindow):#, form_class):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self) 
        
        # move to screen center
        screen = QtGui.QDesktopWidget().screenGeometry()
        windowsize = self.geometry()
        xcenter = (screen.width()  - windowsize.width())/2
        ycenter = (screen.height() - windowsize.height() - windowsize.height())/2
        self.move(xcenter, ycenter)
        
        # Attributes
        self.G = Graph(0, np.zeros((0,0), dtype = np.int32) )   # input graph
        self.p = [] # coordinates of the nodes
        self.pnew = []  # coordinates of the nodes after applying Force-Directed Graph Drawing Algorithm
        self.dist = np.zeros((0,0), dtype = np.int32)   # distance matrix of the graph
        self.step = 0   # iteration step
        
        # constants
        self.paramKK = sparamKK(1,1, 0.0001) # K, L0, eps
        self.paramHK = sparamHK(1, 7, 4, 3, 10) # L, Rad, It, Ratio, Minsize
        self.maxit = 1000
        
        self.k = np.zeros((0,0), dtype = np.int32)
        self.l = np.zeros((0,0), dtype = np.int32)
        
        # Methods        
        # initialise graph
        self.ui.pButton_generateG.clicked.connect(self.pButton_generateG_clicked)
        # run complete algorithm
        self.ui.pbuttonStart.clicked.connect(self.pButtonStart_clicked)
        # make one step of the algorithm
        self.ui.pbuttonStep.clicked.connect(self.pButtonStep_clicked)
        # run till the end from the current position
        self.ui.pbuttonContinue.clicked.connect(self.pButtonContinue_clicked)

        # plot labels
        self.showLabels = True
        self.ui.cBox_ShowLabels.clicked.connect(self.cBox_ShowLabels_clicked)
        # save current graph image
        self.ui.pbuttonSave_InitialG.clicked.connect(self.pButtonSaveImage1_clicked)
        self.ui.pbuttonSave.clicked.connect(self.pButtonSaveImage2_clicked)
    
        # delete result of algorithms 
        self.ui.pbuttonReset.clicked.connect(self.pButtonReset_clicked)     
        
        # hard coded examples
        self.connect(self.ui.actionExample_1, QtCore.SIGNAL('triggered()'), self.startExample_1)
        self.connect(self.ui.actionExample_2, QtCore.SIGNAL('triggered()'), self.startExample_2)
        self.connect(self.ui.actionExample_3, QtCore.SIGNAL('triggered()'), self.startExample_3)  

        self.readFromFile = False
        self.connect(self.ui.action_3eltGraph, QtCore.SIGNAL('triggered()'), self.startExample_3elt)
#        self.connect(self.ui.actionExample_2, QtCore.SIGNAL('triggered()'), self.startExample_2)
#        self.connect(self.ui.actionExample_3, QtCore.SIGNAL('triggered()'), self.startExample_3)  
        
        self.connect(self.ui.action_16x16, QtCore.SIGNAL('triggered()'), self.startExample_grid_16)
        self.connect(self.ui.action_grid32x32, QtCore.SIGNAL('triggered()'), self.startExample_grid_32)
        self.connect(self.ui.action_grid55x55, QtCore.SIGNAL('triggered()'), self.startExample_grid_55)
        
        self.connect(self.ui.action_sgrid16x16, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_16)
        self.connect(self.ui.action_sgrid32x32, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_32)
        self.connect(self.ui.action_sgrid40x40, QtCore.SIGNAL('triggered()'), self.startExample_sgrid_40)
        
        # on parameter changed
        self.ui.textEdit_h.textChanged.connect(self.h_changed)
        self.ui.textEdit_eps.textChanged.connect(self.eps_changed)
        self.ui.textEdit_K.textChanged.connect(self.K_changed)
        self.ui.textEdit_L0.textChanged.connect(self.L0_changed)
        self.ui.textEdit_maxit.textChanged.connect(self.maxit_changed)
        
        self.ui.textEdit_l.textChanged.connect(self.L_changed)
        self.ui.textEdit_radius.textChanged.connect(self.Radius_changed)
        self.ui.textEdit_iterator.textChanged.connect(self.It_changed)
        self.ui.textEdit_ratio.textChanged.connect(self.Ratio_changed)
        self.ui.textEdit_minsize.textChanged.connect(self.Minsize_changed)
        
        # select Algorithm
        self.Alg_KamadaKawai = True
        self.Alg_HarelKoren = False
        self.connect(self.ui.rB_KamadaKawai, QtCore.SIGNAL('toggled(bool)'), self.select_Alg_KamadaKawai)
        self.connect(self.ui.rB_HarelKoren, QtCore.SIGNAL('toggled(bool)'), self.select_Alg_HarelKoren)
    # end __init__
        
    # --------------------------------------------------------------------                 
    # Initialise graph 
    # --------------------------------------------------------------------       
    def h_changed(self):
        if self.ui.textEdit_h.toPlainText() != '':
            h = int(self.ui.textEdit_h.toPlainText())   # height of the complete binary tree
            self.ui.textEdit_nV.setText(QtCore.QString(str(2**h-1)))
        #end if    
    #end h_changed      
        
    def pButton_generateG_clicked(self):
        
        # init graph
        h = int(self.ui.textEdit_h.toPlainText())   # height of the complete binary tree
        n = 2**h-1
        self.ui.textEdit_nV.setText(QtCore.QString(str(n)))
        A = generate_full_binary_tree(h)
        
        self.G = Graph(n, A)
        
        # get values of the parameters
        self.paramKK.L0 = int(self.ui.textEdit_L0.toPlainText())   # length of rectangle side of display area
        self.paramKK.K   = int(self.ui.textEdit_K.toPlainText())
        self.paramKK.eps = float(self.ui.textEdit_eps.toPlainText())
        
        
        self.paramHK.L       = int(self.ui.textEdit_l.toPlainText())        # desired length of the edges
        self.paramHK.Rad     = int(self.ui.textEdit_radius.toPlainText())   # radius of local neighborhood
        self.paramHK.It      = int(self.ui.textEdit_iterator.toPlainText()) # number of iterations of local beautification
        self.paramHK.Ratio   = int(self.ui.textEdit_ratio.toPlainText())    # ration between number of nodes in two censecutive levels
        self.paramHK.Minsize = int(self.ui.textEdit_minsize.toPlainText())  # min size of the coarsest graph
        
        self.maxit = int(self.ui.textEdit_maxit.toPlainText())       
        
        # calculate graph distance
#        self.dist = floyed(A,n)
#        self.dist = dist_with_DijkstraAlg(A)
        self.dist = scipy.sparse.csgraph.dijkstra(A, directed = False, return_predecessors = False, unweighted = True)
     
        
        # calculate desirable length of single edge
        if self.Alg_HarelKoren:
            L = self.paramHK.L  
        else:
            L = self.paramKK.L0 / np.max(self.dist)           

        # calculate length of edges
        self.l = L * self.dist
        # calculate strength of spring between two nodes
        self.dist[range(n), range(n)] = np.Infinity         # just to get rif of division by zero error
        self.k = self.paramKK.K * 1./(self.dist**2) # attention, infinity on diagonals, but we dont need diagonal element
        
        self.dist[range(n), range(n)] = 0        # just to get rif of division by zero error
        
        # init coordinates
        self.readFromFile = False
        self.p = init_particles(n, self.paramKK.L0)  #particles p1, ... ,pn
        self.pnew = (self.p).copy()
        
        # plot initial graph
        self.plotGraph_onStart()
        self.plotGraph_Step()

        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: generated"))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end pButton_generateG_clicke

    # --------------------------------------------------------------------                 
    # Run complete algorithm 
    # --------------------------------------------------------------------                   
    def pButtonStart_clicked(self):
        
        # pnew      coordinates of the nodes
        # dist      distance matrix of the graph
        # k         strength of the edges
        # l         desired length of the edges
        # maxit     maximal number of iterations 
        
        self.pnew = (self.p).copy()
        
        if self.Alg_KamadaKawai:
            self.pnew, self.step = Algorithm_KamadaKawai(self.G.get_n(), self.pnew,            self.k, self.l, self.paramKK.eps, self.maxit)
        else:
            self.pnew, self.step = Algorithm_HarelKoren (self.G.get_n(), self.pnew, self.dist, self.k, self.l, self.paramHK)
        
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        self.plotGraph_Step()        
    # end pButtonStart_clicked

    # --------------------------------------------------------------------                 
    # Make one step of the algorithm
    # --------------------------------------------------------------------         
    def pButtonStep_clicked(self):
        
        if self.Alg_KamadaKawai:
            self.pnew = Algorithm_KamadaKawai_step(self.G.get_n(), self.pnew,            self.k, self.l, self.paramKK.eps, self.maxit)
        else:
            self.pnew = Algorithm_HarelKoren_step(self.G.get_n(), self.pnew, self.dist, self.k, self.l, self.paramHK)
        # end if
        # plot result of the step
        self.plotGraph_Step()
        
        self.step += 1
        
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))         
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonContinue.setEnabled(True)
    # end pButtonStep_clicked

    # --------------------------------------------------------------------                 
    # Run algorithm till end from the current position
    # --------------------------------------------------------------------         
    def pButtonContinue_clicked(self):
        
        # pnew      coordinates of the nodes
        # dist      distance matrix of the graph
        # k         strength of the edges
        # l         desired length of the edges
        # maxit     maximal number of iterations
        
        if self.Alg_KamadaKawai:
            self.pnew, nContSteps = Algorithm_KamadaKawai(self.G.get_n(), self.pnew,            self.k, self.l, self.paramKK.eps, self.maxit)
        else:
            self.pnew, nContSteps = Algorithm_HarelKoren (self.G.get_n(), self.pnew, self.dist, self.k, self.l, self.paramHK)
        
        self.step += nContSteps
        
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        self.plotGraph_Step() 
        
        self.ui.pbuttonStart.setEnabled(True)
    # end pButtonStep_clicked

    # --------------------------------------------------------------------                 
    # Delete result of algorithms 
    # --------------------------------------------------------------------  
    def pButtonReset_clicked(self):
               
        n = self.G.get_n()        
        self.step = 0
        
        # get values of the parameters
        self.paramKK.L0  = int(self.ui.textEdit_L0.toPlainText())   # length of rectangle side of display area
        self.paramKK.K   = int(self.ui.textEdit_K.toPlainText())
        self.paramKK.eps = float(self.ui.textEdit_eps.toPlainText())
        self.maxit       = int(self.ui.textEdit_maxit.toPlainText())
        
        self.paramHK.L       = int(self.ui.textEdit_l.toPlainText())        # desired length of the edges
        self.paramHK.Rad     = int(self.ui.textEdit_radius.toPlainText())   # radius of local neighborhood
        self.paramHK.It      = int(self.ui.textEdit_iterator.toPlainText()) # number of iterations of local beautification
        self.paramHK.Ratio   = int(self.ui.textEdit_ratio.toPlainText())    # ration between number of nodes in two censecutive levels
        self.paramHK.Minsize = int(self.ui.textEdit_minsize.toPlainText())  # min size of the coarsest graph
        self.paramHK.Startsize = self.paramHK.Minsize
               
        # calculate desirable length of single edge
        if self.Alg_HarelKoren:
            L = self.paramHK.L  
        else:
            L = self.paramKK.L0 / np.max(self.dist)            
        # calculate length of edges
        self.l = L * self.dist
        # calculate length of edges
        self.l = L * self.dist
        # calculate strength of spring between two nodes
        self.dist[range(n), range(n)] = np.Infinity         # just to get rif of division by zero error
        self.k = self.paramKK.K * 1./(self.dist**2) # attention, infinity on diagonals, but we dont need diagonal element
        self.dist[range(n), range(n)] = 0        # just to get rif of division by zero error
        
        # init coordinates
        if not self.readFromFile :
            self.p = init_particles(self.G.get_n(), self.paramKK.L0)  #particles p1, ... ,pn
        self.pnew = (self.p).copy()
        
        self.plotGraph_onStart()
        self.plotGraph_Step()
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)  
        self.ui.pbuttonContinue.setEnabled(False)
    #end pButtonReset_clicked        

    # --------------------------------------------------------------------                 
    # Save initial graph
    # --------------------------------------------------------------------                 
    def pButtonSaveImage1_clicked(self):
        fileName, flagOK= QtGui.QInputDialog.getText(self, 'Save image', 'File name to save:')
    
        if flagOK:
            fileName += ".png" 
            self.ui.MatplotlibWidget1.canvas.fig.savefig(str(fileName))
    # end pButtonSaveImage1_clicked
            
    # --------------------------------------------------------------------                 
    # Save new graph
    # --------------------------------------------------------------------         
    def pButtonSaveImage2_clicked(self):
        fileName, flagOK= QtGui.QInputDialog.getText(self, 'Save image', 'File name to save:')
    
        if flagOK:
            fileName += ".png" 
            self.ui.MatplotlibWidget2.canvas.fig.savefig(str(fileName))
    # end pButtonSaveImage2_clicked        
            
    # --------------------------------------------------------------------                 
    # Plot initial graph
    # --------------------------------------------------------------------  
    def cBox_ShowLabels_clicked(self):  # show labels or not
        if self.ui.cBox_ShowLabels.isChecked():
            self.showLabels = True
        else:
            self.showLabels = False
        if len(self.p)!=0:
            self.plotGraph_onStart()
            self.plotGraph_Step()
    #end cBox_ShowLabels_clicked
        
    def plotGraph_onStart(self):
        n = self.G.get_n()
        A = self.G.get_A()
        particls = self.p
        
        self.ui.MatplotlibWidget1.canvas.ax.clear()
        plot.scatter(particls[0,],particls[1,])
        self.ui.MatplotlibWidget1.canvas.ax.scatter(particls[0,],particls[1,])
        for i in range(n):
            for j in range(i+1,n):
                if A[i,j] < np.Infinity :
                    self.ui.MatplotlibWidget1.canvas.ax.plot([particls[0,i],particls[0,j]],
                                                             [particls[1,i],particls[1,j]])
                # end if
            # end for j
            # Annotate the points
            if self.showLabels:
                self.ui.MatplotlibWidget1.canvas.ax.annotate('{}'.format(i+1), 
                                                         xy=(particls[0,i],particls[1,i]),
                                                         xytext=(particls[0,i], particls[1,i]))
            #end if show labels
        # end for i        

        self.ui.MatplotlibWidget1.canvas.draw() 
    # end plotGraph_onStart
        
    # --------------------------------------------------------------------                 
    # Plot new graph
    # --------------------------------------------------------------------                 
    def plotGraph_Step(self):
        n = self.G.get_n()
        A = self.G.get_A()
        particls = self.pnew
        
        self.ui.MatplotlibWidget2.canvas.ax.clear()
        plot.scatter(particls[0,:],particls[1,:])
        self.ui.MatplotlibWidget2.canvas.ax.scatter(particls[0,],particls[1,])
        for i in range(n):
            for j in range(i+1,n):
                if i!=j and A[i,j] < np.Infinity :
                    self.ui.MatplotlibWidget2.canvas.ax.plot([particls[0,i],particls[0,j]],
                                                             [particls[1,i],particls[1,j]])
                # end if
            # end for j
            # Annotate the points                                           
            if self.showLabels:
                self.ui.MatplotlibWidget2.canvas.ax.annotate('{}'.format(i+1), 
                                                         xy=(particls[0,i],particls[1,i]),
                                                         xytext=(particls[0,i], particls[1,i]))
            #end if show labels                  
        # end for i
        self.ui.MatplotlibWidget2.canvas.draw() 
    # end plotGraph_Step
            
    # -------------------------------------------------------------------- 
    # Hard coded examples
    # --------------------------------------------------------------------     

    #                           Example 1            
    def startExample_1(self):
        self.readFromFile = False
        
        # init graph
        A = examplesKamadaKawai89.examplePicture2()
        n = np.size(A,0)   
        self.G = Graph(n, A)

#        self.dist = floyed(A,n)
        self.dist = dist_with_DijkstraAlg(A)    
                        
        self.pButtonReset_clicked()     # reset the algorithm

        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
                
        self.ui.labelStart.setText(QtCore.QString("Start: example1"))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_1
    
    #                           Example 2
    def startExample_2(self):
        self.readFromFile = False
        
        # init graph
        A = examplesKamadaKawai89.examplePicture3a()
        n = np.size(A,0)   
        self.G = Graph(n, A)
        
#        self.dist = floyed(A,n)
        self.dist = dist_with_DijkstraAlg(A)  

        self.pButtonReset_clicked()     # reset the algorithm

        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: example2"))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_2
       
    #                           Example 3
    def startExample_3(self):
        self.readFromFile = False                
        # init graph
        A = examplesKamadaKawai89.examplePicture5a()
        n = np.size(A,0)   
        self.G = Graph(n, A)
        
#        self.dist = floyed(A,n)
        self.dist = dist_with_DijkstraAlg(A)
 
        self.pButtonReset_clicked()     # reset the algorithm

        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: example3"))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_3               
    
     #                           Example Grid Graphs
    def startExample_grid_16(self):
        self.startExample_grid(16*16)
    #end startExample_grid_32:
        
    def startExample_grid_32(self):
        self.startExample_grid(32*32)
    #end startExample_grid_32:

    def startExample_grid_55(self):
        self.startExample_grid(55*55)
    #end startExample_grid_55:
    
    def startExample_grid(self, n):
        self.readFromFile = False        
        # not show labels by plotting
        self.showLabels = False
        self.ui.cBox_ShowLabels.setChecked(False)                
        
        # init graph (load adjacency matrix)
        A = examplesHarelKoren02.example_grid(n)
        self.G = Graph(n, A)

#        self.dist = floyed(A,n)
#        self.dist = dist_with_DijkstraAlg(A)
        starttime = time.time()
        self.dist = scipy.sparse.csgraph.dijkstra(A, directed = False, return_predecessors = False, unweighted = True)
        stoptime = time.time()        
        print "Time spent to calculate distance matrix of the graph({0:5d} nodes) with Scipy Dijkstra Alg: {1:0.6f} sec". format(n, stoptime-starttime)          

        self.pButtonReset_clicked()     # reset the algorithm
        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: Grid Graph|V|="+str(n)))
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_grid              
        
         #                           Example Sparse Grid Graphs    
    def startExample_sgrid_16(self):
        self.startExample_sgrid(16*16)
    #end startExample_grid_32:    

    def startExample_sgrid_32(self):
        self.startExample_sgrid(32*32)
    #end startExample_grid_32:

    def startExample_sgrid_40(self):
        self.startExample_sgrid(40*40)
    #end startExample_grid_55:    
        
    def startExample_sgrid(self, n):
        self.readFromFile = False
        # not show labels by plotting
        self.showLabels = False
        self.ui.cBox_ShowLabels.setChecked(False)                
        
        # init graph (load adjacency matrix)
        A = examplesHarelKoren02.example_sgrid(n)
        self.G = Graph(n, A)

#        self.dist = floyed(A,n)
#        self.dist = dist_with_DijkstraAlg(A)
        starttime = time.time()
        self.dist = scipy.sparse.csgraph.dijkstra(A, directed = False, return_predecessors = False, unweighted = True)
        stoptime = time.time()        
        print "Time spent to calculate distance matrix of the graph({0:5d} nodes) with Scipy Dijkstra Alg: {1:0.6f} sec". format(n, stoptime-starttime)          

        self.pButtonReset_clicked()     # reset the algorithm
        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: Grid Graph|V|="+str(n)))
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_grid        
    
    #                           Example_3elt
    def startExample_3elt(self):
        self.readFromFile = True
        
        # not show labels by plotting
        self.showLabels = False
        self.ui.cBox_ShowLabels.setChecked(False)                
        
        # init graph (load adjacency matrix and read coordinates of nodes)
        A, p = examplesHarelKoren02.example_3elt() 
        n = np.size(A,0)   
        self.G = Graph(n, A)
        self.p = p
        self.pnew = (self.p).copy()
        
#        self.dist = floyed(A,n)
#        self.dist = dist_with_DijkstraAlg(A) 
        starttime = time.time()
        self.dist = scipy.sparse.csgraph.dijkstra(A, directed = False, return_predecessors = False, unweighted = True)
        stoptime = time.time()        
        print "Time spent to calculate distance matrix of the graph({0:5d} nodes) with Scipy Dijkstra Alg: {1:0.6f} sec". format(n, stoptime-starttime)          
        
        self.pButtonReset_clicked()     # reset the algorithm     
        # set buttons enabled        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)
        self.ui.pbuttonContinue.setEnabled(False)

        self.ui.pbuttonSave.setEnabled(True)
        self.ui.pbuttonReset.setEnabled(True)        
        
        self.ui.labelStart.setText(QtCore.QString("Start: 3elt |V|="+str(n)))
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        self.ui.groupBox_Algorithm.setEnabled(True)
    # end startExample_3elt
        
    # -------------------------------------------------------------------- 
    # If parameter were changed
    # --------------------------------------------------------------------      
    def eps_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end eps_changed  

    def K_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end K_changed  

    def L0_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed  
        
    def maxit_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed 

    def L_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed  
        
    def Radius_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed     
        
    def It_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed     
        
    def Ratio_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
    #end maxit_changed     
    def Minsize_changed(self):
        self.ui.pbuttonStart.setEnabled(False)
        self.ui.pbuttonStep.setEnabled(False)    
        if self.ui.textEdit_minsize.toPlainText() != '' and  \
                                    int(self.ui.textEdit_minsize.toPlainText()<2):
            self.ui.textEdit_minsize.setText(QtCore.QString(str(2)))
            
    #end maxit_changed     
        
    # -------------------------------------------------------------------- 
    # select Algorithm
    # --------------------------------------------------------------------      
        
    def select_Alg_KamadaKawai(self):
        if self.ui.rB_KamadaKawai.isChecked():
            self.Alg_KamadaKawai = True
            self.Alg_HarelKoren = False
        else:
            self.Alg_KamadaKawai = False
            self.Alg_HarelKoren = True
            self.paramHK.Startsize = self.paramHK.Minsize# start size of the neighborhood
        #end if
        

        self.step = 0
        self.pnew = (self.p).copy()
        
        # calculate desirable length of single edge
        if self.Alg_HarelKoren:
            L = self.paramHK.L  
        else:
            L = self.paramKK.L0 / np.max(self.dist)           
        # calculate length of edges
        self.l = L * self.dist
        
#        self.plotGraph_onStart()
#        self.plotGraph_Step()
        
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)  
        self.ui.pbuttonContinue.setEnabled(False)        
    #end select_Alg_KamadaKawai(self)
    
    def select_Alg_HarelKoren(self):
        if self.ui.rB_HarelKoren.isChecked():
            self.Alg_KamadaKawai = False
            self.Alg_HarelKoren = True
            self.paramHK.Startsize = self.paramHK.Minsize# start size of the neighborhood
        else:
            self.Alg_KamadaKawai = True
            self.Alg_HarelKoren = False    #end select_Alg_HarelKoren(self):    
        #end if
                              
        self.step = 0
        self.pnew = (self.p).copy()
        
        # calculate desirable length of single edge
        if self.Alg_HarelKoren:
            L = self.paramHK.L  
        else:
            L = self.paramKK.L0 / np.max(self.dist)           

        # calculate length of edges
        self.l = L * self.dist
        
#        self.plotGraph_onStart()
#        self.plotGraph_Step()
        
        self.ui.labelResult.setText(QtCore.QString("Result: Step " + str(self.step)))
        
        self.ui.pbuttonStart.setEnabled(True)
        self.ui.pbuttonStep.setEnabled(True)  
        self.ui.pbuttonContinue.setEnabled(False)
Пример #6
0
 def __init__(self):
     super().__init__()
     self.settings = QSettings("Sunline", "sunline-automation")
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.readSettings()
Пример #7
0
class MyMainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.settings = QSettings("Sunline", "sunline-automation")
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.readSettings()

    def writeSettings(self):
        geometry = self.saveGeometry()
        self.settings.setValue('geometry', geometry)

        dockwidget_visible = self.ui.dockWidget.isVisible()
        self.settings.setValue('dockwidget_visible', dockwidget_visible)

        dockwidget_floating = self.ui.dockWidget.isFloating()
        self.settings.setValue('dockwidget_floating', dockwidget_floating)

        dockwidget_geometry = self.ui.dockWidget.saveGeometry()
        self.settings.setValue('dockwidget_geometry', dockwidget_geometry)

        area = self.dockWidgetArea(self.ui.dockWidget)
        self.settings.setValue('dockwidget_area', area)

    def readSettings(self):
        geometry = self.settings.value('geometry', type=QtCore.QByteArray)
        self.restoreGeometry(geometry)

        dockwidget_visible = self.settings.value('dockwidget_visible',
                                                 type=bool)
        self.ui.dockWidget.setVisible(dockwidget_visible)
        self.ui.actShowHideDockWidget.setChecked(dockwidget_visible)

        dockwidget_floating = self.settings.value('dockwidget_floating',
                                                  type=bool)
        self.ui.dockWidget.setFloating(dockwidget_floating)

        dockwidget_geometry = self.settings.value('dockwidget_geometry',
                                                  type=QtCore.QByteArray)
        self.ui.dockWidget.restoreGeometry(dockwidget_geometry)

        area = self.settings.value('dockwidget_area')
        if area is None:
            area = QtCore.Qt.DockWidgetArea(8)
        self.addDockWidget(area, self.ui.dockWidget)

    def closeEvent(self, e):
        reply = QMessageBox.question(self, 'Подтверждение',
                                     "Выйти из приложения?",
                                     QMessageBox.Yes | QMessageBox.No,
                                     QMessageBox.No)
        if reply == QMessageBox.Yes:
            self.form_close()
            self.writeSettings()
            e.accept()
        else:
            e.ignore()

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_Escape:
            self.close()
Пример #8
0
class TtForm(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.statusBar = QtWidgets.QStatusBar()
        self.setStatusBar(self.statusBar)
        self.ui.memo_text_lb = QtWidgets.QLabel(self.ui.centralwidget, text='')
        self.statusBar.addWidget(self.ui.memo_text_lb)
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
        self.ui.actionLayer.setChecked(True)
        self.task_started = False
        self.timer_start = 0
        self.cur_task, self.cur_task_id = NULL_TASK, -1
        self.cur_period = TP_DEF
        self.cur_dialog = None
        prepare_db()
        self.saved_states = retrieve_saved_state()
        all_time_start = float(self.saved_states.get('all_time_start', '0'))
        # TODO correct it when manually added/edited time reports
        self.task_combo_init()
        self.tp_combo_init()
        self.timer = QtCore.QTimer()

        self.timer.timeout.connect(self.tick)
        self.ui.startStop_btn.clicked.connect(self.start_btn_clicked)
        self.ui.task_combo.currentIndexChanged.connect(self.new_task_selected)
        self.ui.tp_combo.currentIndexChanged.connect(self.new_period_selected)

        self.ui.actionAddTask.triggered.connect(partial(self.open_dialog, 'AddTaskDialog'))
        self.ui.actionAddMemo.triggered.connect(partial(self.open_dialog, 'MemoDialog'))
        self.ui.actionPeriodReport.triggered.connect(partial(self.open_dialog, 'ReportMainWindow', TIME_REPORT))
        self.ui.actionTaskReport.triggered.connect(partial(self.open_dialog, 'ReportMainWindow', TASK_REPORT))
        self.ui.actionLayer.triggered.connect(self.toggle_ontop)


    def tick(self):
        delta = time() - self.timer_start
        self.ui.cur_time.display(str(timedelta(seconds=round(delta))))

    def start_btn_clicked(self):
        if not self.task_started:
            self.start_tracking()
        else:
            self.stop_tracking()

    def start_tracking(self):
        self.timer_start = time()
        self.timer.start(TIMER_TIMEOUT)
        self.task_started = True
        self.ui.startStop_btn.setText(LABEL_STOP)

    def stop_tracking(self):
        time_spent = time() - self.timer_start
        if time_spent < 0: time_spent = 0
            # TODO show error, propose to correct time
        log_time(self.cur_task_id, self.timer_start, self.timer_start + time_spent, time_spent, offline_l=0)
        self.timer.stop()
        self.task_started = False
        self.ui.startStop_btn.setText(LABEL_START)
        self.update_time_for_cur_period()

    def update_time_for_cur_period(self):
        # TODO period definition
        if self.cur_task_id > 0:
            start_t, end_t = period_to_timestamp(self.cur_period)
            total_time = select_time(self.cur_task_id, start_t, end_t)
            total_time_lb = time_to_str(total_time, TU_SECOND)
        else:
            total_time_lb = '0m'
        self.ui.totalForPeriod_lb.setText(total_time_lb)
        if self.task_started:
            self.ui.cur_time.display(str(timedelta(seconds=round(time() - self.timer_start))))
        else:
            self.ui.cur_time.display('0:00:00')

    def new_task_selected(self):
        if self.task_started:
            self.stop_tracking()
        self.proceed_selected_task()

    def proceed_selected_task(self):
        t_name = self.ui.task_combo.currentText()
        if len(t_name) == 0:
            self.cur_task, self.cur_task_id = NULL_TASK, -1
        else:
            self.cur_task, self.cur_task_id = t_name, self.all_tasks[t_name]
        self.update_time_for_cur_period()
        self.show_last_memo()

    def find_task_by_id(self, task_id):
        for t_name, t_id in self.all_tasks.items():
            if t_id == task_id:
                return t_name

    def update_task_combo(self):
        last_task_id = self.cur_task_id
        self.ui.task_combo.clear()
        self.task_combo_init(last_task_id)

    def select_another_task(self):
        pass
    # TODO select last entered task
    
    def task_combo_init(self, cur_task_id=-1):
        self.all_tasks = get_tasks()
        self.ui.task_combo.addItems(sorted(self.all_tasks.keys(), key=lambda t: t.lower()))
        try:
            if cur_task_id < 0:
                t_id = int(self.saved_states['last_task_id'])
            else:
                t_id = cur_task_id
            combo_text = self.find_task_by_id(t_id)
        except:
            combo_text = NULL_TASK
        self.ui.task_combo.setCurrentText(combo_text)
        self.proceed_selected_task()

    def tp_combo_init(self):
        self.ui.tp_combo.addItems(TP_LIST)
        ind = self.ui.tp_combo.findText(self.cur_period)
        if ind >= 0:
            self.ui.tp_combo.setCurrentIndex(ind)

    def new_period_selected(self):
        new_period = self.ui.tp_combo.currentText()
        for period in TP_LIST:
            if new_period == period:
                self.cur_period = period
        self.update_time_for_cur_period()

    def show_last_memo(self):
        if self.cur_task_id < 0: return
        memo = select_last_memo(self.cur_task_id)
        memo_to_show = '' if memo[0] is None \
            else ('Last Memo (' + str(datetime.fromtimestamp(int(memo[1]))) + '): ' + memo[0])
        self.ui.memo_text_lb.setText(memo_to_show)


    def closeEvent(self, event):
        self.safe_close()
        # event.accept()
        sys.exit(0)

    def terminate(self, signum, frame):
        self.safe_close()
        sys.exit(0)

    def safe_close(self):
        if self.cur_dialog:
            self.dialog_closed()
        if self.task_started:
            self.stop_tracking()
        save_cur_state([('last_task_id', str(self.cur_task_id))])

    def open_dialog(self, dial_name, dial_type):
        self.last_ontop_val = self.ui.actionLayer.isChecked()
        if self.last_ontop_val:
            self.toggle_ontop(False)
        self.ui.menubar.setEnabled(False)

        self.cur_dialog_name = dial_name
        constructor = globals()[dial_name]
        if dial_name == 'AddTaskDialog':
            dialog = constructor()
            dialog.task_added_s.connect(self.update_task_combo)
            dialog.task_added_s.connect(self.select_another_task)
        elif dial_name == 'MemoDialog':
            dialog = constructor(cur_task=self.cur_task, all_tasks=self.all_tasks)
            dialog.memo_added_s.connect(self.show_last_memo)
        elif dial_name == 'ReportMainWindow':
            cur_task = None
            if dial_type == TASK_REPORT:
                ddd = self.cur_task.find('::')
                cur_task = self.cur_task[ddd + 2:]
            dialog = constructor(cur_period=self.cur_period, cur_task=cur_task)
        self.cur_dialog = dialog
        self.cur_dialog.dialog_closed_s.connect(self.dialog_closed)
        dialog.show()
        # dialog.exec()

    def dialog_closed(self):
        if self.cur_dialog_name == 'AddTaskDialog':
            self.cur_dialog.task_added_s.disconnect(self.update_task_combo)
            self.cur_dialog.task_added_s.disconnect(self.select_another_task)
        elif self.cur_dialog_name == 'MemoDialog':
            self.cur_dialog.memo_added_s.disconnect(self.show_last_memo)
        self.cur_dialog.dialog_closed_s.disconnect(self.dialog_closed)
        self.cur_dialog = None
        self.ui.menubar.setEnabled(True)
        if self.last_ontop_val:
            self.toggle_ontop(True)

    def toggle_ontop(self, new_val=True):
        if self.ui.actionLayer.isChecked() and new_val:
            self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
        else:
            self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
        self.show()