def __init__(self, parent_widget, container_info, group) -> None: self.repo = container_info['from'] self.ui = ShortAppWidgetUi(parent_widget, self) self.disable_button = False self.group = group self.ui.from_repo.setText(self._translate(self.template, "#Dockerhub")) self.ui.install.setText(self._translate(self.template, "Install")) self.ui.name.setText( self._translate(self.template, container_info['name'])) if containers_service.isAppInstalled(container_info['name']): self.ui.install.setText(self._translate("widget", "Installed")) self.ui.install.setStyleSheet( 'border: 1px solid gray; padding: 1px 6px; color: gray') self.disable_button = True self.ui.install.clicked.connect(self.installApp) if 'description' not in container_info: worker = Worker(containers_service.getContainerInfo, container_info['name'], container_info['is_official']) worker.signals.result.connect(self.showInfo) threadpool.start(worker) else: self.showInfo(container_info) if 'logo_url' not in container_info: worker = Worker(containers_service.getContainerLogo, container_info['name']) worker.signals.result.connect(self.showLogo) threadpool.start(worker) else: self.showLogo(container_info['logo_url'])
def onSyncClicked(self): self.ui.sync.setText(self._tr(self.template, "Syncing")) worker = Worker(containers_service.updateContainerTags, self.container) worker.signals.result.connect( lambda: self.ui.sync.setText(self._tr(self.template, "Sync"))) worker.signals.finished.connect(self.loadTags) threadpool.start(worker)
def installApp(self): if self.disable_button: return self.disable_button = True self.ui.install.setText(self._translate(self.template, "Installing")) worker = Worker(containers_service.installContainer, self.ui.name.text(), self.repo, self.ui.description.text(), "latest", None, None, self.group) worker.signals.result.connect(self.onAppInstalled) threadpool.start(worker)
def controlApp(self, start_only=False, force=False): if not containers_service.isContainerRunning(self.container): self.ui.status.setText('Starting') worker = Worker(containers_service.startContainer, self.container, start_only, force) worker.signals.result.connect(self.onAppStarted) else: self.ui.status.setText('Stopping') worker = Worker(containers_service.stopContainer, self.container) worker.signals.error.connect(self.onFailure) threadpool.start(worker)
def cloneContainer(self, action): clone_to_workspace = action.text() if clone_to_workspace == 'Unspecified workspace': workspace = workspace_service.getDefaultWorkspace() else: workspace = workspace_service.getWorkspace(clone_to_workspace) worker = Worker(containers_service.cloneContainer, self.container, workspace) worker.signals.result.connect( lambda x: data_transporter_service.fire(CONTAINER_CHANNEL, x)) threadpool.start(worker)
def restartContainer(self): if containers_service.isContainerRunning(self.container): self.ui.status.setText('Stopping') worker = Worker(containers_service.stopContainer, self.container) worker.signals.result.connect(self.restartContainer) else: self.ui.status.setText('Starting') containers_service.startContainer(self.container) worker = Worker(containers_service.startContainer, self.container) worker.signals.result.connect(self.onAppStarted) worker.signals.error.connect(self.onFailure) threadpool.start(worker)
def prefetchDefaultContainersInBackground(): """ Fetch the default search result in background Will be run once per day """ try: last_time_fetched = float( global_preference_service.getPreference( DEFAULT_SEARCH_UPDATE_DATE).value) if time.time() - last_time_fetched < 24 * 3600: return except DoesNotExist: pass worker = Worker(prefetchDefaultContainers) threadpool.start(worker)
def showLogo(self, logo): if logo is not None: worker = Worker(self.getImage, logo) worker.signals.result.connect(self.drawLogo) threadpool.start(worker, 99)