本文整理汇总了Python中PyQt5.QtNetwork.QLocalSocket.errorString方法的典型用法代码示例。如果您正苦于以下问题:Python QLocalSocket.errorString方法的具体用法?Python QLocalSocket.errorString怎么用?Python QLocalSocket.errorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket.errorString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _has_legacy_server
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import errorString [as 别名]
def _has_legacy_server(name):
"""Check if there is a legacy server.
Args:
name: The name to try to connect to.
Return:
True if there is a server with the given name, False otherwise.
"""
socket = QLocalSocket()
log.ipc.debug("Trying to connect to {}".format(name))
socket.connectToServer(name)
err = socket.error()
if err != QLocalSocket.UnknownSocketError:
log.ipc.debug("Socket error: {} ({})".format(socket.errorString(), err))
os_x_fail = (
sys.platform == "darwin" and socket.errorString() == "QLocalSocket::connectToServer: " "Unknown error 38"
)
if err not in [QLocalSocket.ServerNotFoundError, QLocalSocket.ConnectionRefusedError] and not os_x_fail:
return True
socket.disconnectFromServer()
if socket.state() != QLocalSocket.UnconnectedState:
socket.waitForDisconnected(CONNECT_TIMEOUT)
return False
示例2: __init__
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import errorString [as 别名]
class Client:
def __init__(self):
self.socket = QLocalSocket()
self.socket.setServerName(piony.G_SOCKET_NAME)
self.socket.error.connect(self.displayError)
self.socket.disconnected.connect(self.socket.deleteLater)
def _log_(self, text, *args):
logger.info(self.__class__.__qualname__ + ': ' + text, *args)
def connect(self):
self.socket.abort()
self._log_("connection attempt")
self.socket.connectToServer()
def send(self, argv):
data = QByteArray()
out = QDataStream(data, QIODevice.WriteOnly)
out.setVersion(QDataStream.Qt_5_0)
out.writeQVariant(argv)
self._log_("writes: %s", str(data))
self.socket.write(data)
self.socket.flush()
self.socket.disconnectFromServer()
def displayError(self, err):
msg = {
QLocalSocket.ServerNotFoundError:
"The host was not found. Check the host name and port.",
QLocalSocket.ConnectionRefusedError:
"The connection was refused by the peer. "
"Check server is running, it's host and port.",
QLocalSocket.PeerClosedError:
"Peer was closed", # None,
}.get(err, "Client error: {}.".format(self.socket.errorString()))
self._log_(msg)
示例3: SingleApplicationClient
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import errorString [as 别名]
class SingleApplicationClient(object):
"""
Class implementing the single application client base class.
"""
def __init__(self, name):
"""
Constructor
@param name name of the local server to connect to (string)
"""
self.name = name
self.connected = False
def connect(self):
"""
Public method to connect the single application client to its server.
@return value indicating success or an error number. Value is one of:
<table>
<tr><td>0</td><td>No application is running</td></tr>
<tr><td>1</td><td>Application is already running</td></tr>
</table>
"""
self.sock = QLocalSocket()
self.sock.connectToServer(self.name)
if self.sock.waitForConnected(10000):
self.connected = True
return 1
else:
err = self.sock.error()
if err == QLocalSocket.ServerNotFoundError:
return 0
else:
return -err
def disconnect(self):
"""
Public method to disconnect from the Single Appliocation server.
"""
self.sock.disconnectFromServer()
self.connected = False
def processArgs(self, args):
"""
Public method to process the command line args passed to the UI.
<b>Note</b>: This method must be overridden by subclasses.
@param args command line args (list of strings)
@exception RuntimeError raised to indicate that this method must be
implemented by a subclass
"""
raise RuntimeError("'processArgs' must be overridden")
def sendCommand(self, cmd):
"""
Public method to send the command to the application server.
@param cmd command to be sent (string)
"""
if self.connected:
self.sock.write(cmd)
self.sock.flush()
def errstr(self):
"""
Public method to return a meaningful error string for the last error.
@return error string for the last error (string)
"""
return self.sock.errorString()
示例4: MainForm
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import errorString [as 别名]
#.........这里部分代码省略.........
def itemClicked(self):
sender = self.sender()
if sender.item.folder:
self.setCurrentItem(sender.item)
self.refresh(False)
else:
flags = ['f', 'F', 'u', 'U', 'd', 'D', 'n', 'N', 'i', 'k', 'v', 'm']
command = sender.item.command
for i in flags:
command = command.replace('%' + i, '')
# %c needs a proper value in some cases
command = command.replace('%c', '"%s"' % sender.item.name)
working = sender.item.working
if not os.path.isdir(working):
working = None
# Need to redirect stdout and stderr so if the process writes something it won't fail
with open(os.path.devnull, 'w') as devnull:
Popen(command + '&', stdout=devnull, stderr=devnull, shell=True, cwd=working)
self.hideOrClose()
def backClicked(self):
if self.currentItem:
self.setCurrentItem(self.currentItem.parent)
self.refresh(False)
def setCurrentItem(self, item):
self.currentItem = item
if item != None:
self.currentLabel.setText(item.name)
if item.parent != None:
self.backButton.setText(item.parent.name)
else:
self.backButton.setText('Favorites')
else:
self.currentLabel.setText('')
self.backButton.setText('Favorites')
def settingsClicked(self):
form = SettingsForm(self)
form.quitCheck.setChecked(self.settings['quit'])
theme = self.settings.get('iconTheme')
if theme:
form.themeCombo.setCurrentIndex(form.themeCombo.findText(theme))
self.holdOpen = True
form.exec_()
self.checkMouse()
self.holdOpen = False
if form.accepted:
self.settings['quit'] = form.quitCheck.isChecked()
def firstRun(self):
QMessageBox.information(self, 'First Time?', 'Your menu is currently empty. It is recommended that you import an existing menu file.')
self.settingsClicked()
def connectToRunning(self):
self.socket = QLocalSocket()
self.socket.connectToServer('nemuSocket')
self.socket.waitForConnected(1000)
if self.socket.state() == QLocalSocket.ConnectedState:
print 'Server found'
if self.socket.waitForReadyRead(3000):
line = self.socket.readLine()
print line
else:
print self.socket.errorString()
sys.exit()
else:
print 'No server running'
def handleConnection(self):
import datetime
print "Got connection", datetime.datetime.now()
connection = self.server.nextPendingConnection()
connection.write('connected')
del connection
self.setCurrentItem(None)
self.filterBox.setText('')
self.refresh(False)
self.show()
print "Showed", datetime.datetime.now()
return
# Call periodically to keep data resident in memory (hopefully)
def keepalive(self):
if self.isHidden():
self.refresh(False)
示例5: Client
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import errorString [as 别名]
class Client(QDialog):
def __init__(self, parent=None):
super(Client, self).__init__(parent)
self.blockSize = 0
self.currentFortune = None
hostLabel = QLabel("&Server name:")
self.hostLineEdit = QLineEdit("fortune")
hostLabel.setBuddy(self.hostLineEdit)
self.statusLabel = QLabel("This examples requires that you run the Fortune Server " "example as well.")
self.statusLabel.setWordWrap(True)
self.getFortuneButton = QPushButton("Get Fortune")
self.getFortuneButton.setDefault(True)
quitButton = QPushButton("Quit")
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.getFortuneButton, QDialogButtonBox.ActionRole)
buttonBox.addButton(quitButton, QDialogButtonBox.RejectRole)
self.socket = QLocalSocket()
self.hostLineEdit.textChanged.connect(self.enableGetFortuneButton)
self.getFortuneButton.clicked.connect(self.requestNewFortune)
quitButton.clicked.connect(self.close)
self.socket.readyRead.connect(self.readFortune)
self.socket.error.connect(self.displayError)
mainLayout = QGridLayout()
mainLayout.addWidget(hostLabel, 0, 0)
mainLayout.addWidget(self.hostLineEdit, 0, 1)
mainLayout.addWidget(self.statusLabel, 2, 0, 1, 2)
mainLayout.addWidget(buttonBox, 3, 0, 1, 2)
self.setLayout(mainLayout)
self.setWindowTitle("Fortune Client")
self.hostLineEdit.setFocus()
def requestNewFortune(self):
self.getFortuneButton.setEnabled(False)
self.blockSize = 0
self.socket.abort()
self.socket.connectToServer(self.hostLineEdit.text())
def readFortune(self):
ins = QDataStream(self.socket)
ins.setVersion(QDataStream.Qt_4_0)
if self.blockSize == 0:
if self.socket.bytesAvailable() < 2:
return
self.blockSize = ins.readUInt16()
if ins.atEnd():
return
nextFortune = ins.readQString()
if nextFortune == self.currentFortune:
QTimer.singleShot(0, self.requestNewFortune)
return
self.currentFortune = nextFortune
self.statusLabel.setText(self.currentFortune)
self.getFortuneButton.setEnabled(True)
def displayError(self, socketError):
errors = {
QLocalSocket.ServerNotFoundError: "The host was not found. Please check the host name and port "
"settings.",
QLocalSocket.ConnectionRefusedError: "The connection was refused by the peer. Make sure the "
"fortune server is running, and check that the host name and "
"port settings are correct.",
QLocalSocket.PeerClosedError: None,
}
msg = errors.get(socketError, "The following error occurred: %s." % self.socket.errorString())
if msg is not None:
QMessageBox.information(self, "Fortune Client", msg)
self.getFortuneButton.setEnabled(True)
def enableGetFortuneButton(self):
self.getFortuneButton.setEnabled(self.hostLineEdit.text() != "")