Convert to tabs

This commit is contained in:
Vinyl Darkscratch 2018-03-06 23:49:05 -08:00
parent f17fd64eb7
commit b29385fd4d

View file

@ -15,73 +15,73 @@ try: base_path = sys._MEIPASS
except AttributeError: base_path = os.path.abspath('.') except AttributeError: base_path = os.path.abspath('.')
class WatchPipe(QThread): class WatchPipe(QThread):
change_image = pyqtSignal(str) change_image = pyqtSignal(str)
def run(self): def run(self):
while True: while True:
if os.path.exists(pipe_path): break if os.path.exists(pipe_path): break
else: time.sleep(0.1) else: time.sleep(0.1)
pipe = open(pipe_path, 'r') pipe = open(pipe_path, 'r')
pipe.flush() pipe.flush()
while True: while True:
message = os.read(pipe.fileno(), 256) message = os.read(pipe.fileno(), 256)
if len(message) > 0: if len(message) > 0:
self.change_image.emit(message.decode()) self.change_image.emit(message.decode())
time.sleep(0.05) time.sleep(0.05)
class Journal(QWidget): class Journal(QWidget):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.label = QLabel(self) self.label = QLabel(self)
self.change_image('default_en') self.change_image('default_en')
self.setWindowFlags(self.windowFlags()) self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_TranslucentBackground)
self.setAttribute(Qt.WA_NoSystemBackground) self.setAttribute(Qt.WA_NoSystemBackground)
self.setWindowTitle('') self.setWindowTitle('')
self.setMinimumSize(800, 600) self.setMinimumSize(800, 600)
self.setMaximumSize(800, 600) self.setMaximumSize(800, 600)
self.setGeometry(0, 0, 800, 600) self.setGeometry(0, 0, 800, 600)
self.show() self.show()
def change_image(self, image): def change_image(self, image):
name, lang = image.split('_', 1) name, lang = image.split('_', 1)
img = os.path.join(base_path, 'images', lang.upper(), '{}.png'.format(name)) img = os.path.join(base_path, 'images', lang.upper(), '{}.png'.format(name))
if not os.path.exists(img): if not os.path.exists(img):
img = os.path.join(base_path, 'images', '{}.png'.format(name)) img = os.path.join(base_path, 'images', '{}.png'.format(name))
if not os.path.exists(img): return if not os.path.exists(img): return
self.pixmap = QPixmap(img) # XXX Use QImage instead to support transparency! self.pixmap = QPixmap(img) # XXX Use QImage instead to support transparency!
self.label.setPixmap(self.pixmap) self.label.setPixmap(self.pixmap)
class Niko(QWidget): class Niko(QWidget):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.start_x, self.start_y = kwargs['start_x'], kwargs['start_y'] self.start_x, self.start_y = kwargs['start_x'], kwargs['start_y']
del kwargs['start_x'], kwargs['start_y'] del kwargs['start_x'], kwargs['start_y']
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.frames = [QPixmap(os.path.join(base_path, 'images', 'niko{}.png'.format(n)) for n in range(1,4))] self.frames = [QPixmap(os.path.join(base_path, 'images', 'niko{}.png'.format(n)) for n in range(1,4))]
self.setBackgroundRole(QPalette.Base) self.setBackgroundRole(QPalette.Base)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
if len(sys.argv) == 3: if len(sys.argv) == 3:
# "Niko-leaves-the-screen" mode # "Niko-leaves-the-screen" mode
x, y = int(sys.argv[1]), int(sys.argv[2]) x, y = int(sys.argv[1]), int(sys.argv[2])
else: else:
# Author's Journal mode # Author's Journal mode
journal = Journal() journal = Journal()
thread = WatchPipe() thread = WatchPipe()
thread.change_image.connect(journal.change_image) thread.change_image.connect(journal.change_image)
thread.start() thread.start()
app.exec_() app.exec_()