本文整理汇总了Python中PyQt5.QtNetwork.QLocalServer.removeServer方法的典型用法代码示例。如果您正苦于以下问题:Python QLocalServer.removeServer方法的具体用法?Python QLocalServer.removeServer怎么用?Python QLocalServer.removeServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QLocalServer
的用法示例。
在下文中一共展示了QLocalServer.removeServer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def init():
"""Start listening to incoming connections."""
global _server
if _server is not None:
return
server = QLocalServer(None)
# find a free socket name to use
for name in ids():
if server.listen(name):
break
else:
# all names failed, try to contact and remove stale file if that fails
socket = QLocalSocket()
for name in ids():
socket.connectToServer(name)
if not socket.waitForConnected(10000):
QLocalServer.removeServer(name)
if server.listen(name):
break
else:
socket.disconnectFromServer()
else:
# no ids left, don't listen
return
app.aboutToQuit.connect(server.close)
server.newConnection.connect(slot_new_connection)
os.environ["FRESCOBALDI_SOCKET"] = name
_server = server
示例2: create
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def create(self, name=piony.G_SOCKET_NAME):
QLocalServer.removeServer(name)
self.server = QLocalServer()
if not self.server.listen(name):
print("Error: server -- unable to start: {}."
.format(self.server.errorString()))
self.quit.emit()
self.server.newConnection.connect(self.notify)
示例3: __init__
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def __init__(self, win_id, *argv):
logfunc = logging.info
logfunc(sys._getframe().f_code.co_name + '()')
QApplication.__init__(self, *argv)
self._id = win_id
self._activation_window = None
self._activate_on_message = False
# Is there another instance running?
self._outSocket = QLocalSocket()
self._outSocket.connectToServer(self._id)
self._isRunning = self._outSocket.waitForConnected()
self._outStream = None
self._inSocket = None
self._inStream = None
self._server = None
if self._isRunning:
# Yes, there is.
self._outStream = QTextStream(self._outSocket)
self._outStream.setCodec('UTF-8')
else:
# No, there isn't, at least not properly.
# Cleanup any past, crashed server.
error = self._outSocket.error()
logfunc(LOGVARSTR % ('self._outSocket.error()', error))
if error == QLocalSocket.ConnectionRefusedError:
logfunc('received QLocalSocket.ConnectionRefusedError; ' + \
'removing server.')
self.close()
QLocalServer.removeServer(self._id)
self._outSocket = None
self._server = QLocalServer()
self._server.listen(self._id)
self._server.newConnection.connect(self._on_new_connection)
logfunc(sys._getframe().f_code.co_name + '(): returning')
示例4: _remove_server
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def _remove_server(self):
"""Remove an existing server."""
ok = QLocalServer.removeServer(self._socketname)
if not ok:
raise Error("Error while removing server {}!".format(self._socketname))
示例5: _remove_server
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def _remove_server(self):
"""Remove an existing server."""
ok = QLocalServer.removeServer(SOCKETNAME)
if not ok:
raise IPCError("Error while removing server {}!".format(
SOCKETNAME))
示例6: __init__
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
def __init__(self, parent = None):
QDialog.__init__(self, parent)
# If a Nemu instance is already running, this is as far as we go
self.connectToRunning()
self.holdOpen = False
self.menuItems = []
self.allItems = []
self.favorites = []
self.currentItem = None
self.menuFile = os.path.expanduser('~/.nemu/menu')
self.favoritesFile = os.path.expanduser('~/.nemu/favorites')
# NOTE: If you change this, also update migrate-settings
self.settingsFile = os.path.expanduser('~/.nemu/settings')
self.initSettings()
self.server = QLocalServer()
self.server.newConnection.connect(self.handleConnection)
QLocalServer.removeServer('nemuSocket')
self.server.listen('nemuSocket')
self.configDir = os.path.expanduser('~/.nemu')
if not os.path.isdir(self.configDir):
os.mkdir(self.configDir)
self.menuItems = self.loadConfig(self.menuFile, self.menuItems)
self.favorites = self.loadConfig(self.favoritesFile, self.favorites)
# Don't load directly into self.settings so we can add new default values as needed
try:
tempSettings = self.loadConfig(self.settingsFile, self.settings)
for key, value in tempSettings.items():
self.settings[key] = value
except SystemError:
print('ERROR: Failed to load settings. You may need to run migrate-settings.')
raise
# This should never happen, but unfortunately bugs do, so clean up orphaned items.
# We need to do this because these items won't show up in the UI, but may interfere with
# merges if they duplicate something that is being merged in.
self.menuItems[:] = [i for i in self.menuItems if i.parent == None or i.parent in self.menuItems]
# Look for broken icon paths
needSave = False
for i in self.menuItems + self.favorites:
if not os.path.exists(i.icon):
i.findIcon()
needSave = True
if needSave:
self.saveMenu()
for i in self.menuItems:
if not hasattr(i, 'imported'):
i.imported = False
self.setupUI()
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.createMenu(self)
self.refresh(False)
if len(self.menuItems) == 0:
self.firstRun()
self.show()
self.keepaliveTimer = QTimer(self)
self.keepaliveTimer.timeout.connect(self.keepalive)
self.keepaliveTimer.start(60000)
示例7: SingleApplication
# 需要导入模块: from PyQt5.QtNetwork import QLocalServer [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalServer import removeServer [as 别名]
class SingleApplication(QtWidgets.QApplication):
'''
Inheriting from QApplication, executing main App instead.
Watching whether the app is already running.
If so, quit befor execution.
'''
messageReceived = QtCore.pyqtSignal(str)
def __init__(self, id, *argv):
super(SingleApplication, self).__init__(*argv)
self._id = id
self._activationWindow = None
self._activateOnMessage = False
# Check if another instance is running?
self._outSocket = 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 = QLocalServer()
self._server.removeServer(self._id) # if existing after crash-exit
self._server.listen(self._id)
self._server.newConnection.connect(self._onNewConnection)
def isRunning(self):
return self._isRunning
def id(self):
return self._id
def activationWindow(self):
return self._activationWindow
def setActivationWindow(self, activationWindow, activateOnMessage=True):
self._activationWindow = activationWindow
self._activateOnMessage = activateOnMessage
def activateWindow(self):
if not self._activationWindow:
return
self._activationWindow.setWindowState(
self._activationWindow.windowState() & ~QtCore.Qt.WindowMinimized)
self._activationWindow.show()
self._activationWindow.activateWindow()
def sendMessage(self, msg):
if not self._outStream:
return False
self._outStream << msg << '\n'
self._outStream.flush()
return self._outSocket.waitForBytesWritten()
def _onNewConnection(self):
if self._inSocket:
self._inSocket.readyRead.disconnect(self._onReadyRead)
self._inSocket = self._server.nextPendingConnection()
if not self._inSocket:
return
self._inStream = QtCore.QTextStream(self._inSocket)
self._inStream.setCodec('UTF-8')
self._inSocket.readyRead.connect(self._onReadyRead)
if self._activateOnMessage:
self.activateWindow()
def _onReadyRead(self):
while True:
msg = self._inStream.readLine()
if not msg:
break
self.messageReceived.emit(msg)