当前位置: 首页>>代码示例>>Python>>正文


Python Server.console方法代码示例

本文整理汇总了Python中Server.Server.console方法的典型用法代码示例。如果您正苦于以下问题:Python Server.console方法的具体用法?Python Server.console怎么用?Python Server.console使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Server的用法示例。


在下文中一共展示了Server.console方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MyServer

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import console [as 别名]
class MyServer(QtGui.QMainWindow):
  
  def __init__(self, parent=None):
  
    #Instance variables
    self.chatLines = []
    self.consoleLines = []
    self.lastServerLine = ''
    
    #Initialize a QTimer to run background updates (online players, status, new chat messages, etc)
    self.repeatingTimer = QtCore.QTimer()
    self.singleTimer = QtCore.QTimer()
    
    self.s=Server()
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    self.initUI()
    
    self.startRepeatingTimer()
    self.sendMessageClicked()
    self.consoleClicked()
    self.onlineClicked()
    

    
    
  def initUI(self):
    self.connect(self.ui.pushButtonStart, QtCore.SIGNAL('clicked()'), self.startClicked)
    self.connect(self.ui.pushButtonStop, QtCore.SIGNAL('clicked()'), self.stopClicked)
    self.connect(self.ui.pushButtonStopStart, QtCore.SIGNAL('clicked()'), self.stopStartClicked)
    
    
    self.connect(self.ui.pushButtonStatus, QtCore.SIGNAL('clicked()'), self.statusClicked)
    self.connect(self.ui.pushButtonOnline, QtCore.SIGNAL('clicked()'), self.onlineClicked)
    
    self.connect(self.ui.pushButtonSendMessage, QtCore.SIGNAL('clicked()'), self.sendMessageClicked)
    self.connect(self.ui.lineEditMessage, QtCore.SIGNAL('returnPressed()'), self.sendMessageClicked)
    
    self.connect(self.ui.pushButtonConsole, QtCore.SIGNAL('clicked()'), self.consoleClicked)
    self.connect(self.ui.lineEditConsole, QtCore.SIGNAL('returnPressed()'), self.consoleClicked)
    
    #Connect the timer button
    self.connect(self.ui.pushButtonStartTimer, QtCore.SIGNAL('clicked()'), self.startRepeatingTimer)
    #Connect the timer
    self.connect(self.repeatingTimer, QtCore.SIGNAL('timeout()'), self.ticToc)
    
  def startClicked(self):
    self.s.start()
    self.checkStatus()
    
  def stopClicked(self):
    self.s.stop()
    self.checkStatus()
    
  def statusClicked(self):
    self.checkStatus()
    
  def onlineClicked(self):
    self.players = self.s.players()
    playersFormatted = ''
    if self.players == ['']:
      playersFormatted = 'No one online. Click to refresh'
    elif len(self.players) is 1 and self.players[0] != '':
      playersFormatted = self.players[0]
    else:
      for player in self.players:
        playersFormatted = playersFormatted + ' ' + player
    self.ui.labelOnline.setText(playersFormatted)
    
  def sendMessageClicked(self):

    message = self.ui.lineEditMessage.text()
    self.ui.lineEditMessage.clear()   
    if message != '':
      self.s.message(message)

    if len(self.chatLines) is 0:
      self.chatLines = self.s.chat(60)
      newChatLines = self.chatLines
    else:
      newChatLine = 'poop'
      searchBack = 0
      while newChatLine not in self.chatLines[-2:]:
        searchBack = searchBack + 1
        newChatLine = self.s.chat(searchBack, oneLine=True)
      newChatLines = self.s.chat(searchBack)
      newChatLines.pop(0)
      
    if len(newChatLines) > 0:
      for line in newChatLines:
        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)
      self.ui.treeWidgetChat.scrollToItem(a)
    self.chatLines.extend(newChatLines)

      
#.........这里部分代码省略.........
开发者ID:doctoboggan,项目名称:blankkit,代码行数:103,代码来源:main.py


注:本文中的Server.Server.console方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。