示例#1
0
class pogPalette(QDockWidget):
    """The list of loaded pogs."""
    def __init__(self, mainWindow):
        """Initializes the pog palette."""
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.
            tr("Drag a file from this widget into the game window to place a pog."
               ))
        self.setWindowTitle(self.tr("Pog Palette"))
        self.widget = QWidget(mainWindow)
        self.mainLayout = QBoxLayout(2)
        self.pogsModel = PogFileSystemModel()
        self.ROOT_LEN = len(self.pogsModel.absRoot) + 1
        self.pogArea = pogTree(mainWindow)
        self.pogArea.setModel(self.pogsModel)
        self.pogArea.setRootIndex(self.pogsModel.index(POG_DIR))
        self.pogArea.setColumnHidden(1, True)
        self.pogArea.setColumnHidden(2, True)
        self.pogArea.setColumnHidden(3, True)
        self.pogArea.setDragDropMode(QAbstractItemView.DragDrop)
        self.mainLayout.addWidget(self.pogArea)
        self.widget.setLayout(self.mainLayout)
        self.setWidget(self.widget)
        self.setObjectName("Pog Palette")
        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)
示例#2
0
class transferMonitorWidget(QDockWidget):
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("Allows for monitoring and control of file transfers."))
        self.setWindowTitle(self.tr("Transfer Monitor"))
        self.transferDict = {}
        self.transferTable = QTableWidget(0, 3, mainWindow)
        self.transferTable.setHorizontalHeaderLabels(
            ["Client", "Filename", "Status"])
        self.widget = QWidget(mainWindow)
        self.status = QLabel("Initializing", mainWindow)
        self.layout = QBoxLayout(2)
        self.layout.addWidget(self.transferTable)
        self.layout.addWidget(self.status)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Transfer Monitor")

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.hide()

    def updateItem(self, client, filename, status):
        '''Update the status of a transfer, creating a new table row for it if it's new.'''
        if client.username + filename not in list(self.transferDict.keys()):
            self.transferDict[client.username +
                              filename] = self.transferTable.rowCount()
            self.transferTable.setRowCount(self.transferTable.rowCount() + 1)
            for column in (0, 1, 2):
                self.transferTable.setItem(self.transferTable.rowCount() - 1,
                                           column, QTableWidgetItem(""))
                self.transferTable.item(self.transferTable.rowCount() - 1,
                                        column).setFlags(Qt.NoItemFlags)
        self.transferTable.item(self.transferDict[client.username + filename],
                                0).setText(client.username)
        self.transferTable.item(self.transferDict[client.username + filename],
                                1).setText(filename)
        self.transferTable.item(self.transferDict[client.username + filename],
                                2).setText(status)
        self.transferTable.update()
        self.update()

    def processFileEvent(self, client, filename, event):
        '''Process a raw file/general status event.'''
        if len(filename) > 1:
            self.updateItem(client, filename, event)
        else:
            self.status.setText(event)
            self.update()

    def processPartialTransferEvent(self, client, filename, size, processed):
        '''Process a partial transfer event.'''
        processedAmount = "".join(
            (UNICODE_STRING(round(float(processed) / float(size) * 100,
                                  1)), "%"))
        self.updateItem(client, filename, processedAmount)
