本文整理汇总了Python中Server.Server.command方法的典型用法代码示例。如果您正苦于以下问题:Python Server.command方法的具体用法?Python Server.command怎么用?Python Server.command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.command方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyServer
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import command [as 别名]
class MyServer(QtGui.QMainWindow):
def __init__(self, parent=None):
#Instance variables
self.chatLines = []
self.consoleLines = []
self.lastServerLine = 'first run'
self.onlineDict = {}
self.pluginsDict = {}
#Initialize a QTimer to run background updates (online players, status, new chat messages, etc)
self.repeatingTimer = QtCore.QTimer()
self.singleTimer = QtCore.QTimer() #Not used...
self.s=Server()
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.initUI()
self.startRepeatingTimer()
self.findPlugins() #Find the currently installed plugins by searching the plugin folder
#Set the start/stop button text
if self.s.status():
self.ui.pushButtonStopStart.setText('Stop Server')
else:
self.ui.pushButtonStopStart.setText('Start Server')
def initUI(self):
self.connect(self.ui.pushButtonStopStart, QtCore.SIGNAL('clicked()'), self.stopStartClicked)
self.connect(self.ui.lineEditMessage, QtCore.SIGNAL('returnPressed()'), self.sendChat)
self.connect(self.ui.lineEditConsole, QtCore.SIGNAL('returnPressed()'), self.sendConsole)
self.connect(self.ui.treeWidgetPluginList, QtCore.SIGNAL('itemSelectionChanged()'), self.pluginNameClicked)
#Connect the timer
self.connect(self.repeatingTimer, QtCore.SIGNAL('timeout()'), self.ticToc)
#####################
#GUI control methods
#####################
#Start or stop the server
def stopStartClicked(self):
if self.s.status():
self.s.stop()
self.updateStatusBar()
self.ui.pushButtonStopStart.setText('Start Server')
else:
self.s.start()
self.updateStatusBar()
self.ui.pushButtonStopStart.setText('Stop Server')
def sendChat(self):
message = str(self.ui.lineEditMessage.text())
self.ui.lineEditMessage.clear()
if message != '':
self.s.message(message)
self. updateChatDisplay([])
def updateChatDisplay(self, chatLines):
for line in chatLines:
fixedLine = line[5:19] + line[26:]
width = self.ui.treeWidgetChat.columnWidth(0)
fixedLine = utils.wordWrap(width-5, fixedLine)
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetChat)
a.setText(0, fixedLine)
if len(chatLines):
self.ui.treeWidgetChat.scrollToItem(a)
self.chatLines.extend(chatLines)
def sendConsole(self):
message = str(self.ui.lineEditConsole.text())
self.ui.lineEditConsole.clear()
if message != '':
self.s.command(message)
self. updateConsoleDisplay([])
def updateConsoleDisplay(self, consoleLines):
for line in consoleLines:
fixedLine = line[5:19] + line[26:]
width = self.ui.treeWidgetConsole.columnWidth(0)
fixedLine = utils.wordWrap(width-5, fixedLine)
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetConsole)
a.setText(0, fixedLine)
if len(consoleLines):
self.ui.treeWidgetConsole.scrollToItem(a)
self.consoleLines.extend(consoleLines)
def updatePlayersDisplay(self):
self.ui.treeWidgetPlayersList.clear()
for name in self.onlineDict:
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetPlayersList)
a.setText(0, name)
childrenList = []
for key in self.onlineDict[name]:
w = QtGui.QTreeWidgetItem(a)
w.setText(0, str(key) + ': ' + str(self.onlineDict[name][key]))
a.insertChild(0, w)
#.........这里部分代码省略.........
示例2: MyServer
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import command [as 别名]
#.........这里部分代码省略.........
self.stopStartThread.start()
def updateStatusBar(self):
if self.s.status():
line = 'SERVER IS ON - Players Online: ' + str(len(self.onlineDict))
else:
line = 'SERVER IS OFF'
self.ui.statusbar.showMessage(line)
def sendChat(self):
message = str(self.ui.lineEditMessage.text())
self.ui.lineEditMessage.clear()
if message != '':
self.s.message(message)
print message
self.updateChatDisplay([])
def updateChatDisplay(self, chatLines):
for line in chatLines:
fixedLine = line[5:19] + line[26:]
width = self.ui.treeWidgetChat.columnWidth(0)
fixedLine = utils.wordWrap(width-5, fixedLine)
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetChat)
a.setText(0, fixedLine)
if len(chatLines):
self.ui.treeWidgetChat.scrollToItem(a)
self.chatLines.extend(chatLines)
def sendConsole(self):
message = str(self.ui.lineEditConsole.text())
self.ui.lineEditConsole.clear()
if message != '':
print message
self.s.command(message)
self.updateConsoleDisplay([])
def updateConsoleDisplay(self, consoleLines):
for line in consoleLines:
fixedLine = line[5:19] + line[26:]
width = self.ui.treeWidgetConsole.columnWidth(0)
fixedLine = utils.wordWrap(width-5, fixedLine)
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetConsole)
a.setText(0, fixedLine)
if len(consoleLines):
self.ui.treeWidgetConsole.scrollToItem(a)
self.consoleLines.extend(consoleLines)
def updatePlayersDisplay(self):
self.ui.treeWidgetPlayersList.clear()
for name in self.onlineDict:
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetPlayersList)
a.setText(0, name)
childrenList = []
for key in self.onlineDict[name]:
w = QtGui.QTreeWidgetItem(a)
w.setText(0, str(key) + ': ' + str(self.onlineDict[name][key]))
a.insertChild(0, w)
def updatePluginsList(self):
for pluginName in self.pluginsDict.keys():
a = QtGui.QTreeWidgetItem(self.ui.treeWidgetPluginList)
a.setText(0, str(pluginName))
def pluginNameClicked(self):
pluginName = str(self.ui.treeWidgetPluginList.currentItem().text(0))
lines = '\n'.join(self.pluginsDict[pluginName])