Exemplo n.º 1
0
    def __init__(self, id, *argv):

        super(QtSingleApplication, self).__init__(*argv)
        self._id = id
        self._activationWindow = None
        self._activateOnMessage = False

        # Is there another instance running?
        self._outSocket = QtNetwork.QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            # Yes, there is.
            self._outStream = QtCore.QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            # No, there isn't.
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QtNetwork.QLocalServer(self)
            self._server.listen(self._id)
            self._server.newConnection.connect(self._onNewConnection)
            self.NAM = QtNetwork.QNetworkAccessManager(self)
Exemplo n.º 2
0
 def firstWindow(self, fileNames):
     """Open first main window"""
     try:
         # check for existing TreeLine session
         socket = QtNetwork.QLocalSocket()
         socket.connectToServer('treeline-session',
                                QtCore.QIODevice.WriteOnly)
         # if found, send files to open and exit TreeLine
         if socket.waitForConnected(1000):
             socket.write(repr(fileNames))
             if socket.waitForBytesWritten(1000):
                 socket.close()
                 sys.exit(0)
         qApp = QtGui.QApplication.instance()
         # start local server to listen for attempt to start new session
         self.serverSocket = QtNetwork.QLocalServer()
         self.serverSocket.listen('treeline-session')
         qApp.connect(self.serverSocket, QtCore.SIGNAL('newConnection()'),
                      self.getSocket)
     except AttributeError:
         print 'Warning:  Could not create local socket'
     if fileNames:
         fileNames = [unicode(fileName, globalref.localTextEncoding) for
                      fileName in fileNames]
         self.openMultipleFiles(fileNames)
     else:
         win = treemainwin.TreeMainWin()
         self.windowList.append(win)
         self.updateWinMenu()
         self.autoOpen()
         win.show()
     globalref.setStatusBar(_('Ready'), 2000)
Exemplo n.º 3
0
    def __init__(self, guid, *argv):
        super(QtSingleApplication, self).__init__(*argv)
        self._id = guid
        self._activationWindow = None
        self._activateOnMessage = False

        # Is there another instance running?
        self._outSocket = QtNetwork.QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            # Yes, there is.
            self._outStream = QtCore.QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            # No, there isn't.
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QtNetwork.QLocalServer()
            self._server.listen(self._id)
            # noinspection PyUnresolvedReferences
            self._server.newConnection.connect(
                self._onNewConnection
            )  # PyCharm doesn't recognize newConnection.connect()...
Exemplo n.º 4
0
    def __init__(self, argv):
        super(SingleApplication, self).__init__(argv)
        self.isSingle = True

        self.setApplicationName('HelloWord')
        serverName = self.applicationName()
        socket = QtNetwork.QLocalSocket()
        socket.connectToServer(serverName)
        if socket.waitForConnected(1000):
            # print u'已存在一个实例'
            self.isSingle = False
            return
        # print u'建立本地服务器'
        self.server = QtNetwork.QLocalServer(self)
        # self.server.listen(serverName)
        self.server.newConnection.connect(self.newLocalConnection)
        if not self.server.listen(serverName):
            #     print '听'
            # 防止程序崩溃时,残留进程服务,移除之
            # 确保监听成功
            if self.server.serverError() == QtNetwork.QAbstractSocket.AddressInUseError and \
                    QtCore.QFile.exists(self.server.serverName()):
                QtCore.QFile.remove(self.server.serverName())
        #       print u'什么情况?'
                self.server.listen(serverName)
Exemplo n.º 5
0
    def __init__(self):

        self.srv = QtNetwork.QLocalServer()
        self.receiver = None
        self.ses = {}

        self.is_connected = self.srv.connect(self.srv,
                                             QtCore.SIGNAL("newConnection()"),
                                             self.connected)
