[wgem] runtime dir | improving installation options dialog design

This commit is contained in:
Vinicius Moreira
2019-12-15 13:54:18 -03:00
parent fa9038025e
commit 995dc23a72
6 changed files with 49 additions and 20 deletions

View File

@@ -1,10 +1,12 @@
import os import os
from pathlib import Path
from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
BIN_PATH = '{}/.local/share/bauh/web'.format(HOME_PATH) WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home())
INSTALLED_PATH = '{}/installed'.format(BIN_PATH) INSTALLED_PATH = '{}/installed'.format(WEB_PATH)
BIN_PATH = '{}/runtime'.format(WEB_PATH)
NODE_DIR_PATH = '{}/node'.format(BIN_PATH) NODE_DIR_PATH = '{}/node'.format(BIN_PATH)
NODE_PATHS = {NODE_DIR_PATH + '/bin'} NODE_PATHS = {NODE_DIR_PATH + '/bin'}
NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH) NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH)

View File

@@ -19,10 +19,10 @@ from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \ from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \
SelectViewType, TextInputComponent, FormComponent SelectViewType, TextInputComponent, FormComponent
from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR from bauh.api.constants import DESKTOP_ENTRIES_DIR
from bauh.commons.html import bold from bauh.commons.html import bold
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN, environment
from bauh.gems.web.environment import EnvironmentUpdater from bauh.gems.web.environment import EnvironmentUpdater
from bauh.gems.web.model import WebApplication from bauh.gems.web.model import WebApplication
@@ -243,7 +243,7 @@ class WebApplicationManager(SoftwareManager):
options=[tray_op_off, tray_op_default, tray_op_min], options=[tray_op_off, tray_op_default, tray_op_min],
label=self.i18n['web.install.option.tray.label']) label=self.i18n['web.install.option.tray.label'])
form_1 = FormComponent(components=[inp_url, inp_name, inp_desc, inp_cat, inp_tray]) form_1 = FormComponent(components=[inp_url, inp_name, inp_desc, inp_cat, inp_tray], label="Basic")
op_single = InputOption(id_='single', label=self.i18n['web.install.option.single.label'], value="--single-instance", tooltip=self.i18n['web.install.option.single.tip']) op_single = InputOption(id_='single', label=self.i18n['web.install.option.single.label'], value="--single-instance", tooltip=self.i18n['web.install.option.single.tip'])
op_max = InputOption(id_='max', label=self.i18n['web.install.option.max.label'], value="--maximize", tooltip=self.i18n['web.install.option.max.tip']) op_max = InputOption(id_='max', label=self.i18n['web.install.option.max.label'], value="--maximize", tooltip=self.i18n['web.install.option.max.tip'])
@@ -254,7 +254,7 @@ class WebApplicationManager(SoftwareManager):
op_insecure = InputOption(id_='insecure', label=self.i18n['web.install.option.insecure.label'], value="--insecure", tooltip=self.i18n['web.install.option.insecure.tip']) op_insecure = InputOption(id_='insecure', label=self.i18n['web.install.option.insecure.label'], value="--insecure", tooltip=self.i18n['web.install.option.insecure.tip'])
op_igcert = InputOption(id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip']) op_igcert = InputOption(id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip'])
check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='') check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='Advanced')
res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'], res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
body=None, body=None,
@@ -447,9 +447,7 @@ class WebApplicationManager(SoftwareManager):
return False return False
def prepare(self): def prepare(self):
if bool(int(os.getenv('BAUH_WEB_UPDATE_NODE', 1))): Thread(target=self._update_environment).start()
self.env_updater = Thread(daemon=True, target=self._update_environment)
self.env_updater.start()
def list_updates(self, internet_available: bool) -> List[PackageUpdate]: def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
pass pass

View File

@@ -199,7 +199,7 @@ class EnvironmentUpdater:
return False return False
def get_environment(self) -> dict: def read_settings(self) -> dict:
try: try:
res = self.http_client.get(URL_ENVIRONMENT_SETTINGS) res = self.http_client.get(URL_ENVIRONMENT_SETTINGS)
@@ -217,7 +217,7 @@ class EnvironmentUpdater:
def update_environment(self, is_x86_x64_arch: bool, handler: ProcessHandler = None) -> dict: def update_environment(self, is_x86_x64_arch: bool, handler: ProcessHandler = None) -> dict:
settings = self.get_environment() settings = self.read_settings()
if settings is None: if settings is None:
return return

View File

