class MainWindow(QtWidgets.QMainWindow, uic.loadUiType('data/planner.ui')[0]): def __init__(self): global main super().__init__() main = self self.setupUi(self) self.submit.clicked.connect(self.on_input) self.data_edit.returnPressed.connect(self.submit.click) self.storage_manager = StorageManager() self.storage_manager.start() self.music_player = MusicPlayer() self.music_player.start() self.scheduler = Scheduler(self) self.scheduler.start() self.log_units = [ self.storage_manager, self.music_player, self.scheduler ] self.checkbox_list = [] for k in range(16): self.checkbox_list.append(getattr(self, f'checkbox_list_item{k}')) def get_checkbox_handler(checkbox, k, callback): return lambda: callback(checkbox, k) for k, log_unit in enumerate(self.log_units): self.checkbox_list[k].setText(log_unit.log_header) self.checkbox_list[k].setChecked(True) self.checkbox_list[k].toggled.connect( get_checkbox_handler(self.checkbox_list[k], k, self.on_toggle_checkbox)) self.checkbox_list_autoscroll.setChecked(True) self.console_log = QStringListModel() self.console.setModel(self.console_log) self.schedule_tree.setHeaderLabels(['일자', '시간', '행동']) for head in entire_schedule: header = QTreeWidgetItem([head]) for tail_time in entire_schedule[head]: header.addChild( QTreeWidgetItem([ None, str(tail_time), entire_schedule[head][tail_time] ])) self.schedule_tree.addTopLevelItem(header) header.setExpanded(True) self.schedule_tree.doubleClicked.connect( self.on_double_click_schedule_tree) for k, macro_name in enumerate(quick_macros): create_quick_macro_button(k, macro_name, quick_macros[macro_name]) self.log_timer = QTimer() self.log_timer.setInterval(1000) self.log_timer.timeout.connect(self.on_check_log) self.log_timer.start() self.show() def closeEvent(self, c): print('Closing...') self.log_timer.stop() for log_unit in self.log_units: log_unit.close() log_unit.quit() def insert_log(self, log: str): row = self.console_log.rowCount() self.console_log.insertRow(row) index = self.console_log.index(row) print(log) self.console_log.setData(index, log) @pyqtSlot(QModelIndex) def on_double_click_schedule_tree(self, index): try: key = index.model().data(index, 2) if key is not None: self.parse_command(f'-{key}') except: self.insert_log(traceback.format_exc()) @pyqtSlot() def on_toggle_checkbox(self, check_box, k): if k < len(self.log_units): self.log_units[k].log_enable = check_box.isChecked() @pyqtSlot() def on_input(self): text = self.data_edit.text() self.parse_command(text.lower()) self.console.scrollToBottom() self.data_edit.setText('') for k, method_name in enumerate(quick_macros): button = getattr(self, f'button_list_item{k}') print(button.x(), button.y()) @pyqtSlot() def on_check_log(self): logs_to_insert = [] for k, log_unit in enumerate(self.log_units): if log_unit.is_empty(): continue for log in log_unit.flush_log(): logs_to_insert.append(log) if len(logs_to_insert) > 0: logs_to_insert.sort(key=lambda x: x[0]) for log in logs_to_insert: self.insert_log('%02d:%02d: %s' % (log[0].hour, log[0].minute, log[1].replace( os.getcwd(), '$://'))) if self.checkbox_list_autoscroll.isChecked(): self.console.scrollToBottom() @pyqtSlot(str) def parse_command(self, command: str): self.insert_log(f'>> {command}') try: if command == 'test': self.music_player.music_pause() self.music_player.play_unstoppable_music('audio/테스트.mp3') self.music_player.music_resume() elif command == 'get_musics': with self.storage_manager.lock: log = '=================현재 기상송===============\n' for file_path in self.storage_manager.files_to_play: log += file_path + '\n' log += '=========================================' self.insert_log(log) elif command == 'all_around_test': self.scheduler.all_around_test() elif command == 'abort_song': self.music_player.close() elif command.startswith('-'): self.scheduler.push_tag_command(command[1:]) else: self.insert_log(f'?? {command}') except: self.insert_log(traceback.format_exc()) self.insert_log(f'<< {command}')
# Copyright (c) 2016, Erik Moqvist # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # This file is part of the Pumbaa project. # from music_player import MusicPlayer music_player = MusicPlayer() music_player.start()
# Copyright (c) 2016-2017, Erik Moqvist # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # This file is part of the Pumbaa project. # from music_player import MusicPlayer music_player = MusicPlayer() music_player.start()
dialog.labelSongName.setText(title) def ui_update_on_queue_empty(is_empty: bool): dialog.buttonPlayPause.setIcon(QtGui.QIcon('icons/play.png')) def ui_update_on_queue_size_change(no_songs_in_queue: int): dialog.labelInQueue.setText('In queue: ' + str(no_songs_in_queue) + ' songs') player.on_title_change.connect(update_song_title) player.on_queue_empty.connect(ui_update_on_queue_empty) player.on_queue_size_change.connect(ui_update_on_queue_size_change) player.start() t = GUIUpdateSongProgress(player) t.completed.connect(update_progress_bar) t.start() s = GUIUpdateEmotion() s.emotion.connect(update_predominant_emotion) s.start() dialog.buttonPlayPause.clicked.connect(on_play_pause_clicked) dialog.buttonSkip.clicked.connect(on_skip_clicked) dialog.show() app.exec()