示例#3
0
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)

        #self.__eat = True
        self.painting = True
        self.dragging = False
        self.rectStart = None

        self.setWindowTitle(self.tr("Map Editor"))
        self.widget = QWidget(mainWindow)
        self.layout = QGridLayout()
        self.currentTileLayout = QBoxLayout(1)
        self.scrollarea = QScrollArea(mainWindow)
        self.noPaintingButton = QRadioButton(self.tr("Stop Painting"),
                                             mainWindow)
        self.singlePaintingButton = QRadioButton(self.tr("Single Tile Brush"),
                                                 mainWindow)
        self.noPaintingButton.setChecked(True)
        self.rectPaintingButton = QRadioButton(
            self.tr("Area (Rectangle) Brush"), mainWindow)
        self.hollowRectPaintingButton = QRadioButton(
            self.tr("Hollow Rectangle Brush"), mainWindow)
        self.currentTileLabel = QLabel()
        self.currentTileLabelLabel = QLabel(self.tr("Current tile: "))
        self.undoButton = QPushButton("Undo", mainWindow)
        self.redoButton = QPushButton("Redo", mainWindow)
        #self.moveMapButton = QPushButton("Move Map", mainWindow)
        self.layout.addWidget(self.scrollarea, 0, 0, 1, 2)
        self.layout.addWidget(self.noPaintingButton, 1, 0)
        self.layout.addWidget(self.singlePaintingButton, 2, 0)
        self.layout.addWidget(self.rectPaintingButton, 3, 0)
        self.layout.addWidget(self.hollowRectPaintingButton, 4, 0)
        self.layout.addWidget(self.undoButton, 1, 1)
        self.layout.addWidget(self.redoButton, 2, 1)
        #self.layout.addWidget(self.moveMapButton, 3, 1)
        self.layout.addWidget(self.currentTileLabel, 5, 1)
        self.layout.addWidget(self.currentTileLabelLabel, 5, 0)
        self.tilelabel = None
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Map Editor")
        mainWindow.addDockWidget(Qt.RightDockWidgetArea, self)

        self.currentMap = None
        self.copyData = None

        self.undo = []
        self.undoButton.clicked.connect(self._undo)
        self.undoButton.setEnabled(False)

        self.redo = []
        self.redoButton.clicked.connect(self._redo)
        self.redoButton.setEnabled(False)

        addMapChangedListener(self.mapChangedResponse, NORMAL_RESPONSE_LEVEL)
        addMousePressListener(self.mousePressResponse, NORMAL_RESPONSE_LEVEL)
        addMouseMoveListener(self.mouseMoveResponse, NORMAL_RESPONSE_LEVEL)
        addMouseReleaseListener(self.mouseReleaseResponse,
                                NORMAL_RESPONSE_LEVEL)
示例#4
0
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("A widget for out-of-character chat and system messages."))
        self.setWindowTitle(self.tr("OOC Chat / System"))
        self.widgetEditor = QTextBrowser(mainWindow)
        self.widgetLineInput = chatLineEdit(mainWindow)
        self.widgetLineInput.setToolTip(
            self.tr(
                "Type text here and press Enter or Return to transmit it."))
        self.widget = QWidget(mainWindow)
        self.widgetEditor.setReadOnly(True)
        self.widgetEditor.setOpenLinks(False)
        self.layout = QBoxLayout(2)
        self.layout.addWidget(self.widgetEditor)
        self.layout.addWidget(self.widgetLineInput)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Chat Widget")
        self.timestamp = False
        self.timestampformat = "[%H:%M:%S]"
        self.messageCache = []

        try:
            js = jsonload(ospath.join(SAVE_DIR, "ui_settings.rgs"))
        except:
            pass
        try:
            self.toggleTimestamp(
                loadString('chatWidget.timestamp', js.get('timestamp')))
        except:
            pass
        try:
            self.timestampformat = loadString('chatWidget.timestampformat',
                                              js.get('timestampformat'))
        except:
            pass

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.widgetEditor.anchorClicked.connect(self.anchorClicked)
        self.widgetLineInput.returnPressed.connect(self.processInput)
