chatServer/dumbconsole.py

73 lines
2.0 KiB
Python
Raw Permalink Normal View History

2021-10-28 06:08:33 +00:00
import qtpy
#import qtpy.QtGui as QtGui
from qtpy.QtGui import *
from qtpy.QtWidgets import *
from qtpy.QtCore import *
#from qtpy.QtMultimedia import QSound
import sys
import queue
inputQueue = queue.Queue()
class consoleWindow(QMainWindow):
def __init__(self,outputFunc,*args,**kwargs):
super().__init__(*args,**kwargs)
self.cOutputFunc = outputFunc
self.cWidth = 640
self.cHeight = 480
self.cCommandEditHeight = 22
self.resize(self.cWidth,self.cHeight)
self.cCreateElements()
self.cTaskTimer = QTimer()
self.cTaskTimer.setInterval(100)
self.cTaskTimer.timeout.connect(self.cRunTasks)
self.cTaskTimer.start()
def cCreateElements(self):
self.cTextBox = QTextBrowser(self)
self.cCommandEdit = QLineEdit("",self)
self.cCommandEdit.returnPressed.connect(self.cSend)
self.cButtonSend = QPushButton("Go",self)
self.cButtonSend.clicked.connect(self.cSend)
self.cResizeElements()
self.show()
self.cCommandEdit.setFocus()
def cResizeElements(self):
self.cTextBox.move(0,0)
self.cTextBox.resize(self.cWidth,self.cHeight - self.cCommandEditHeight)
self.cCommandEdit.move(0,self.cHeight - self.cCommandEditHeight)
self.cCommandEdit.resize(self.cWidth - 50,self.cCommandEditHeight)
self.cButtonSend.move(self.cWidth - 50,self.cHeight - self.cCommandEditHeight)
self.cButtonSend.resize(50,self.cCommandEditHeight)
def resizeEvent(self,event):
self.cWidth = self.width()
self.cHeight = self.height()
self.cResizeElements()
def cSend(self):
text = self.cCommandEdit.text()
self.cCommandEdit.clear()
self.cOutput(">" +text)
self.cOutputFunc(text)
def cOutput(self,text):
self.cTextBox.append(text)
def cRunTasks(self):
try:
while True:
text = inputQueue.get(False)
self.cOutput(text)
except queue.Empty:
return
def init(outputFunc):
global app
global window
app = QApplication(sys.argv)
window = consoleWindow(outputFunc)
app.exec_()