run button

This commit is contained in:
Vinicius Moreira
2019-08-27 18:08:30 -03:00
parent caf5ac4883
commit 82145a35a3
7 changed files with 44 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import os
import subprocess
from threading import Lock
from typing import List
@@ -367,6 +368,13 @@ class AppsTable(QTableWidget):
def _set_col_settings(self, idx: int, app_v: ApplicationView):
tb = QToolBar()
if app_v.model.can_be_run() and app_v.model.get_command():
def run():
self.window.run_app(app_v)
tb.addWidget(IconButton(icon_path=resource.get_path('img/app_play.png'), action=run, background='#088A08', tooltip=self.window.locale_keys['action.run.tooltip']))
if app_v.model.has_info():
def get_info():

View File

@@ -1,3 +1,4 @@
import subprocess
import time
from datetime import datetime, timedelta
from typing import List
@@ -342,3 +343,20 @@ class ListWarnings(QThread):
warnings = self.man.list_warnings()
if warnings:
self.signal_warnings.emit(warnings)
class RunApp(AsyncAction):
def __init__(self, app: ApplicationView = None):
super(RunApp, self).__init__()
self.app = app
def run(self):
if self.app:
try:
time.sleep(0.5)
subprocess.Popen(self.app.model.get_command().split(' '))
self.notify_finished(True)
except:
self.notify_finished(False)

View File

@@ -23,7 +23,7 @@ from bauh.view.qt.info import InfoDialog
from bauh.view.qt.root import is_root, ask_root_password
from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, RefreshApp, FindSuggestions, ListWarnings, \
AsyncAction
AsyncAction, RunApp
from bauh.view.qt.view_model import ApplicationView
DARK_ORANGE = '#FF4500'
@@ -163,6 +163,7 @@ class ManageWindow(QWidget):
self.thread_downgrade = self._bind_async_action(DowngradeApp(self.manager, self.locale_keys), finished_call=self._finish_downgrade)
self.thread_refresh_app = self._bind_async_action(RefreshApp(manager=self.manager), finished_call=self._finish_refresh)
self.thread_suggestions = self._bind_async_action(FindSuggestions(man=self.manager), finished_call=self._finish_search, only_finished=True)
self.thread_run_app = self._bind_async_action(RunApp(), finished_call=self._finish_run_app, only_finished=False)
self.thread_install = InstallApp(manager=self.manager, disk_cache=self.disk_cache, icon_cache=self.icon_cache, locale_keys=self.locale_keys)
self._bind_async_action(self.thread_install, finished_call=self._finish_install)
@@ -334,6 +335,11 @@ class ManageWindow(QWidget):
self.thread_uninstall.root_password = pwd
self.thread_uninstall.start()
def run_app(self, app: ApplicationView):
self._begin_action(self.locale_keys['manage_window.status.running_app'].format(app.model.base_data.name))
self.thread_run_app.app = app
self.thread_run_app.start()
def refresh(self, app: ApplicationView):
pwd = None
requires_root = self.manager.requires_root('refresh', app.model)
@@ -739,3 +745,6 @@ class ManageWindow(QWidget):
def _update_progress(self, value: int):
self.progress_bar.setValue(value)
def _finish_run_app(self, success: bool):
self.finish_action()