本文整理汇总了Python中PyQt5.QtNetwork.QLocalSocket.readLine方法的典型用法代码示例。如果您正苦于以下问题:Python QLocalSocket.readLine方法的具体用法?Python QLocalSocket.readLine怎么用?Python QLocalSocket.readLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtNetwork.QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket.readLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __readCommands
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import readLine [as 别名]
def __readCommands(self, connection: QLocalSocket) -> None:
line = connection.readLine()
while len(line) != 0: # There is also a .canReadLine()
try:
payload = json.loads(str(line, encoding = "ascii").strip())
command = payload["command"]
# Command: Remove all models from the build plate.
if command == "clear-all":
self._application.callLater(lambda: self._application.deleteAll())
# Command: Load a model file
elif command == "open":
self._application.callLater(lambda f = payload["filePath"]: self._application._openFile(f))
# Command: Activate the window and bring it to the top.
elif command == "focus":
# Operating systems these days prevent windows from moving around by themselves.
# 'alert' or flashing the icon in the taskbar is the best thing we do now.
main_window = self._application.getMainWindow()
if main_window is not None:
self._application.callLater(lambda: main_window.alert(0)) # type: ignore # I don't know why MyPy complains here
# Command: Close the socket connection. We're done.
elif command == "close-connection":
connection.close()
else:
Logger.log("w", "Received an unrecognized command " + str(command))
except json.decoder.JSONDecodeError as ex:
Logger.log("w", "Unable to parse JSON command '%s': %s", line, repr(ex))
line = connection.readLine()
示例2: MainForm
# 需要导入模块: from PyQt5.QtNetwork import QLocalSocket [as 别名]
# 或者: from PyQt5.QtNetwork.QLocalSocket import readLine [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)