示例#1
0
 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.ICChatInput.emit(
         self.newmes,
         UNICODE_STRING(
             self.characters[self.characterSelector.currentIndex()].name),
         UNICODE_STRING(self.characters[
             self.characterSelector.currentIndex()].portrait))
示例#2
0
    def mimeData(self, indices):
        path = makePortableFilename(
            ospath.join(
                POG_DIR,
                UNICODE_STRING(
                    self.filePath(indices[0])[len(self.absRoot) + 1:])))

        if not ospath.isfile(path): return None

        mime = QMimeData()
        mime.setText(UNICODE_STRING(path))
        return mime
示例#3
0
 def setCharacterPreview(self, newIndex=-1):
     try:
         preview = QPixmap(
             ospath.join(
                 UNICODE_STRING(PORTRAIT_DIR),
                 UNICODE_STRING(self.characters[
                     self.characterSelector.currentIndex()].portrait)))
         if preview.isNull(
         ):  #Sadly, we have to check ahead, because Qt is dumb and prints an error about the scaling instead of raising one we can catch.
             raise TypeError
         preview = preview.scaled(min(preview.width(), 64),
                                  min(preview.height(), 64))
         self.characterPreview.setPixmap(preview)
     except:
         self.characterPreview.clear()
示例#4
0
def chat(st, chname, portrait):
    """Parses and executes chat commands."""
    st = UNICODE_STRING(st)

    if (len(st) <= 0):
        return
    if ('<' in st
            and '>' not in st) or ('<' in st and '>' in st
                                   and '<' in str(st)[str(st).rfind('>'):]):
        ICSay(
            translate(
                'chat',
                "Please type &#38;#60; if you wish to include &#60; in your message."
            ))
        return

    if st[0] != '/' or len(st) > 1 and st[1] == '/':
        if len(st) > 1 and st[1] == '/':
            st = st[1:]
        command = 'say'
        message = st.strip()
    else:
        command, message = splitword(st[1:])
        command = str(command).lower()
    #print command, message

    if command in chatCommands:
        chatCommands[command](message, chname, portrait)
    else:
        if command not in ('help', '?'):
            ICSay(
                translate('chatdoc', "Invalid command.",
                          'Unknown chat command name.'))
        elif message in chatCommands:
            ICSay(translate('chatdoc', chatCommands[message].documentation))
            return
        ICSay(
            translate(
                'chatdoc', "Command Help:<br>"
                "Typing ordinary text and pressing 'enter' "
                "will display to all players. Other commands may be invoked "
                "with '/' plus the name of the command plus any arguments."
                "<dl><dt>Commands</dt><dd>{commandList}</dd></dl><br>").format(
                    commandList=translate(
                        'chatdoc', '</dd><dd>',
                        'Goes inbetween the commands in the commandList.').
                    join(chatCommandNames)))
示例#5
0
 def userIP(self, username):
     """Gets the IP of an existing client."""
     if not self.userExists(username):
         raise RuntimeError("Invalid username {0}".format(username))
     if self.clients[self._processUsername(username)] == self.client:
         return "127.0.0.1"
     return UNICODE_STRING(self.clients[self._processUsername(
         username)].obj.socket.peerAddress())
示例#6
0
    def dump(self):
        """Serialize to an object valid for JSON dumping."""

        macroz = []
        for i in range(0, self.diceArea.count()):
            macroz.append(UNICODE_STRING(self.diceArea.item(i).text()))

        return dict(macros=dict([(i, macro)
                                 for i, macro in enumerate(macroz)]))
示例#7
0
    def updateReceive(self):
        """Parses incoming data into messages or objects."""

        while True:
            if self.receivedfile is not None:
                length = min(
                    CHUNK_SIZE,
                    self.receivedfile.size - self.receivedfile.processed)
                if self.socket.bytesAvailable() < length:
                    return
                data = self._rawread(length)
                if data is None:
                    return
                if not self.receivedfile.write(self.context, data):
                    self._closeWithPrejudice()
                    return
                self.filePartlyReceived.emit(
                    self.receivedfile.filename,
                    UNICODE_STRING(self.receivedfile.size),
                    UNICODE_STRING(self.receivedfile.processed))
                if self.receivedfile.size == self.receivedfile.processed:
                    receivedfile = self.receivedfile
                    self.receivedfile = None
                    receivedfile.file.close()
                    self.fileReceived.emit(self, receivedfile.filename)
                    # May be more available
                    continue
            else:
                if not self.socket.canReadLine():
                    return
                serial = self._rawreadline()
                if serial is None:
                    return
                # Allow empty lines
                if EMPTY_REGEX.match(UNICODE_STRING(serial)):
                    continue
                try:
                    obj = jsonloads(UNICODE_STRING(serial))
                except:
                    self._respondToSocketError("JSON Error", -1, text=serial)
                    return
                self.receiveObject(obj)
示例#8
0
    def updateSend(self):
        """Continues sending the current send file."""
        if not self.sentfile:
            return

        while self.socket.bytesToWrite() < CHUNK_SIZE:
            data = self.sentfile.read(self.context)
            if data is None:
                self._closeWithPrejudice()
                return
            if not self._rawsend(data):
                return
            self.filePartlySent.emit(self.sentfile.filename,
                                     UNICODE_STRING(self.sentfile.size),
                                     UNICODE_STRING(self.sentfile.processed))
            if self.sentfile.file.atEnd():
                sentfile = self.sentfile
                self.sentfile = None
                sentfile.file.close()
                self.fileSent.emit(self, sentfile.filename)
                return
示例#9
0
    def __init__(self):
        """Initializes the client."""
        # Sockets/server
        self.obj = None
        self.xfer = None
        self.server = None
        self.hostname = None
        self.port = None
        self.password = None

        # File transfer lists
        self.sendList = set()
        self.getList = set()
        self.sentfile = None
        self.receivedfile = None
        # Doesn't need translation
        self.username = UNICODE_STRING(localUser()) or 'localhost'
        assert (self.username)

        self.timer = QTimer()
        self.timer.timeout.connect(self._updatetransfer)
        self.timer.start(1000)
示例#10
0
 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)
示例#11
0
 def _processUsername(self, username):
     """Processes a username to lowercase."""
     return UNICODE_STRING(username).lower()
示例#12
0
 def rollDice(self):
     current = self.diceArea.item(self.currentMacro)
     if current is not None:
         text = UNICODE_STRING(current.text())
         self.rollRequested.emit(text[text.rfind(':') + 1:])
示例#13
0
 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)
示例#14
0
 def __str__(self):
     text = "Image(", self.imagepath, self.drawRect, self.textureRect, self.layer, self.offset, self.textureId, self._hidden, ")"
     return UNICODE_STRING(text)
示例#15
0
 def __init__(self):
     super(QFileSystemModel, self).__init__()
     self.setRootPath(POG_DIR)
     self.setNameFilters(IMAGE_NAME_FILTER)
     self.setNameFilterDisables(False)
     self.absRoot = ospath.abspath(UNICODE_STRING(POG_DIR))
示例#16
0
 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))
示例#17
0
def localHost():
    """Gets the name of the local machine."""
    return UNICODE_STRING(QHostInfo.localHostName())
示例#18
0
	def _getWidgetValue(self, widget):
		return UNICODE_STRING(widget.currentText())
示例#19
0
def localUser():
    """Gets the name of the local user."""
    return UNICODE_STRING(getuser())