Exemplo n.º 6
0
    def __init__(self, settings):
        super(MainWindow, self).__init__()
        self.settings = settings
        self.last_dir = os.getcwd()
        self.defer_load = self.settings.INPUT

        self.actionOpen.activated.connect(self.on_open)
        self.actionCloseTab.activated.connect(self.close_tab)
        self.actionCloseAll.activated.connect(self.close_all)
        self.actionSavePlot.activated.connect(self.save_plot)
        self.actionLoadExtra.activated.connect(self.load_extra)
        self.actionOtherExtra.activated.connect(self.other_extra)
        self.actionClearExtra.activated.connect(self.clear_extra)
        self.actionScaleOpen.activated.connect(self.scale_open)
        self.actionNextTab.activated.connect(self.next_tab)
        self.actionPrevTab.activated.connect(self.prev_tab)
        self.actionRefresh.activated.connect(self.refresh_plot)

        self.viewArea.tabCloseRequested.connect(self.close_tab)
        self.viewArea.currentChanged.connect(self.activate_tab)

        self.plotDock.visibilityChanged.connect(self.plot_visibility)
        self.metadataDock.visibilityChanged.connect(self.metadata_visibility)
        self.metadataView.entered.connect(self.update_statusbar)
        self.expandButton.clicked.connect(self.metadata_column_resize)

        # Set initial value of checkboxes from settings
        self.checkZeroY.setChecked(self.settings.ZERO_Y)
        self.checkInvertY.setChecked(self.settings.INVERT_Y)
        self.checkDisableLog.setChecked(not self.settings.LOG_SCALE)
        self.checkScaleMode.setChecked(self.settings.SCALE_MODE)
        self.checkSubplotCombine.setChecked(self.settings.SUBPLOT_COMBINE)
        self.checkAnnotation.setChecked(self.settings.ANNOTATE)
        self.checkLegend.setChecked(self.settings.PRINT_LEGEND)
        self.checkTitle.setChecked(self.settings.PRINT_TITLE)
        self.checkFilterLegend.setChecked(self.settings.FILTER_LEGEND)

        self.checkZeroY.toggled.connect(self.update_checkboxes)
        self.checkInvertY.toggled.connect(self.update_checkboxes)
        self.checkDisableLog.toggled.connect(self.update_checkboxes)
        self.checkScaleMode.toggled.connect(self.update_checkboxes)
        self.checkSubplotCombine.toggled.connect(self.update_checkboxes)
        self.checkAnnotation.toggled.connect(self.update_checkboxes)
        self.checkLegend.toggled.connect(self.update_checkboxes)
        self.checkTitle.toggled.connect(self.update_checkboxes)
        self.checkFilterLegend.toggled.connect(self.update_checkboxes)

        # Start IPC socket server on name corresponding to pid
        self.server = QtNetwork.QLocalServer()
        self.sockets = []
        self.server.newConnection.connect(self.new_connection)
        self.server.listen(
            os.path.join(SOCKET_DIR,
                         "%s%d" % (SOCKET_NAME_PREFIX, os.getpid())))

        self.read_settings()
Exemplo n.º 7
0
    def checkConnection(self):
        from PyQt4 import QtNetwork

        self.socket = QtNetwork.QLocalSocket(self)
        self.connect(self.socket, QtCore.SIGNAL('connected()'),
                     self.onSocketConnected)
        self.socket.connectToServer(self.serverName)
        if not self.socket.waitForConnected(1000):
            self.isServer = True

        if self.isServer:
            self.server = QtNetwork.QLocalServer()
            self.connect(self.server, QtCore.SIGNAL('newConnection()'),
                         self.onNewConnection)
            QtNetwork.QLocalServer.removeServer(self.serverName)
Exemplo n.º 8
0
    def __init__(self, argv, catalog):
        QApplication.__init__(self, argv)
        self.aboutToQuit.connect(self.cleanup)
        self.control = QtNetwork.QLocalServer(self)
        self.control.newConnection.connect(self.onControlConnect)
        self.mainwindow = None
        self.catalog = '%s-pds.socket' % catalog

        self._init_translations()

        self.readyToRun = self.control.listen(self.catalog)

        if not self.readyToRun:
            if self.sendToInstance('show-mainwindow'):
                sys.exit()
            else:
                self.control.removeServer(self.catalog)
                self.readyToRun = self.control.listen(self.catalog)
Exemplo n.º 9
0
    def __init__(self, parent=None):
        super(Server, self).__init__(parent)

        statusLabel = QtGui.QLabel()
        statusLabel.setWordWrap(True)
        quitButton = QtGui.QPushButton("Quit")
        quitButton.setAutoDefault(False)

        self.fortunes = (
            "You've been leading a dog's life. Stay off the furniture.",
            "You've got to think about tomorrow.",
            "You will be surprised by a loud noise.",
            "You will feel hungry again in another hour.",
            "You might have mail.",
            "You cannot kill time without injuring eternity.",
            "Computers are not intelligent. They only think they are.",
        )

        self.server = QtNetwork.QLocalServer()
        if not self.server.listen('fortune'):
            QtGui.QMessageBox.critical(
                self, "Fortune Server",
                "Unable to start the server: %s." % self.server.errorString())
            self.close()
            return

        statusLabel.setText("The server is running.\nRun the Fortune Client "
                            "example now.")

        quitButton.clicked.connect(self.close)
        self.server.newConnection.connect(self.sendFortune)

        buttonLayout = QtGui.QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle("Fortune Server")
