示例#1
0
 def __init__(self):
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.setupUi()
     self.tipPupup = TipPupup()
     self.presenter = MainWindowPresenter(self)
     self.setupSignals()
示例#2
0
 def __init__(self):
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.setupUi()
     self.tipPupup = TipPupup()
     self.presenter = MainWindowPresenter(self)
     self.setupSignals()
示例#3
0
 def __init__(self, parent=None):
     QtGui.QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.setWindowIcon(QtGui.QIcon(config.LOGO_PNG))
     self.ui.archView.setPixmap(QtGui.QPixmap(config.ARCH_PNG))
     self.ui.versionLabel.setText(config.VERSION_INFO)
     self.setupUi_disconnected()
     self.tipPupup = TipPupup()
     self.presenter = MainWindowPresenter(self)
     self.bleproxyAddressDialog = BleproxyAddressDialog(self)
     self.progressDialog = ProgressDialog(self)
     self.menuManager = MenuManager(self)
     self.setupSignals()
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.project = Project()
        self.virtualLinksEditor = VirtualLinksEditor(
            self.ui.treeWidgetVirtualLinks, self.project)
        self.dataFlowsEditor = DataFlowsEditor(self.ui.treeWidgetDataFlows,
                                               self.project)
        self.canvas = NetworkCanvas(self.ui.networkArea,
                                    self.virtualLinksEditor,
                                    self.dataFlowsEditor)
        self.basename = self.windowTitle()
        self.ui.networkArea.setWidget(self.canvas)
        self.setWindowTitle(self.tr("Untitled") + " - " + self.basename)
        self.canvas.resources = self.project.resources
        self.projFilter = self.tr("AFDX projects (*.afdxxml)")
        self.limitJitter = True
        # time constraints
        self.esDelay = 0
        self.switchDelay = 16
        self.ifg = 0

        self.readProperties()
示例#5
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.setWindowTitle("IKnow")

        # DB-Connection
        self.dbConnection = DatabaseConnection()
        if self.dbConnection.connect():
            logging.info("Connected to the Database")
        else:
            logging.error("Failed to connect to the database")

        # Create Models
        self.tagModel = TagModel(self.dbConnection.db)
        self.knowledgeModel = KnowledgeModel(self.dbConnection.db)

        # Setup views
        self.ui.knowledgeTableView.setModel(self.knowledgeModel)
        self.ui.knowledgeTableView.hideColumn(0)
        self.ui.knowledgeTableView.setColumnWidth(1, 600)
        self.ui.knowledgeTableView.setColumnWidth(2, 700)

        self.ui.tagTreeWidget.setColumnWidth(0, 300)
        self.ui.tagTreeWidget.setColumnWidth(1, 30)

        # Load tags
        self.updateTagWidget()

        self.currentTag = None
        self.filterKnowledgeText = ""

        # Create menus
        act = QtGui.QAction("Remove selected Tag", self, statusTip="Remove the selected Tag. The child Tags are not touched.", triggered=self.removeSelectedTag)
        self.ui.tagTreeWidget.addAction(act)
        self.ui.tagTreeWidget.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

        # Connect signals and slots
        self.ui.tagTreeWidget.currentItemChanged.connect(self.tagChanged)
        self.ui.newTagButton.clicked.connect(self.showNewTagButtonDialog)
        self.ui.updateTagsButton.clicked.connect(self.updateTagWidget)
        self.ui.newKnowledgeButton.clicked.connect(self.showNewKnowledgeDialog)

        self.ui.filterTagsEdit.textChanged.connect(self.updateTagWidget)
        self.ui.filterKnowledgeEdit.textChanged.connect(self.filterKnowledgeByText)

        self.ui.knowledgeTableView.doubleClicked.connect(self.showEditKnowledgeDialog)
