def alert(self, repo): if Settings().show_msg: repo_name = QtCore.QFileInfo(repo).fileName() self.tray_icon.showMessage( repo_name, "Remote repository has been updated. It's time to pull!") if Settings().play_sound: QtMultimedia.QSound.play(':/time2pull/sounds/sonar.wav')
def on_pushButtonRemove_clicked(self): repo = self.listWidgetRepos.currentItem().text() answer = QtWidgets.QMessageBox.question( self, 'Remove repository', 'Are you sure you want to remove repository: %s?' % repo) if answer == QtWidgets.QMessageBox.Yes: self.listWidgetRepos.takeItem(self.listWidgetRepos.currentRow()) settings = Settings() repos = settings.repositories try: repos.remove(repo) except ValueError: pass settings.repositories = repos
def closeEvent(self, event): if not self._quitting: if (not self._user_warned_about_tray and not Settings().hide_on_startup): QtWidgets.QMessageBox.information( self, "Time2Pull", "The program will keep running in the system tray.\n" "To terminate the program, choose Quit in the context menu" " of the system tray entry.") self._user_warned_about_tray = True self.hide() event.ignore() # save geometry and state s = Settings() s.geometry = self.saveGeometry() s.state = self.saveState()
def main(): global app, win app = QtWidgets.QApplication(sys.argv) win = MainWindow() if not Settings().hide_on_startup: win.show() app.exec_()
def get_tray_icon(is_behind): if is_behind: return QtGui.QIcon(':/time2pull/icons/Download.png') else: icons = { TrayIconType.light: ':/time2pull/icons/Download-light.png', TrayIconType.dark: ':/time2pull/icons/Download-dark.png' } return QtGui.QIcon(icons[Settings().tray_icon_type])
def load_repo_from_settings(self): self.listWidgetRepos.clear() self.listWidgetRepos.setIconSize(QtCore.QSize(64, 64)) settings = Settings() for file in settings.repositories: item = QtWidgets.QListWidgetItem() item.setText(file) item.setIcon(get_status_icon()) item.setData(QtCore.Qt.UserRole, (False, RemoteStatus.up_to_date)) self.listWidgetRepos.addItem(item)
def on_pushButtonAdd_clicked(self): path = QtWidgets.QFileDialog.getExistingDirectory( self, 'Select a repository') settings = Settings() if path and path not in settings.repositories: if os.path.exists(os.path.join(path, '.git')): repos = settings.repositories repos.append(path) settings.repositories = repos item = QtWidgets.QListWidgetItem() item.setText(path) item.setIcon(get_status_icon()) item.setData(QtCore.Qt.UserRole, (False, RemoteStatus.up_to_date)) self.listWidgetRepos.addItem(item) self.on_refresh_requested() else: QtWidgets.QMessageBox.warning( self, 'Not a git repository', 'The chosen directory is not a git repository')
def setup_tray_icon_mnu(self): self.tray_icon_menu = QtWidgets.QMenu(self) self.tray_icon_menu.addAction(self.actionRestore) self.tray_icon_menu.addSeparator() self.tray_icon_menu.addAction(self.actionAdd) self.actionAdd.triggered.connect(self.on_pushButtonAdd_clicked) self.tray_icon_menu.addAction(self.actionRefresh) self.actionRefresh.triggered.connect(self.on_refresh_requested) self.tray_icon_menu.addSeparator() # Preferences preferences = QtWidgets.QMenu('Preferences', self) self.actionIconGroup = QtWidgets.QActionGroup(self) self.actionIconGroup.triggered.connect( self.on_tray_icon_style_triggered) for title in ['Light icon', 'Dark icon']: action = QtWidgets.QAction(title, self) action.setCheckable(True) self.actionIconGroup.addAction(action) self.actionIconGroup.actions()[int(TrayIconType.light)].setChecked( Settings().tray_icon_type == TrayIconType.light) self.actionIconGroup.actions()[int(TrayIconType.dark)].setChecked( Settings().tray_icon_type == TrayIconType.dark) mnu = QtWidgets.QMenu(self) mnu.setTitle('Tray icon') mnu.addActions(self.actionIconGroup.actions()) preferences.addMenu(mnu) preferences.addAction(self.actionHide_on_startup) self.actionHide_on_startup.setChecked(Settings().hide_on_startup) self.tray_icon_menu.addMenu(preferences) preferences.addAction(self.actionPlay_alert_sound) preferences.addAction(self.actionShow_message) self.actionShow_message.setChecked(Settings().show_msg) self.actionPlay_alert_sound.setChecked(Settings().play_sound) self.tray_icon_menu.addSeparator() self.tray_icon_menu.addAction(self.actionHelp) self.tray_icon_menu.addAction(self.actionAbout) self.actionHelp.setShortcut(QtGui.QKeySequence.HelpContents) self.tray_icon_menu.addSeparator() self.tray_icon_menu.addAction(self.actionQuit) self.actionQuit.setShortcut(QtGui.QKeySequence.Quit)
def restore_geometry_and_state(self): s = Settings() if s.geometry: self.restoreGeometry(s.geometry) if s.state: self.restoreState(s.state)
def on_actionShow_message_triggered(self): Settings().show_msg = self.actionShow_message.isChecked()
def on_actionPlay_alert_sound_triggered(self): Settings().play_sound = self.actionPlay_alert_sound.isChecked()
def on_actionHide_on_startup_toggled(self, checked): Settings().hide_on_startup = checked
def on_tray_icon_style_triggered(self, action): ltext = action.text().lower() settings = Settings() settings.tray_icon_type = ( TrayIconType.dark if 'dark' in ltext else TrayIconType.light) self.update_tray_icon()
def _get_repositories_to_refresh(self): # maybe only the selected if there is a selection ? not sure it would # be useful. return Settings().repositories