示例#5
0
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("Allows for monitoring and control of file transfers."))
        self.setWindowTitle(self.tr("Transfer Monitor"))
        self.transferDict = {}
        self.transferTable = QTableWidget(0, 3, mainWindow)
        self.transferTable.setHorizontalHeaderLabels(
            ["Client", "Filename", "Status"])
        self.widget = QWidget(mainWindow)
        self.status = QLabel("Initializing", mainWindow)
        self.layout = QBoxLayout(2)
        self.layout.addWidget(self.transferTable)
        self.layout.addWidget(self.status)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Transfer Monitor")

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.hide()
示例#6
0
class chatWidget(QDockWidget):
    def __init__(self, mainWindow):
        super(QDockWidget, self).__init__(mainWindow)
        self.setToolTip(
            self.tr("A widget for out-of-character chat and system messages."))
        self.setWindowTitle(self.tr("OOC Chat / System"))
        self.widgetEditor = QTextBrowser(mainWindow)
        self.widgetLineInput = chatLineEdit(mainWindow)
        self.widgetLineInput.setToolTip(
            self.tr(
                "Type text here and press Enter or Return to transmit it."))
        self.widget = QWidget(mainWindow)
        self.widgetEditor.setReadOnly(True)
        self.widgetEditor.setOpenLinks(False)
        self.layout = QBoxLayout(2)
        self.layout.addWidget(self.widgetEditor)
        self.layout.addWidget(self.widgetLineInput)
        self.widget.setLayout(self.layout)
        self.setWidget(self.widget)
        self.setObjectName("Chat Widget")
        self.timestamp = False
        self.timestampformat = "[%H:%M:%S]"
        self.messageCache = []

        try:
            js = jsonload(ospath.join(SAVE_DIR, "ui_settings.rgs"))
        except:
            pass
        try:
            self.toggleTimestamp(
                loadString('chatWidget.timestamp', js.get('timestamp')))
        except:
            pass
        try:
            self.timestampformat = loadString('chatWidget.timestampformat',
                                              js.get('timestampformat'))
        except:
            pass

        mainWindow.addDockWidget(Qt.BottomDockWidgetArea, self)

        self.widgetEditor.anchorClicked.connect(self.anchorClicked)
        self.widgetLineInput.returnPressed.connect(self.processInput)

    def toggleDarkBackgroundSupport(self, dark):
        if dark:
            self.widgetEditor.document().setDefaultStyleSheet(
                "a {color: cyan; }")
        else:
            self.widgetEditor.document().setDefaultStyleSheet(
                "a {color: blue; }")
        self.refreshMessages()

    def refreshMessages(self):
        '''Clear the text display and re-add all messages with current style settings etc.'''
        self.widgetEditor.clear()
        for message in self.messageCache:
            self.widgetEditor.append(message)

    def anchorClicked(self, url):
        '''If the url appears to be one of the /tell links in a player name, load it to the input.'''
        if "/tell" in UNICODE_STRING(url):
            self.widgetLineInput.setText(url.toString())
        else:
            QDesktopServices.openUrl(QUrl(url))

    def toggleTimestamp(self, newsetting):
        if newsetting == "On":
            self.timestamp = True
        else:
            self.timestamp = False

    def insertMessage(self, mes):
        self.scroll = (self.widgetEditor.verticalScrollBar().value() ==
                       self.widgetEditor.verticalScrollBar().maximum())
        if self.timestamp:
            message = " ".join((strftime(self.timestampformat,
                                         localtime()), mes))
            self.messageCache.append(message)
            self.widgetEditor.append(message)
        else:
            self.messageCache.append(mes)
            self.widgetEditor.append(mes)
        if self.scroll:
            self.widgetEditor.verticalScrollBar().setValue(
                self.widgetEditor.verticalScrollBar().maximum())
        try:
            try:
                self.logfile = open(
                    ospath.join(LOG_DIR, strftime("%b_%d_%Y.log",
                                                  localtime())), 'a')
                self.logfile.write(mes + "\n")
            finally:
                self.logfile.close()
        except:
            pass

    def processTags(self, message):
        message = message.replace("<", "&lt;").replace(">", "&gt;")
        for validTag in ("i", "b", "u", "s"):
            message = message.replace("".join(("[", validTag, "]")), "".join(
                ("<", validTag, ">")))
            message = message.replace("".join(("[", "/", validTag, "]")),
                                      "".join(("<", "/", validTag, ">")))
        message = sub(r"\[url\](.*?)\[/url\]", r"<a href=\1>\1</a>", message)
        message = message.replace(
            "/>",
            ">")  #prevents anchor from closing with trailing slash in URL
        return message

    def processInput(self):
        self.newmes = UNICODE_STRING(self.widgetLineInput.text())
        self.newmes = self.processTags(self.newmes)
        self.widgetLineInput.clear()
        self.widgetLineInput.addMessage(self.newmes)
        self.chatInput.emit(self.newmes)

    chatInput = signal(BASE_STRING,
                       doc="""Called when chat input is received.

		text -- the message entered

		""")