def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle("Audiolog Music Organizer") self.confDialog = ConfigurationDialog(self) self.directoryPathsToScan = [] self.running = False # Load icons iconsPath = os.path.join(os.path.dirname(__file__), "..", "..", "icons") playIcon = QIcon(os.path.join(iconsPath, "play.png")) pauseIcon = QIcon(os.path.join(iconsPath, "pause.png")) stopIcon = QIcon(os.path.join(iconsPath, "stop.png")) confIcon = QIcon(os.path.join(iconsPath, "configure.png")) logIcon = QIcon(os.path.join(iconsPath, "log.png")) # Menu and Status Bars self.setMenuBar(MenuBar(self)) self.statusBar = self.statusBar() # Top-Level Frame self.topLevelFrame = QFrame(self) # Graphics Frame self.graphicsFrame = GraphicsFrame(self.topLevelFrame) # Paths Frame self.pathsFrame = PathsFrame(self.topLevelFrame) # Button Frame self.buttonFrame = QFrame(self.topLevelFrame) self.flowButton = QPushButton("Start", icon=playIcon) self.stopButton = QPushButton("Stop", icon=stopIcon) self.confButton = QPushButton("Configure...", icon=confIcon) self.logButton = QPushButton("Show Log", icon=logIcon, checkable=True) self.stopButton.setEnabled(False) self.connect(self.flowButton, SIGNAL("clicked(bool)"), self.manageFlow) self.connect(self.stopButton, SIGNAL("clicked(bool)"), self.stop) self.connect(self.confButton, SIGNAL("clicked(bool)"), self.confDialog.show) self.connect(self.logButton, SIGNAL("clicked(bool)"), self.toggleLog) self.connect(flowcontrol.emitter, SIGNAL("RunEnded"), self.runEnded) buttonLayout = QHBoxLayout(self.buttonFrame) buttonLayout.addStretch(1) buttonLayout.addWidget(self.flowButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.stopButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.confButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.logButton, 3) buttonLayout.addStretch(1) # Stop Button Menu (Now and Cleanly) stopNow = QAction("Now", self.stopButton) stopCleanly = QAction("After Current Directory", self.stopButton) self.connect(stopNow, SIGNAL("triggered()"), self.stop) self.connect(stopCleanly, SIGNAL("triggered()"), partial(self.stop, True)) stopMenu = QMenu(self.stopButton) stopMenu.addAction(stopNow) stopMenu.addAction(stopCleanly) self.stopButton.setMenu(stopMenu) # Log Frame self.logFrame = LogFrame(self.topLevelFrame) self.logFrame.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.logFrame.hide() # Top-Level Frame Layout layout = QVBoxLayout(self.topLevelFrame) layout.addWidget(self.graphicsFrame) layout.addWidget(self.pathsFrame) layout.addWidget(self.buttonFrame) layout.addWidget(self.logFrame) # Makes window shrink back down again after log is hidden. layout.setSizeConstraint(QLayout.SetFixedSize) self.layout().setSizeConstraint(QLayout.SetFixedSize) self.setCentralWidget(self.topLevelFrame)
class MainWindow(QMainWindow): """The Audiolog GUI main window.""" def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle("Audiolog Music Organizer") self.confDialog = ConfigurationDialog(self) self.directoryPathsToScan = [] self.running = False # Load icons iconsPath = os.path.join(os.path.dirname(__file__), "..", "..", "icons") playIcon = QIcon(os.path.join(iconsPath, "play.png")) pauseIcon = QIcon(os.path.join(iconsPath, "pause.png")) stopIcon = QIcon(os.path.join(iconsPath, "stop.png")) confIcon = QIcon(os.path.join(iconsPath, "configure.png")) logIcon = QIcon(os.path.join(iconsPath, "log.png")) # Menu and Status Bars self.setMenuBar(MenuBar(self)) self.statusBar = self.statusBar() # Top-Level Frame self.topLevelFrame = QFrame(self) # Graphics Frame self.graphicsFrame = GraphicsFrame(self.topLevelFrame) # Paths Frame self.pathsFrame = PathsFrame(self.topLevelFrame) # Button Frame self.buttonFrame = QFrame(self.topLevelFrame) self.flowButton = QPushButton("Start", icon=playIcon) self.stopButton = QPushButton("Stop", icon=stopIcon) self.confButton = QPushButton("Configure...", icon=confIcon) self.logButton = QPushButton("Show Log", icon=logIcon, checkable=True) self.stopButton.setEnabled(False) self.connect(self.flowButton, SIGNAL("clicked(bool)"), self.manageFlow) self.connect(self.stopButton, SIGNAL("clicked(bool)"), self.stop) self.connect(self.confButton, SIGNAL("clicked(bool)"), self.confDialog.show) self.connect(self.logButton, SIGNAL("clicked(bool)"), self.toggleLog) self.connect(flowcontrol.emitter, SIGNAL("RunEnded"), self.runEnded) buttonLayout = QHBoxLayout(self.buttonFrame) buttonLayout.addStretch(1) buttonLayout.addWidget(self.flowButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.stopButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.confButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.logButton, 3) buttonLayout.addStretch(1) # Stop Button Menu (Now and Cleanly) stopNow = QAction("Now", self.stopButton) stopCleanly = QAction("After Current Directory", self.stopButton) self.connect(stopNow, SIGNAL("triggered()"), self.stop) self.connect(stopCleanly, SIGNAL("triggered()"), partial(self.stop, True)) stopMenu = QMenu(self.stopButton) stopMenu.addAction(stopNow) stopMenu.addAction(stopCleanly) self.stopButton.setMenu(stopMenu) # Log Frame self.logFrame = LogFrame(self.topLevelFrame) self.logFrame.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.logFrame.hide() # Top-Level Frame Layout layout = QVBoxLayout(self.topLevelFrame) layout.addWidget(self.graphicsFrame) layout.addWidget(self.pathsFrame) layout.addWidget(self.buttonFrame) layout.addWidget(self.logFrame) # Makes window shrink back down again after log is hidden. layout.setSizeConstraint(QLayout.SetFixedSize) self.layout().setSizeConstraint(QLayout.SetFixedSize) self.setCentralWidget(self.topLevelFrame) def manageFlow(self): """Start a thread if one is not running; toggle pause if one is.""" if not self.running: # Not running, start a new thread self.start() elif not flowcontrol.PAUSED: # Currently running, pause self.pause() else: # Currently paused, unpause self.unpause() def start(self): if not configuration.PATHS["TO_SCAN"]: self.confDialog.show() return self.running = True self.logFrame.clearLog() self.handlerThread = threading.Thread(target=traverse.handleIt) self.handlerThread.setDaemon(True) self.handlerThread.start() self.statusBar.showMessage("Audiolog running...") self.flowButton.setText("Pause") self.stopButton.setEnabled(True) def pause(self): flowcontrol.pause() self.flowButton.setText("Unpause") self.statusBar.showMessage("Current run paused.") def unpause(self): flowcontrol.unpause() self.flowButton.setText("Pause") self.statusBar.showMessage("Audiolog running...") def stop(self, cleanly=False): """Stop the currently running handler thread.""" if not self.running: self.statusBar.showMessage("Audiolog isn't running.", 5) return if cleanly: self.statusBar.showMessage( "Stopping after current directory is complete...") else: self.statusBar.showMessage("Stopping immediately.") flowcontrol.stop(cleanly) def runEnded(self, status="complete"): """Initialize GUI; display run status in status bar. This function is bound to the RunEnded signal which is emitted when the handler thread ends, either from completion, error or being stopped.""" flowcontrol.initialize() self.running = False self.flowButton.setText("Start") self.stopButton.setEnabled(False) self.statusBar.showMessage("Run %s." % status) def showConfDialog(self): """Display the configuration dialog box.""" self.confDialog.show() def toggleLog(self): """Toggle the visiblity of the log.""" if self.logFrame.isVisible(): self.logFrame.hide() else: self.logFrame.show()
class MainWindow(QMainWindow): """The Audiolog GUI main window.""" def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setWindowTitle("Audiolog Music Organizer") self.confDialog = ConfigurationDialog(self) self.directoryPathsToScan = [] self.running = False # Load icons iconsPath = os.path.join(os.path.dirname(__file__), "..", "..", "icons") playIcon = QIcon(os.path.join(iconsPath, "play.png")) pauseIcon = QIcon(os.path.join(iconsPath, "pause.png")) stopIcon = QIcon(os.path.join(iconsPath, "stop.png")) confIcon = QIcon(os.path.join(iconsPath, "configure.png")) logIcon = QIcon(os.path.join(iconsPath, "log.png")) # Menu and Status Bars self.setMenuBar(MenuBar(self)) self.statusBar = self.statusBar() # Top-Level Frame self.topLevelFrame = QFrame(self) # Graphics Frame self.graphicsFrame = GraphicsFrame(self.topLevelFrame) # Paths Frame self.pathsFrame = PathsFrame(self.topLevelFrame) # Button Frame self.buttonFrame = QFrame(self.topLevelFrame) self.flowButton = QPushButton("Start", icon=playIcon) self.stopButton = QPushButton("Stop", icon=stopIcon) self.confButton = QPushButton("Configure...", icon=confIcon) self.logButton = QPushButton("Show Log", icon=logIcon, checkable=True) self.stopButton.setEnabled(False) self.connect(self.flowButton, SIGNAL("clicked(bool)"), self.manageFlow) self.connect(self.stopButton, SIGNAL("clicked(bool)"), self.stop) self.connect(self.confButton, SIGNAL("clicked(bool)"), self.confDialog.show) self.connect(self.logButton, SIGNAL("clicked(bool)"), self.toggleLog) self.connect(flowcontrol.emitter, SIGNAL("RunEnded"), self.runEnded) buttonLayout = QHBoxLayout(self.buttonFrame) buttonLayout.addStretch(1) buttonLayout.addWidget(self.flowButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.stopButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.confButton, 3) buttonLayout.addStretch(1) buttonLayout.addWidget(self.logButton, 3) buttonLayout.addStretch(1) # Stop Button Menu (Now and Cleanly) stopNow = QAction("Now", self.stopButton) stopCleanly = QAction("After Current Directory", self.stopButton) self.connect(stopNow, SIGNAL("triggered()"), self.stop) self.connect(stopCleanly, SIGNAL("triggered()"), partial(self.stop, True)) stopMenu = QMenu(self.stopButton) stopMenu.addAction(stopNow) stopMenu.addAction(stopCleanly) self.stopButton.setMenu(stopMenu) # Log Frame self.logFrame = LogFrame(self.topLevelFrame) self.logFrame.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.logFrame.hide() # Top-Level Frame Layout layout = QVBoxLayout(self.topLevelFrame) layout.addWidget(self.graphicsFrame) layout.addWidget(self.pathsFrame) layout.addWidget(self.buttonFrame) layout.addWidget(self.logFrame) # Makes window shrink back down again after log is hidden. layout.setSizeConstraint(QLayout.SetFixedSize) self.layout().setSizeConstraint(QLayout.SetFixedSize) self.setCentralWidget(self.topLevelFrame) def manageFlow(self): """Start a thread if one is not running; toggle pause if one is.""" if not self.running: # Not running, start a new thread self.start() elif not flowcontrol.PAUSED: # Currently running, pause self.pause() else: # Currently paused, unpause self.unpause() def start(self): if not configuration.PATHS["TO_SCAN"]: self.confDialog.show() return self.running = True self.logFrame.clearLog() self.handlerThread = threading.Thread(target=traverse.handleIt) self.handlerThread.setDaemon(True) self.handlerThread.start() self.statusBar.showMessage("Audiolog running...") self.flowButton.setText("Pause") self.stopButton.setEnabled(True) def pause(self): flowcontrol.pause() self.flowButton.setText("Unpause") self.statusBar.showMessage("Current run paused.") def unpause(self): flowcontrol.unpause() self.flowButton.setText("Pause") self.statusBar.showMessage("Audiolog running...") def stop(self, cleanly=False): """Stop the currently running handler thread.""" if not self.running: self.statusBar.showMessage("Audiolog isn't running.", 5) return if cleanly: self.statusBar.showMessage("Stopping after current directory is complete...") else: self.statusBar.showMessage("Stopping immediately.") flowcontrol.stop(cleanly) def runEnded(self, status="complete"): """Initialize GUI; display run status in status bar. This function is bound to the RunEnded signal which is emitted when the handler thread ends, either from completion, error or being stopped.""" flowcontrol.initialize() self.running = False self.flowButton.setText("Start") self.stopButton.setEnabled(False) self.statusBar.showMessage("Run %s." % status) def showConfDialog(self): """Display the configuration dialog box.""" self.confDialog.show() def toggleLog(self): """Toggle the visiblity of the log.""" if self.logFrame.isVisible(): self.logFrame.hide() else: self.logFrame.show()