@@ -7,6 +7,7 @@ from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGrid
from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \ from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \
TextInputComponent, FormComponent TextInputComponent, FormComponent
from bauh.view.qt import css
from bauh.view.util import resource from bauh.view.util import resource
@@ -160,12 +161,18 @@ class MultipleSelectQt(QGroupBox):
def __init__(self, model: MultipleSelectComponent, callback): def __init__(self, model: MultipleSelectComponent, callback):
super(MultipleSelectQt, self).__init__(model.label if model.label else None) super(MultipleSelectQt, self).__init__(model.label if model.label else None)
self.setStyleSheet("QGroupBox { font-weight: bold }") self.setStyleSheet(css.GROUP_BOX)
self.model = model self.model = model
self._layout = QGridLayout() self._layout = QGridLayout()
self.setLayout(self._layout) self.setLayout(self._layout)
line, col = 0, 0 if model.label:
line = 1
self.layout().addWidget(QLabel(), 0, 1)
else:
line = 0
col = 0
pixmap_help = QPixmap() pixmap_help = QPixmap()
@@ -200,6 +207,9 @@ class MultipleSelectQt(QGroupBox):
else: else:
col += 1 col += 1
if model.label:
self.layout().addWidget(QLabel(), line + 1, 1)
class InputFilter(QLineEdit): class InputFilter(QLineEdit):
@@ -248,22 +258,26 @@ class IconButton(QWidget):
class FormQt(QGroupBox): class FormQt(QGroupBox):
def __init__(self, model: FormComponent): def __init__(self, model: FormComponent):
super(FormQt, self).__init__() super(FormQt, self).__init__(model.label if model.label else '')
self.model = model self.model = model
self.setLayout(QFormLayout()) self.setLayout(QFormLayout())
self.setStyleSheet('QLabel { font-weight: bold; }') self.setStyleSheet(css.GROUP_BOX)
self.layout().addRow(QLabel(), QLabel())
for c in model.components: for c in model.components:
if isinstance(c, TextInputComponent): if isinstance(c, TextInputComponent):
label, field = self._new_text_input(c) label, field = self._new_text_input(c)
self.layout().addRow(label, field) self.layout().addRow(label, field)
elif isinstance(c, SingleSelectComponent): elif isinstance(c, SingleSelectComponent):
label = QLabel(c.label.capitalize() + ':' if c.label else '') label = QLabel(c.label.capitalize() if c.label else '')
field = ComboBoxQt(c) field = ComboBoxQt(c)
self.layout().addRow(label, field) self.layout().addRow(label, field)
else: else:
raise Exception('Unsupported component type {}'.format(c.__class__.__name__)) raise Exception('Unsupported component type {}'.format(c.__class__.__name__))
self.layout().addRow(QLabel(), QLabel())
def _new_text_input(self, c: TextInputComponent) -> Tuple[QLabel, QLineEdit]: def _new_text_input(self, c: TextInputComponent) -> Tuple[QLabel, QLineEdit]:
line_edit = QLineEdit() line_edit = QLineEdit()
@@ -284,7 +298,7 @@ class FormQt(QGroupBox):
c.value = text c.value = text
line_edit.textChanged.connect(update_model) line_edit.textChanged.connect(update_model)
return QLabel(c.label.capitalize() + ':' if c.label else ''), line_edit return QLabel(c.label.capitalize() if c.label else ''), line_edit
def new_single_select(model: SingleSelectComponent): def new_single_select(model: SingleSelectComponent):

View File

@@ -1,7 +1,7 @@
from typing import List from typing import List
from PyQt5.QtCore import QSize, Qt from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QWidget, QScrollArea, QFrame from PyQt5.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QWidget, QScrollArea, QFrame, QSizePolicy
from bauh.api.abstract.view import ViewComponent, SingleSelectComponent, MultipleSelectComponent, TextInputComponent, \ from bauh.api.abstract.view import ViewComponent, SingleSelectComponent, MultipleSelectComponent, TextInputComponent, \
FormComponent FormComponent
@@ -63,10 +63,10 @@ class ConfirmationDialog(QMessageBox):
scroll.setFixedHeight(height) scroll.setFixedHeight(height)
self.layout().addWidget(scroll, 1, 1) self.layout().addWidget(scroll, 1 if body else 0, 1)
if not body and width > 0: if not body and width > 0:
self.layout().addWidget(QLabel(' ' * int(width / 2)), 0, 1) self.layout().addWidget(QLabel(' ' * int(width / 2)), 1, 1)
self.exec_() self.exec_()

View File

@@ -2,3 +2,18 @@
OK_BUTTON = """QPushButton { background: green; color: white; font-weight: bold} OK_BUTTON = """QPushButton { background: green; color: white; font-weight: bold}
QPushButton:disabled { background-color: gray; } QPushButton:disabled { background-color: gray; }
""" """
GROUP_BOX = """
QGroupBox {
font-weight: bold;
font-size: 12px;
border: 1px solid silver;
border-radius: 6px;
margin-top: 6px;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 7px;
padding: 0px 5px 0px 5px;
}
"""