Exemplo n.º 1
0
import sys

from fbs_runtime.application_context import ApplicationContext
from PyQt5 import QtWidgets, QtGui

from app import App

if __name__ == '__main__':
    appctxt = ApplicationContext()  # 1. Instantiate ApplicationContext
    app = QtWidgets.QApplication(sys.argv)
    # load from fbs resources
    splash_image = appctxt.get_resource('signalum.png')
    pixmap = QtGui.QPixmap(splash_image)
    splash = QtWidgets.QSplashScreen(pixmap)
    splash.show()
    app.setOrganizationName("BisonCorps")
    app.setApplicationName("Signalum")
    a = App()
    splash.showMessage("Loading application")
    a.setWindowTitle("Signalum Desktop - (BisonCorps, 2019)")
    a.show()
    splash.showMessage("Finished loading application")
    splash.finish(a)
    # app.exec_()
    exit_code = appctxt.app.exec_()  # 2. Invoke appctxt.app.exec_()
    sys.exit(exit_code)
Exemplo n.º 2
0
#!/usr/bin/env python3

# TODO: support for derivative words

from fbs_runtime.application_context import ApplicationContext
import json

# TODO: solve absolute path issue in the scr/.../rdict.py file
appctxt = ApplicationContext()
datafile = appctxt.get_resource('rdict.json')
jdict = None

# reads json file 'datafile' into 'jdict' list
def parse():
    global jdict
    df = open(datafile)
    raw = df.read()
    df.close()
    jdict = json.loads(raw)

# recursively adds lines of formatted 'val' to 'outlist'
def _fstr(val, outlist, offstr = '', tabstr = ' ' * 4):
    if type(val) == dict:
        for k, v in val.items():
            outlist.append('{}{}:'.format(offstr, '<b>' + k + '</b>'))
            _fstr(v, outlist, offstr + tabstr, tabstr)
    elif type(val) == list:
        if len(val) == 1:
            _fstr(val[0], outlist, offstr, tabstr)
        elif type(val[0]) == str:
            outlist.append(offstr + ', '.join(val))
Exemplo n.º 3
0
class MainApp(QMainWindow, design.Ui_MainWindow):
    resized = QtCore.pyqtSignal()

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.auto_add = True
        self.resized.connect(self.on_mwresize)
        self.show()
        self.appctxt = ApplicationContext()
        self.setListener()
        self.attempt = [1, False]
        try:
            a = parser.RandomRightWord()
            self.word = a.get_word()
        except requests.exceptions.ConnectionError:
            try:
                a = parser.RandomWord()
                self.word = a.get_word()
            except requests.exceptions.ConnectionError:
                with open(self.appctxt.get_resource('dictionary.txt'),
                          'r') as f:
                    f = f.read().split('\n')
                    for x in range(len(f) - 1, -1, -1):
                        if f[x] == '':
                            del f[x]
                    random.shuffle(f)
                    word = f[0].split('||')
                    self.word = {'word': word[0], 'description': word[1]}
            except FileNotFoundError:
                QMessageBox.warning(
                    self, "Error",
                    "Connect to internet or make dictionary in the program's resource folder"
                )
                return
        if self.auto_add:
            with open("dictionary.txt", 'a') as f:
                f.write(word['word'] + "||" + word['description'])
        self.answered = ['_' for x in self.word['word']]
        self.logic()
        self.prev = []

    def stickman_update(self):
        self.label_4.setPixmap(
            QPixmap(
                self.appctxt.get_resource(
                    f'Man {str(self.attempt[0])}|{str(int(self.attempt[1]))}.svg'
                )))

    def logic(self, letter=None):
        if type(letter) != str:
            pass
        else:
            letter = letter.lower()
            right = False
            for x in range(0, len(self.word['word'])):
                if letter == self.word['word'][x]:
                    self.answered[x] = letter
                    right = True
            if letter.upper() in self.all_letters:
                if not right and not letter in self.prev:
                    self.attempt[0] += 1
                self.prev.append(letter)

        self.label_3.setText('Attempt left ' + str(7 - self.attempt[0]))
        self.label.setText(f'Description: {self.word["description"]}')
        self.label_2.setText(f"Word: {' '.join(self.answered)}")
        self.stickman_update()
        if 7 - self.attempt[0] <= 0:
            self.gameover()
        elif self.word['word'] == ''.join(self.answered):
            self.win()

    def gameover(self):
        QMessageBox.information(
            self, "Game Over",
            f"Right word is {self.word['word']}\nYou loose this game")
        self.close()

    def win(self):
        QMessageBox.information(
            self, "Win",
            f"Right word is {self.word['word']}\nСongratulations, you guessed this word)"
        )
        self.close()

    def resizeEvent(self, event):
        self.resized.emit()
        return super(MainApp, self).resizeEvent(event)

    def on_mwresize(self):
        if self.geometry().height() < 642:
            self.verticalFrame_2.setHidden(True)
        elif self.geometry().height() >= 642:
            self.verticalFrame_2.setHidden(False)

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_Escape:
            self.close()
        for x in range(0, len(self.all_letters)):
            if self.all_letters[x] == e.text().upper():
                eval(f'self.key_pressed(self.pushButton_{x+1})')

    def key_pressed(self, letter):
        if letter.text() != "":
            self.logic(letter.text())
            letter.setText("")

    def setListener(self):
        self.all_letters = []
        for x in range(1, 27):
            eval(
                f'self.pushButton_{x}.clicked.connect(partial(self.key_pressed,self.pushButton_{x}))'
            )
            eval(f"self.all_letters.append(self.pushButton_{x}.text())")