示例#6
0
 def __init__(self):
     QMainWindow.__init__(self)
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
     self.project = Project()
     self.virtualLinksEditor = VirtualLinksEditor(self.ui.treeWidgetVirtualLinks, self.project)
     self.dataFlowsEditor = DataFlowsEditor(self.ui.treeWidgetDataFlows, self.project)
     self.canvas = NetworkCanvas(self.ui.networkArea, self.virtualLinksEditor, self.dataFlowsEditor)
     self.basename = self.windowTitle()
     self.ui.networkArea.setWidget(self.canvas)
     self.setWindowTitle(self.tr("Untitled") + " - " + self.basename)
     self.canvas.resources = self.project.resources
     self.projFilter = self.tr("AFDX projects (*.afdxxml)")
     self.limitJitter = True
     # time constraints
     self.esDelay = 0
     self.switchDelay = 16
     self.ifg = 0
     
     self.readProperties()
示例#7
0
 def __init__(self):
     QMainWindow.__init__(self)
     Util.debug(2, "App", "Setting up UI")
     self.ui = Ui_MainWindow()
     self.ui.setupUi(self)
示例#8
0
class Pysciplot(QMainWindow):
    """
    This class initializes the PySciPlot program.
    """

    def __init__(self):
        QMainWindow.__init__(self)
        Util.debug(2, "App", "Setting up UI")
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
    
    def setup(self):
        """
        Setup the application.
        """

        # Variables
        Util.debug(2, "App", "Initializing variables")
        self._version = 1
        self._loadedModules = {}

        self.setDefaults()

        # Let the workspace resize when the main window is resized
        self.setCentralWidget(self.ui.workspace)

        # Make signal/slot connections
        Util.debug(2, "App", "Connecting signals and slots")
        self.ui.actionQuit.triggered.connect(self.close)
        self.ui.actionNew_Project.triggered.connect(self.newProjectSlot)
        self.ui.actionLoad_Project.triggered.connect(self.loadProjectSlot)
        self.ui.actionSave_Project.triggered.connect(self.saveProject)
        self.ui.actionSave_Project_As.triggered.connect(self.saveProjectAs)
        self.ui.actionSave_Current_Figure.triggered.connect(self.saveCurrentFigure)
        self.ui.actionPreferences.triggered.connect(self.preferences.showDialog)

        self.ui.actionShow_Waves.triggered.connect(self.printAllWaves)
        self.ui.actionShow_Figures.triggered.connect(self.printAllFigures)

        Util.debug(2, "App", "Loading modules")
        for moduleName in modules.__all__:
            module = eval(moduleName + "." + moduleName + "()")
            module.load()
            self._loadedModules[moduleName] = module

    def setDefaults(self):
        """
        Setup parts of the application that have some sort of default.
        Intended to be used when creating a new project to reset the application
        to a blank slate.
        """
        
        # Remove or hide any windows
        subWindows = self.ui.workspace.subWindowList()

        for window in subWindows:
            if type(window).__name__ in ["DataTableSubWindow", "FigureSubWindow"]:
                window.setAttribute(Qt.WA_DeleteOnClose)
                window.close()
            else:
                window.setVisible(False)

        # Remove signals
        try:
            self.waves().waveAdded.disconnect(self.model('appWaves').appendRow)
        except:
            pass
        try:
            self.waves().allWavesRemoved.disconnect(self.model('appWaves').removeAllWaves)
        except:
            pass

        # Set variables
        self._waves = Waves()
        self._figures = Figures()
        self._models = {}
        self.projectDir = "" # current project directory
        self.setCurrentProject("")
        self._storedSettings = {}   # this is a dict with widgetName: list pairs
                                    # where each list has [setting-name, setting-value] pairs
                                    # setting-value is a dict with (property-name: Property) pairs

        # Load Preferences
        Util.debug(2, "App", "Loading Preferences from file")
        self.preferences = Preferences("~/.pysciplotrc")

        # Create application-wide models
        self._models['appWaves'] = WavesListModel(self.waves().waveNames())

        # Signals
        self.waves().waveAdded.connect(self.model('appWaves').appendRow)
        self.waves().allWavesRemoved.connect(self.model('appWaves').removeAllWaves)

        # Reload modules
        for module in self._loadedModules.values():
            module.reload()

    def waves(self):
        """
        Return the app's Waves object.  NOT A LIST OF WAVES.
        """
        return self._waves

    def figures(self):
        """
        Return the app's Figures object.  NOT A LIST OF FIGURES.
        """
        return self._figures

    def storedSettings(self):
        """
        Return the storedSettings dict.
        """
        return self._storedSettings
    
    def models(self):
        """
        Return the models dict.
        """
        return self._models

    def model(self, name):
        """
        Return a specific model from the models dict.
        """
        return self._models[name]

    def createTable(self, waves=[], tableName="Table"):
        """
        Create a table.
        """

        Util.debug(2, "App.createTable", "Creating a table")
        model = DataTableModel(waves, self)

        # Connect slots
        self.waves().waveRemoved[Wave].connect(model.removeWave)
        self.waves().allWavesRemoved.connect(model.removeAllWaves)

        return self.createDataTableView(model, tableName)

    def createDataTableView(self, tableModel, tableName="Table"):
        """
        Create a table view based on the given model.
        """

        tableViewSubWindow = DataTableSubWindow(self.ui.workspace)
        tableView = QDataTableView(tableModel, tableName, tableViewSubWindow)
        tableViewSubWindow.setWidget(tableView)
        tableViewSubWindow.setAttribute(Qt.WA_DeleteOnClose)
        tableViewSubWindow.resize(600, 300)
        self.ui.workspace.addSubWindow(tableViewSubWindow)

        tableViewSubWindow.setVisible(True)

        return tableViewSubWindow

    def saveProjectAs(self):
        """
        Save the current project to a file which will be selected by the user.
        """

        Util.debug(2, "App.saveProjectAs", "Saving project as")
        
        fileName = str(QFileDialog.getSaveFileName(self.ui.workspace, "Save Project", self.projectDirectory(), "PySciPlot Project (*.psp);;All Files (*)"))

        Save.writeProjectToFile(self, fileName)

    def saveProject(self):
        """
        Save the current project to a file.  If project has previously been saved, use
        that location.
        """

        Util.debug(2, "App.saveProject", "Saving project")
        if self.currentProjectFile != "" and QFile.exists(self.currentProjectFile):
            Save.writeProjectToFile(self, self.currentProjectFile)
        else:
            self.saveProjectAs()

        
    def loadProjectSlot(self):
        """
        Slot to pick up menu selection and run loadProject.  Required because of different parameters.
        """
        self.loadProject()

    def loadProject(self, fileName="", confirmReset=True):
        """
        Load a project from a file which will be selected by the user.
        """

        Util.debug(2, "App.loadProject", "Loading project from file " + str(fileName))
        
        # Reset app to a clean slate
        self.resetToDefaults(confirmReset)
        
        # Now load the project
        if fileName == "":
            fileDialog = QFileDialog(self.ui.workspace, "Load Project")
            fileDialog.setNameFilter("PySciPlot Project (*.psp);;All Files (*)")
            fileDialog.setDefaultSuffix("psp")
            fileDialog.setConfirmOverwrite(False)
            fileDialog.setDirectory(self.projectDirectory())
            fileDialog.setAcceptMode(QFileDialog.AcceptOpen)
            fileDialog.exec_()
            fileName = str(fileDialog.selectedFiles()[0])
    
        Load.loadProjectFromFile(self, fileName)
        
    def newProjectSlot(self):
        """
        Slot to pick up menu selection and create a new project.  Required because of different parameters.
        """
        Util.debug(2, "App.newProject", "Creating new project")        
        self.resetToDefaults(True)

    def resetToDefaults(self, confirm=True):
        """
        Reset the application to the defaults.  At the very least,
        this will delete all waves, tables, and figures.

        Before resetting, this will ask the user if they want to save
        the current project.
        """
        
        Util.debug(2, "App.resetToDefaults", "Resetting application to defaults")
        
        if confirm:
            # Check to see if we want to save the current project
            saveProjectMessage = QMessageBox()
            saveProjectMessage.setText("You are about to load another project.")
            saveProjectMessage.setInformativeText("Do you want to save your current project?")
            saveProjectMessage.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
            saveProjectResponse = saveProjectMessage.exec_()
            if saveProjectResponse == QMessageBox.Save:
                self.saveProject()
            elif saveProjectResponse == QMessageBox.Cancel:
                return

        # Now reset to a clean slate
        self.setDefaults()

    def setCurrentProject(self, fileName):
        Util.debug(3, "App.setCurrentProject", "Setting current project title")
        self.currentProjectFile = fileName
        if fileName != "":
            self.setWindowTitle("PySciPlot - " + fileName)
        else:
            self.setWindowTitle("PySciPlot")

    def projectDirectory(self):
        if os.path.isdir(self.projectDir):
            return self.projectDir
        return self.preferences.getInternal('projectDirectory')

    def saveCurrentFigure(self):
        """
        Save the current figure to a file.

        First we make sure that the active window has a figure in it.
        Then we ask the user for certain options to be set.
        Then we ask for the file to save the figure to.
        Then we save the file.
        """

        Util.debug(2, "App.saveCurrentFigure", "Saving current Figure")

        currentWindow = self.ui.workspace.activeSubWindow()

        # Check if the active window has a figure in it
        if type(currentWindow).__name__ != "FigureSubWindow":
            notFigureMessage = QMessageBox()
            notFigureMessage.setText("The active window is not a figure, so you cannot save it as a figure.")
            notFigureMessage.exec_()
            return False
        
        # Ask user for user-configurable options
        figureOptionsDialog = QDialog()
        figureOptionsUi = Ui_SaveFigureOptionsDialog()
        figureOptionsUi.setupUi(figureOptionsDialog)
        figureOptionsSubWindow = self.ui.workspace.addSubWindow(figureOptionsDialog)
        figureOptionsResult = figureOptionsDialog.exec_()
        figureOptionsSubWindow.close()
        
        dpi = 100
        orientation = "Landscape"

        if figureOptionsResult == QDialog.Accepted:
            dpi = Util.getWidgetValue(figureOptionsUi.dpi)
            orientation = Util.getWidgetValue(figureOptionsUi.orientation)
        else:
            return False
        
        # As user for the filename to save to
        fileName = QFileDialog.getSaveFileName(self.ui.workspace, "Save Figure", self.projectDirectory())

        # Save the figure to the file
        currentWindow.widget().figure.savefig(str(fileName), dpi=dpi, orientation=orientation)


    ######################
    # temporary methods, for testing
    ######################
    def createDefaultTable(self):
        waveNames = self.model('appWaves').orderedWaveNames()
        waves = []
        for waveName in waveNames:
            waves.append(self.waves().wave(waveName))
        return self.createTable(waves)

    def printAllWaves(self):
        print self._waves

    def printAllFigures(self):
        print self._figures

    def setTestData(self):
        self._waves.addWave(Wave("Wave1", "Integer", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
        self._waves.addWave(Wave("Wave2", "Integer", [0, 1, 4, 9, 4, 1, 0, 1, 4, 9]))
        self._waves.addWave(Wave("Wave3", "Integer", [0, 1, 3, 1, 3, 1, 3, 1, 3, 1]))
        self._waves.addWave(Wave("Wave4", "Integer", [4, 3, 2, 1, 0, 1, 2, 3, 4, 5]))
示例#9
0
class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.setupUi()
        self.tipPupup = TipPupup()
        self.presenter = MainWindowPresenter(self)
        self.setupSignals()

    def setupUi(self):
        self.ui.setupUi(self)
        self.ui.sockTree.init()
        self.ui.qrcodeView.setPixmap(QtGui.QPixmap(config.QRCODE_ZFB))
        self.ui.githubBtn.setIcon(QtGui.QIcon(config.GITHUB_LOGO))
        self.setWindowIcon(QtGui.QIcon(config.LOGO_ICON))

    def setupSignals(self):
        self.ui.createBtn.clicked.connect(self.onCreateBtnClicked)
        self.ui.removeBtn.clicked.connect(self.onRemoveBtnClicked)
        self.ui.githubBtn.clicked.connect(self.onGithubBtnClicked)
        #self.ui.sockTree.itemClicked.connect(self.onSockItemClicked)
        self.ui.sockTab.currentChanged.connect(self.onSockTabClicked)
        self.connect(sigObject, signals.SIG_REMOTE_TCP_CLIENT_CONNECTED,
                     self.onRemoteTcpClientConnected)
        #self.connect(sigObject, signals.SIG_REMOTE_CLOSED, self.onRemoteClosed)
        self.connect(sigObject, signals.SIG_DATA_RECVED, self.onDataRecved)
        self.connect(sigObject, signals.SIG_REMOVE_SOCK_TAB,
                     self.onRemoveSockTab)

        self.connect(self.presenter.createTcpServerDialog,
                     signals.SIG_CREATE_TCP_SERVER, self.onCreateTcpServer)
        self.connect(self.presenter.createTcpClientDialog,
                     signals.SIG_CREATE_TCP_CLIENT, self.onCreateTcpClient)
        self.connect(self.presenter.createUdpServerDialog,
                     signals.SIG_CREATE_UDP_SERVER, self.onCreateUdpServer)
        self.connect(self.presenter.createUdpClientDialog,
                     signals.SIG_CREATE_UDP_CLIENT, self.onCreateUdpClient)

    def onCreateTcpServer(self, ip, port):
        self.presenter.createTcpServer(ip, port)

    def onCreateTcpClient(self, ip, port):
        self.presenter.createTcpClient(ip, port)

    def onCreateUdpClient(self, ip, remoteIp, localIp):
        self.presenter.createUdpClient(ip, remoteIp, localIp)

    def onCreateUdpServer(self, ip, port):
        self.presenter.createUdpServer(ip, port)

    def onDataRecved(self, _id, data):
        logger.debug("id=%d, data=%s" % (_id, data))
        self.ui.sockTab.addData(_id, data, config.RECV_TAG)

    # def onRemoteClosed(self, _id, parentId):
    # logger.debug("REMOTE CLOSED")
    #self.ui.sockTree.removeSocketItemById(_id)
    #self.presenter.removeRemoteTcpClientById(_id, parentId)

    def onRemoteTcpClientConnected(self, tcpClient, serverId, _id, address,
                                   port):
        self.ui.sockTree.addRemoteTcpClient(serverId, _id, address, port)
        self.ui.sockTab.addRemoteTcpClient(tcpClient, _id,
                                           "%s:%d" % (address, port))

    def onCreateBtnClicked(self):
        createDialog = self.presenter.getCreateDialog(
            self.ui.sockTree.currentItem())
        if createDialog is None:
            return

        createDialog.show_()

    def onSockItemClicked(self, sockItem, i):
        self.presenter.onSockItemClicked(sockItem)

    def onSockTabClicked(self, index):
        logger.debug("current sockTab index is %d" % index)
        self.ui.sockTab.clearUnreadIcon(index)

    def onGithubBtnClicked(self):
        self.presenter.openGithubSite()

    def onRemoveBtnClicked(self):
        self.onRemoveSockTab(None)

    def onRemoveSockTab(self, _id):
        self.presenter.removeSockTabById(_id)

    def onCreateTcpServerResult(self, _id, address):
        if _id > 0:
            self.ui.sockTree.addTcpServer(_id, address)
        else:
            self.tipPupup.makeErrorText(error.TCP_CREATE_FAILED)

    def onCreateUdpServerResult(self, udpServer, _id, address):
        if _id > 0:
            self.ui.sockTree.addUdpServer(_id, address)
            self.ui.sockTab.addUdpServer(udpServer, _id, address)

        else:
            self.tipPupup.makeErrorText(error.CREATE_UDP_SERVER_FAILED)

    def onCreateTcpClientResult(self, tcpClient, _id, address):
        if _id > 0:
            self.ui.sockTree.addLocalTcpClient(_id, address)
            self.ui.sockTab.addTcpClient(tcpClient, _id, address)
        else:
            self.tipPupup.makeErrorText(error.TCP_CLIENT_CONNECT_ERROR)

    def onCreateUdpClientResult(self, udpClient, _id, address):
        if _id > 0:
            self.ui.sockTree.addLocalUdpClient(_id, address)
            self.ui.sockTab.addUdpClient(udpClient, _id, address)
        else:
            self.tipPupup.makeErrorText(error.UDP_CLIENT_CONNECT_ERROR)

    def closeEvent(self, e):
        self.presenter.removeAllSockets()
        e.accept()
class MainWindow(QMainWindow):
    project = None
    projectFile = None

    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.project = Project()
        self.virtualLinksEditor = VirtualLinksEditor(
            self.ui.treeWidgetVirtualLinks, self.project)
        self.dataFlowsEditor = DataFlowsEditor(self.ui.treeWidgetDataFlows,
                                               self.project)
        self.canvas = NetworkCanvas(self.ui.networkArea,
                                    self.virtualLinksEditor,
                                    self.dataFlowsEditor)
        self.basename = self.windowTitle()
        self.ui.networkArea.setWidget(self.canvas)
        self.setWindowTitle(self.tr("Untitled") + " - " + self.basename)
        self.canvas.resources = self.project.resources
        self.projFilter = self.tr("AFDX projects (*.afdxxml)")
        self.limitJitter = True
        # time constraints
        self.esDelay = 0
        self.switchDelay = 16
        self.ifg = 0

        self.readProperties()

    # Read properties, if exists
    def readProperties(self):
        name = "options.cfg"
        if os.path.isfile(name):
            parser = ConfigParser.ConfigParser()
            parser.read(name)
            if parser.has_section("Options"):

                if parser.has_option("Options", "limitJitter"):
                    limitJitter = parser.getboolean("Options", "limitJitter")
                    self.limitJitter = limitJitter

                if parser.has_option("Options", "allowMultipleLinks"):
                    allowMultipleLinks = parser.getboolean(
                        "Options", "allowMultipleLinks")
                    self.canvas.allowMultipleLinks = allowMultipleLinks

                if parser.has_option("Options", "esDelay"):
                    esDelay = parser.getint("Options", "esDelay")
                    self.esDelay = esDelay

                if parser.has_option("Options", "switchDelay"):
                    switchDelay = parser.getint("Options", "switchDelay")
                    self.switchDelay = switchDelay

                if parser.has_option("Options", "ifg"):
                    ifg = parser.getint("Options", "ifg")
                    self.ifg = ifg

    def saveProperties(self):
        name = "options.cfg"
        if not os.path.isfile(name):
            open(name, 'a').close()

        parser = ConfigParser.ConfigParser()
        parser.read(name)
        if not parser.has_section("Options"):
            parser.add_section("Options")

        fileObj = open(name, "w")
        parser.set("Options", "limitJitter", self.limitJitter)
        parser.set("Options", "allowMultipleLinks",
                   self.canvas.allowMultipleLinks)
        parser.set("Options", "esDelay", self.esDelay)
        parser.set("Options", "switchDelay", self.switchDelay)
        parser.set("Options", "ifg", self.ifg)
        parser.write(fileObj)
        fileObj.close()

    def toggleSelect(self):
        self.ui.actionSelect.setChecked(True)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = State.Select

    def toggleEndSystem(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(True)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = State.EndSystem

    def togglePartition(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(True)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = State.Partition

    def toggleSwitch(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(True)
        self.canvas.state = State.Switch

    def toggleLink(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(True)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = State.Link

    def toggleVirtualLink(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = State.VirtualLink
        self.virtualLinksEditor.addVirtualLink()

    def toggleVirtualLinkItem(self, item):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = self.virtualLinksEditor.getState(item)
        self.canvas.selectVirtualLink(
            self.virtualLinksEditor.getVirtualLink(item))
        if (self.canvas.state == State.VirtualLinkPath):
            self.canvas.selectVirtualLinkPath(
                self.virtualLinksEditor.getVirtualLinkPath(item))

    def toggleVirtualLinkDoubleClicked(self, item):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.virtualLinksEditor.changeParam(item)

    def toggleRemoveVirtualLink(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        if self.canvas.state == State.VirtualLink:
            vl = self.virtualLinksEditor.removeSelected()
            self.dataFlowsEditor.updateAllDataFlows(vl)

    def toggleDataFlow(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.dataFlowsEditor.addDataFlow()
        self.canvas.state = State.DataFlow

    def toggleDataFlowItem(self, item):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.canvas.state = self.dataFlowsEditor.getState(item)
        self.canvas.selectDataFlow(self.dataFlowsEditor.getDataFlow(item))

    def toggleDataFlowDoubleClicked(self, item):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        self.dataFlowsEditor.changeParam(
            item, self.virtualLinksEditor.virtualLinks.values())

    def toggleRemoveDataFlow(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        if self.canvas.state == State.DataFlow:
            self.dataFlowsEditor.removeSelected()

    def resizeEvent(self, e):
        super(QMainWindow, self).resizeEvent(e)
        self.canvas.ResizeCanvas()

    def showEvent(self, e):
        super(QMainWindow, self).showEvent(e)
        self.canvas.ResizeCanvas()

    def closeEvent(self, e):
        self.canvas.updatePos()

    def New(self):
        self.project = Project()
        self.canvas.setData(self.project.resources)
        self.virtualLinksEditor.setProject(self.project)
        self.dataFlowsEditor.setProject(self.project)
        self.projectFile = None
        self.setWindowTitle(self.tr("Untitled") + " - " + self.basename)

    def Load(self):
        name = unicode(QFileDialog.getOpenFileName(filter=self.projFilter))
        if name == None or name == '':
            return
        self.OpenProjectFromFile(name)
        self.virtualLinksEditor.setProject(self.project)
        self.dataFlowsEditor.setProject(self.project)

    def OpenProjectFromFile(self, name):
        loadProject = Project()

        #try:
        loadProject.Load(name)
        #except:
        # TODO: proper exceptioning
        #    QMessageBox.critical(self, self.tr("An error occured"), self.tr("File is not a valid project file: ") + name)
        #    return
        self.project = loadProject
        self.projectFile = name
        self.canvas.setData(self.project.resources)
        self.setWindowTitle(self.project.name + " - " + self.basename)

    def Save(self):
        self.canvas.updatePos()
        if self.projectFile == None:
            self.SaveProjectAs()
        else:
            self.project.Save(self.projectFile)

    def SaveAs(self):
        self.canvas.updatePos()
        self.SaveProjectAs()

    def SaveProjectAs(self):
        self.canvas.updatePos()
        self.projectFile = unicode(
            QFileDialog.getSaveFileName(directory=self.project.name +
                                        ".afdxxml",
                                        filter=self.projFilter))
        if self.projectFile != '':
            self.project.Save(self.projectFile)
        self.setWindowTitle(
            self.projectFile.split('/').pop().split('.')[0] + " - " +
            self.basename)

    def verify(self):
        file = "tmp/tmp.afdxxml"
        self.project.Save(file)
        if sys.platform.startswith("win"):
            name = "algo/AFDX_DESIGN.exe"
        else:
            name = "algo/AFDX_DESIGN"
        if not os.path.isfile(name):
            QMessageBox.critical(
                self, self.tr("An error occured"),
                self.tr("Please build algorithm and put it into algo file"))
        else:
            #os.system(name + " \"" + os.path.relpath(file) + "\" ")
            result = os.popen(name + " \"" + os.path.relpath(file) +
                              "\" v").read()
            print result
            results = result.split('\n')
            if "Not all parameters are specified, some elements are omitted." in results:
                QMessageBox.critical(
                    self, "Warning",
                    "Not all parameters are specified, some elements are omitted."
                )
            QMessageBox.information(self, "Verification result", results[-2])

    def design(self):
        projectFile = self.projectFile
        self.canvas.updatePos()
        file = "tmp/tmp.afdxxml"
        self.project.Save(file)
        if sys.platform.startswith("win"):
            name = "algo/AFDX_DESIGN.exe"
        else:
            name = "algo/AFDX_DESIGN"
        if not os.path.isfile(name):
            QMessageBox.critical(
                self, self.tr("An error occured"),
                self.tr("Please build algorithm and put it into algo file"))
        else:
            limitJitter = " --limit-jitter="
            limitJitter += "t" if self.limitJitter else "f"
            esDelayText = " --es-fabric-delay=" + str(self.esDelay)
            switchDelayText = " --switch-fabric-delay=" + str(self.switchDelay)
            ifgText = " --interframe-gap=" + str(self.ifg)
            result = os.popen(name + " \"" + os.path.relpath(file) + "\" a" +
                              limitJitter + esDelayText + switchDelayText +
                              ifgText).read()
            print result
            results = result.split('\n')
            if "Not all parameters are specified, some elements are omitted." in results:
                QMessageBox.critical(
                    self, "Warning",
                    "Not all parameters are specified, some elements are omitted."
                )
            else:
                print "loading"
                self.OpenProjectFromFile(os.path.relpath(file))
                self.virtualLinksEditor.setProject(self.project)
                self.dataFlowsEditor.setProject(self.project)
                self.projectFile = projectFile

    def estimateResponseTimes(self):
        projectFile = self.projectFile
        self.canvas.updatePos()
        file = "tmp/tmp.afdxxml"
        self.project.Save(file)
        if sys.platform.startswith("win"):
            name = "algo/AFDX_DESIGN.exe"
        else:
            name = "algo/AFDX_DESIGN"
        if not os.path.isfile(name):
            QMessageBox.critical(
                self, self.tr("An error occured"),
                self.tr("Please build algorithm and put it into algo file"))
        else:
            esDelayText = " --es-fabric-delay=" + str(self.esDelay)
            switchDelayText = " --switch-fabric-delay=" + str(self.switchDelay)
            ifgText = " --interframe-gap=" + str(self.ifg)
            result = os.popen(name + " \"" + os.path.relpath(file) + "\" r" +
                              esDelayText + switchDelayText + ifgText).read()
            print result
            results = result.split('\n')
            if "Not all parameters are specified, some elements are omitted." in results:
                QMessageBox.critical(
                    self, "Warning",
                    "Not all parameters are specified, some elements are omitted."
                )
            else:
                print "loading"
                self.OpenProjectFromFile(os.path.relpath(file))
                self.virtualLinksEditor.setProject(self.project)
                self.dataFlowsEditor.setProject(self.project)
                self.projectFile = projectFile

    def RemoveAllVirtualLinks(self):
        self.ui.actionSelect.setChecked(False)
        self.ui.actionEndSystem.setChecked(False)
        self.ui.actionPartition.setChecked(False)
        self.ui.actionLink.setChecked(False)
        self.ui.actionSwitch.setChecked(False)
        if self.canvas.state == State.VirtualLink:
            vls = self.virtualLinksEditor.removeAll()
            for vl in vls:
                self.dataFlowsEditor.updateAllDataFlows(vl)

    def Options(self):
        d = OptionsDialog()
        d.Load(self)
        d.exec_()
        if d.result() == QDialog.Accepted:
            d.SetResult(self)
            self.saveProperties()
示例#11
0
    if not os.path.exists('data/processing/db'):
        os.makedirs('data/processing/db')
    if not os.path.exists('data/processing/images'):
        os.makedirs('data/processing/images')
    if not os.path.exists('data/processing/png8_test'):
        os.makedirs('data/processing/png8_test')
    if not os.path.exists('data/processing/predict'):
        os.makedirs('data/processing/predict')
    if not os.path.exists('data/processing/results'):
        os.makedirs('data/processing/results')


if __name__ == "__main__":

    CreateFiles()
    app = QApplication(sys.argv)
    mainWindow = QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(mainWindow)
    mainWindow.show()
    app.lastWindowClosed.connect(ui.player.CloseAll)
    camera1 = Camera("出矿口1", "data/mp4/ore1.mp4")
    camera2 = Camera("出矿口2", "data/mp4/ore1.mp4")
    camera3 = Camera("出矿口3", "data/mp4/ore1.mp4")
    camera4 = Camera("出矿口4", "data/mp4/ore1.mp4")
    ui.AddCamera(camera1)
    ui.AddCamera(camera2)
    ui.AddCamera(camera3)
    ui.AddCamera(camera4)
    sys.exit(app.exec_())