Exemplo n.º 10
0
    def __init__(self, appid, *argv):

        super(QtSingleApplication, self).__init__(*argv)
        self._id = appid
        self._activation_window = None
        self._activateOnMessage = False

        self._outSocket = QtNetwork.QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            self._outStream = QtCore.QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QtNetwork.QLocalServer()
            self._server.listen(self._id)
            self._server.newConnection.connect(self._on_new_connection)
Exemplo n.º 11
0
    def __init__(self, filePaths, parent=None):
        """Initialize the main tree controls

        Arguments:
            filePaths -- a list of files to open
            parent -- the parent QObject if given
        """
        super().__init__(parent)
        self.localControls = []
        self.activeControl = None
        self.pluginInterface = None
        self.pluginInstances = []
        self.pluginDescriptions = []
        self.configDialog = None
        self.sortDialog = None
        self.numberingDialog = None
        self.findTextDialog = None
        self.findConditionDialog = None
        self.findReplaceDialog = None
        self.filterTextDialog = None
        self.filterConditionDialog = None
        self.basicHelpView = None
        self.serverSocket = None
        self.passwords = {}
        globalref.mainControl = self
        try:
            # check for existing TreeLine session
            socket = QtNetwork.QLocalSocket()
            socket.connectToServer('treeline2-session',
                                   QtCore.QIODevice.WriteOnly)
            # if found, send files to open and exit TreeLine
            if socket.waitForConnected(1000):
                socket.write(bytes(repr(filePaths), 'utf-8'))
                if socket.waitForBytesWritten(1000):
                    socket.close()
                    sys.exit(0)
            # start local server to listen for attempt to start new session
            self.serverSocket = QtNetwork.QLocalServer()
            self.serverSocket.listen('treeline2-session')
            self.serverSocket.newConnection.connect(self.getSocket)
        except AttributeError:
            print(_('Warning:  Could not create local socket'))
        mainVersion = '.'.join(__version__.split('.')[:2])
        globalref.genOptions = options.Options('general', 'GmEdit',
                                               mainVersion, 'gmedit')
        optiondefaults.setGenOptionDefaults(globalref.genOptions)
        globalref.miscOptions = options.Options('misc')
        optiondefaults.setMiscOptionDefaults(globalref.miscOptions)
        globalref.histOptions = options.Options('history')
        optiondefaults.setHistOptionDefaults(globalref.histOptions)
        globalref.toolbarOptions = options.Options('toolbar')
        optiondefaults.setToolbarOptionDefaults(globalref.toolbarOptions)
        globalref.keyboardOptions = options.Options('keyboard')
        optiondefaults.setKeyboardOptionDefaults(globalref.keyboardOptions)
        try:
            globalref.genOptions.readFile()
            globalref.miscOptions.readFile()
            recentfiles.setRecentOptionDefaults()
            globalref.histOptions.readFile()
            globalref.toolbarOptions.readFile()
            globalref.keyboardOptions.readFile()
        except IOError:
            QtGui.QMessageBox.warning(
                QtGui.QApplication.activeWindow(), 'GmEdit',
                _('Error - could not write config file to {}').format(
                    options.Options.basePath))
        iconPathList = self.findResourcePaths('icons', iconPath)
        globalref.toolIcons = icondict.IconDict(
            [os.path.join(path, 'toolbar') for path in iconPathList],
            ['', '32x32', '16x16'])
        globalref.toolIcons.loadAllIcons()
        windowIcon = globalref.toolIcons.getIcon('gm_logo')
        if windowIcon:
            QtGui.QApplication.setWindowIcon(windowIcon)
        globalref.treeIcons = icondict.IconDict(iconPathList, ['', 'tree'])
        self.recentFiles = recentfiles.RecentFileList()
        if globalref.genOptions.getValue('AutoFileOpen') and not filePaths:
            recentPath = self.recentFiles.firstPath()
            if recentPath:
                filePaths = [recentPath]
        self.allActions = {}
        self.setupActions()
        QtGui.qApp.focusChanged.connect(self.updateActionsAvail)
        if filePaths:
            for path in filePaths:
                self.openFile(path)
        else:
            self.createLocalControl()
        self.setupPlugins()