Exemplo n.º 4
0
#
# lower_window = QWidget()
#
# lower_layout = QVBoxLayout()
# lower_label = QLabel('Click to continue...')
# lower_label.setFont(QFont('Chalkboard', 20))
# lower_layout.addWidget(lower_label, alignment = Qt.AlignCenter)
#
# lower_layout.setAlignment(Qt.AlignBottom)
# lower_window.setLayout(lower_layout)
#
# cover_layout = QVBoxLayout()
# cover_layout.addWidget(upper_window)
# cover_layout.addWidget(lower_window)
cover_window = QWidget()
bg_img = QImage(appctxt.get_resource('bad_bg.jpeg'))
palette = QPalette()
palette.setBrush(10, QBrush(bg_img))
cover_window.setPalette(palette)
cover_window.setFixedSize(600, 600)
# cover_window.setLayout(cover_layout)
cover_window.show()

header_window = QWidget()

header_layout = QHBoxLayout()
header_left_label = QLabel()
header_left_img = QPixmap(appctxt.get_resource('f4t_logo.png')).scaledToHeight(
    64, Qt.SmoothTransformation)
header_left_label.setPixmap(header_left_img)
header_layout.addWidget(header_left_label)
Exemplo n.º 5
0
#!/usr/bin/env python3

from fbs_runtime.application_context import ApplicationContext

appctxt = ApplicationContext()
datafile = appctxt.get_resource('hdict.data')
tdict = {}


def parse():
    global tdict
    for line in open(datafile):
        l = line.split(':')
        tdict[l[0]] = l[1].strip()


def define(w):
    global jdict
    nf_msg = '<span style="color:red">Sorry! Word not found.</span>'
    if w in tdict:
        r = ''
        for i, s in enumerate(tdict[w].split(','), start=1):
            r += f'{i:>3}. {s}<br/>'
        return r
    else:
        return nf_msg


# cli dictionary when run directly
def main():
    parse()
Exemplo n.º 6
0
from fbs_runtime.application_context import ApplicationContext
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout

import requests
import sys

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        text = QLabel()
        text.setWordWrap(True)
        button = QPushButton('Next quote >')
        button.clicked.connect(lambda: text.setText(_get_quote()))
        layout = QVBoxLayout()
        layout.addWidget(text)
        layout.addWidget(button)
        layout.setAlignment(button, Qt.AlignHCenter)
        self.setLayout(layout)

def _get_quote():
    return requests.get('https://build-system.fman.io/quote').text

if __name__ == '__main__':
    appctxt = ApplicationContext()
    stylesheet = appctxt.get_resource('styles.qss')
    appctxt.app.setStyleSheet(open(stylesheet).read())
    window = MainWindow()
    window.show()
    exit_code = appctxt.app.exec_()
    sys.exit(exit_code)