def init_settings(): """Time conf """ time_now = QTime.currentTime() time_start = settings_time_start() time_end = settings_time_end() if not time_start: SETTINGS.setValue('time_start', time_now.toString()) if not time_end: SETTINGS.setValue('time_end', time_now.toString()) if not SETTINGS.value('color'): SETTINGS.setValue('color', '#FFFFFF') SETTINGS.sync()
def init_main_window(self): self.setWindowTitle('Hope') if 'darwin' in str(sys.platform): self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint) else: self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool) self.setAttribute(Qt.WA_TranslucentBackground, True) self.resize(SETTINGS.value('screen_width'), HEIGHT + 20)
def hideEvent(self, event): time_end = self.time_editor_end.time() time_start = self.time_editor_start.time() if time_end < time_start: time_end, time_start = time_start, time_end SETTINGS.setValue('time_end', time_end.toString()) SETTINGS.setValue('time_start', time_start.toString()) SETTINGS.sync() self.app.view_main.start_to_hope()
def run(self): width = SETTINGS.value('screen_width') time_delta = settings_time_delta() if time_delta < 1: time_delta = 1 while True: frequency = time_delta / 1000 / width if frequency < 0.0166: frequency = 0.0166 delta = (settings_time_end().msecsSinceStartOfDay() - QTime.currentTime().msecsSinceStartOfDay()) process = 1 - delta / time_delta if process > 100 or process < 0: break pixel = int(process * width) self.countChanged.emit(pixel) sleep(frequency) self.countChanged.emit(width)
def init_settings(self): # Screen conf screen = self.app.primaryScreen() screen_size = screen.size() width = screen_size.width() height = screen_size.height() rect = screen.availableGeometry() print('Screen: %s' % screen.name()) print('Size: %d x %d' % (width, height)) print('Available size: %d x %d' % (rect.width(), rect.height())) print('Available at: %d, %d' % (rect.x(), rect.y())) SETTINGS.setValue('screen_width', width) SETTINGS.setValue('screen_height', height) y = rect.y() if rect.y() else 0 self.move(0, y) SETTINGS.sync()
def on_refresh(self, value): self.frm.setGeometry(0, 0, value, HEIGHT) color = SETTINGS.value('color') self.frm.setStyleSheet('QWidget { background-color: %s }' % color) self.l.setGeometry(value - self.l.width() / 2, 0, 20, 20)
def init_frm(self): color = SETTINGS.value('color') self.frm.setStyleSheet('QWidget { background-color: %s }' % color) self.frm.setGeometry(0, 0, 0, HEIGHT)
def show_color_dialog(): col = QColorDialog.getColor() if col.isValid(): SETTINGS.setValue('color', col.name())
def showEvent(self, event): self.time_editor_start.setTime( QTime.fromString(SETTINGS.value('time_start'))) self.time_editor_end.setTime( QTime.fromString(SETTINGS.value('time_end')))