Esempio n. 1
0
    def manda(self) -> None:
        """[Método] Manda a mensagem escrita na caixa de texto (entrada) pro servidor."""
        msg = self.getText()  # Pega o texto escrito

        # Se a mensagem for muito grande
        if len(msg) > 300:
            self.setTextStatusBar(
                "Essa mensagem muito longa.",
                "Red")  # Avisa o usuário pela barra de status
            return  # Sai da função

        # Se for um arquivo
        if ("file:///" in msg):
            try:
                # Criação do nome do arquivo
                tipoArquivo: str = splitext(msg)[1]  # Pega o tipo de arquivo
                horaMomento: str = str(datetime.now().strftime("%X")).replace(
                    ":", "-")  # Pega a hora que mandou a mensagem
                ip: str = self.ip.replace(".", "")
                novoNomeArquivo: str = f"{horaMomento}-{ip}{tipoArquivo}"  # Cria o nome do arquivo
                caminho: str = str(
                    msg[8:])  # Pega o caminho do arquivo inserido

                if (not isdir(self.pasta)):
                    mkdir(self.pasta)  # Cria a pasta do chat

                rec: str = f"{self.pasta}\\Chat-Recebidos\\"  # Caminho da pasta de recebidos
                if (not isdir(rec)):
                    mkdir(
                        rec
                    )  # Se a pasta onde recebe arquivos não existir cria ela

                env: str = f"{self.pasta}\\Chat-Enviados\\"  # Caminho da pasta de enviados
                if (not isdir(env)):
                    mkdir(
                        env
                    )  # Se a pasta que guarda os arquivos enviados não existir cria ela

                copyfile(caminho, osJoin(abspath(env), novoNomeArquivo)
                         )  # Copia o arquivo que quer enviar pra pasta
            except:
                self.enviaTxt(msg)
                return

            self.tEnviar = EnviaFileThread(
                novoNomeArquivo, self.ip, self.porta,
                self.pasta)  # Cria uma thread para mandar o arquivo
            self.tEnviar.start()  # Inicia essa thread
            self.clearAll()  # Limpa a caixa de texto (e barra de status)

            rec = env = tipoArquivo = horaMomento = ip = novoNomeArquivo = caminho = None  # Limpas as variáveis
            del tipoArquivo, horaMomento, ip, novoNomeArquivo, caminho, rec, env,  # Deleta as variáveis

        # Se for uma mensagem
        else:
            self.enviaTxt(msg)

        msg = None  # Limpas as variáveis
        del msg  # Deleta as variáveis
Esempio n. 2
0
def gameInit():

    version = '0.1e'
    versionString = 'circle test v' + version

    print ' ' + versionString

    display.reset(width, height)

    init()

    set_caption(versionString)

    menuSetup = ('&Resume', 'resume', 'K_ESCAPE'), \
              None, \
              ('&New game', 'new game'), \
              ('&Save', 'save'), \
              ('&Load', 'load'), \
              ('&Quit', 'quit')

    game.menu = menuGroup(menuSetup)
    game.menu.rect.centerx = width / 2
    game.menu.rect.centery = height / 2
    game.menu.subscript(versionString)

    # string offset [fontsize] [color]
    game.fbLabel = labelSprite('0, 0 add/remove', (10, 10))
    game.ui = Group(game.fbLabel)

    game.currCircle = None

    from os.path import isfile

    game.saveFile = osJoin(abspath(game.dir), 'test.save')

    game.saveRegister = []
    for name, obj in game.__dict__.iteritems():
        if hasattr(obj, 'save'):
            if callable(obj.save) and not isinstance(obj, type):
                game.saveRegister.append((name, obj))

    game.sm.autoSwitch = {
        'new game': 'add-remove',
        'save': 'resume',
        'load': 'resume'
    }

    if isfile(game.saveFile):
        game.sm.autoSwitch['init'] = 'load'
    else:
        game.sm.autoSwitch['init'] = 'new game'
    def __init__(self, credentials):
        super().__init__()
        # do the authentication outside
        assert credentials is not None and credentials.invalid is False, "Invalid or misssing credentials"

        cache = FileCache(osJoin(gettempdir(), ".httpcache"),
                          safe=_SafeCacheName)
        http = Http(cache, timeout=60)
        http = credentials.authorize(http)
        self.drive = build("drive", "v3", http=http)

        _meta = self._meta = {
            "case_insensitive":
            False,  # it will even let you have 2 identical filenames in the same directory!
            "invalid_path_chars": ":",  # not sure what else
            "max_path_length": None,  # don't know what the limit is
            "max_sys_path_length": None,  # there's no syspath
            "network": True,
            "read_only": False,
            "supports_rename": False  # since we don't have a syspath...
        }
Esempio n. 4
0
def gameInit():

    version = '0.8e'
    versionString = 'zoot v' + version

    print ' ' + versionString

    display.clearColor = (32, ) * 3
    display.reset(width, height)

    init()

    set_caption(versionString)

    menuSetup = ('&Resume', 'play', 'K_ESCAPE'), \
              None, \
              ('&New game', 'new game'), \
              ('&Save', 'save'), \
              ('&Load', 'load'), \
              ('&Quit', 'quit')

    game.menu = menuGroup(menuSetup)
    game.menu.rect.centerx = width / 2
    game.menu.rect.centery = height / 2
    game.menu.subscript(versionString)

    game.grid = gridGroup(gridWidth, (-4, gridHeight), blockBase)
    game.nextGrid = gridGroup(4, 4, blockBase,
                              game.grid.pxWide + 2 * blockBase,
                              game.grid.pxTall / 3 - 2 * blockBase)
    game.holdGrid = gridGroup(4, 4, blockBase,
                              game.grid.pxWide + 2 * blockBase,
                              game.grid.pxTall / 3 * 2)

    # string offset [fontsize] [color]
    levelLabel = labelSprite('level 1 - 0', ((size[0] - 80), size[1] - 20))
    nextLabel = labelSprite(
        'Next up:',
        (game.nextGrid.borderRect.left + 4, game.nextGrid.borderRect.top - 20))
    holdLabel = labelSprite(
        'Hold:',
        (game.holdGrid.borderRect.left + 4, game.holdGrid.borderRect.top - 20))
    game.ui = Group(levelLabel, nextLabel, holdLabel)

    game.msg.handler('levelLabel')(levelLabel.text)

    from os.path import isfile

    game.stdCursor = get_cursor()

    game.saveFile = osJoin(abspath(game.dir), 'zoot.save')

    game.saveRegister = []
    for name, obj in game.__dict__.iteritems():
        if hasattr(obj, 'save'):
            if callable(obj.save) and not isinstance(obj, type):
                game.saveRegister.append((name, obj))

    game.sm.autoSwitch = {'new game': 'play', 'load': 'play', 'save': 'play'}

    if isfile(game.saveFile):
        game.sm.autoSwitch['init'] = 'load'
    else:
        game.sm.autoSwitch['init'] = 'new game'
Esempio n. 5
0
# encoding: utf-8
#

from os.path import join as osJoin
from pygame.font import init, Font
import game

init()

uiLabelFontName = osJoin(game.res, 'freesansbold.ttf')
uiLabelSizeHint = 10

menuFontName = osJoin(game.res, 'freesans.ttf')
menuTitleFont = Font(menuFontName, 24)
menuSubFont = Font(menuFontName, 10)
menuDefaultFont = Font(menuFontName, 18)