From 995dc23a72e3e151fbacdbc5611415b04b20cabe Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sun, 15 Dec 2019 13:54:18 -0300 Subject: [PATCH] [wgem] runtime dir | improving installation options dialog design --- bauh/gems/web/__init__.py | 6 ++++-- bauh/gems/web/controller.py | 12 +++++------- bauh/gems/web/environment.py | 4 ++-- bauh/view/qt/components.py | 26 ++++++++++++++++++++------ bauh/view/qt/confirmation.py | 6 +++--- bauh/view/qt/css.py | 15 +++++++++++++++ 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py index b801d238..c35e39c7 100644 --- a/bauh/gems/web/__init__.py +++ b/bauh/gems/web/__init__.py @@ -1,10 +1,12 @@ import os +from pathlib import Path from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -BIN_PATH = '{}/.local/share/bauh/web'.format(HOME_PATH) -INSTALLED_PATH = '{}/installed'.format(BIN_PATH) +WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home()) +INSTALLED_PATH = '{}/installed'.format(WEB_PATH) +BIN_PATH = '{}/runtime'.format(WEB_PATH) NODE_DIR_PATH = '{}/node'.format(BIN_PATH) NODE_PATHS = {NODE_DIR_PATH + '/bin'} NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index ed80f5bb..77bea64a 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -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.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \ 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.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.model import WebApplication @@ -243,7 +243,7 @@ class WebApplicationManager(SoftwareManager): options=[tray_op_off, tray_op_default, tray_op_min], 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_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_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'], body=None, @@ -447,9 +447,7 @@ class WebApplicationManager(SoftwareManager): return False def prepare(self): - if bool(int(os.getenv('BAUH_WEB_UPDATE_NODE', 1))): - self.env_updater = Thread(daemon=True, target=self._update_environment) - self.env_updater.start() + Thread(target=self._update_environment).start() def list_updates(self, internet_available: bool) -> List[PackageUpdate]: pass diff --git a/bauh/gems/web/environment.py b/bauh/gems/web/environment.py index b94ba65b..2c39d4be 100644 --- a/bauh/gems/web/environment.py +++ b/bauh/gems/web/environment.py @@ -199,7 +199,7 @@ class EnvironmentUpdater: return False - def get_environment(self) -> dict: + def read_settings(self) -> dict: try: 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: - settings = self.get_environment() + settings = self.read_settings() if settings is None: return diff --git a/bauh/view/qt/components.py b/bauh/view/qt/components.py index da15f554..438c2b4f 100644 --- a/bauh/view/qt/components.py +++ b/bauh/view/qt/components.py @@ -7,6 +7,7 @@ from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGrid from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \ TextInputComponent, FormComponent +from bauh.view.qt import css from bauh.view.util import resource @@ -160,12 +161,18 @@ class MultipleSelectQt(QGroupBox): def __init__(self, model: MultipleSelectComponent, callback): 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._layout = QGridLayout() 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() @@ -200,6 +207,9 @@ class MultipleSelectQt(QGroupBox): else: col += 1 + if model.label: + self.layout().addWidget(QLabel(), line + 1, 1) + class InputFilter(QLineEdit): @@ -248,22 +258,26 @@ class IconButton(QWidget): class FormQt(QGroupBox): def __init__(self, model: FormComponent): - super(FormQt, self).__init__() + super(FormQt, self).__init__(model.label if model.label else '') self.model = model self.setLayout(QFormLayout()) - self.setStyleSheet('QLabel { font-weight: bold; }') + self.setStyleSheet(css.GROUP_BOX) + + self.layout().addRow(QLabel(), QLabel()) for c in model.components: if isinstance(c, TextInputComponent): label, field = self._new_text_input(c) self.layout().addRow(label, field) 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) self.layout().addRow(label, field) else: raise Exception('Unsupported component type {}'.format(c.__class__.__name__)) + self.layout().addRow(QLabel(), QLabel()) + def _new_text_input(self, c: TextInputComponent) -> Tuple[QLabel, QLineEdit]: line_edit = QLineEdit() @@ -284,7 +298,7 @@ class FormQt(QGroupBox): c.value = text 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): diff --git a/bauh/view/qt/confirmation.py b/bauh/view/qt/confirmation.py index 0a8ec4ee..33488855 100644 --- a/bauh/view/qt/confirmation.py +++ b/bauh/view/qt/confirmation.py @@ -1,7 +1,7 @@ from typing import List 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, \ FormComponent @@ -63,10 +63,10 @@ class ConfirmationDialog(QMessageBox): 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: - self.layout().addWidget(QLabel(' ' * int(width / 2)), 0, 1) + self.layout().addWidget(QLabel(' ' * int(width / 2)), 1, 1) self.exec_() diff --git a/bauh/view/qt/css.py b/bauh/view/qt/css.py index 8162b252..49b411b0 100644 --- a/bauh/view/qt/css.py +++ b/bauh/view/qt/css.py @@ -2,3 +2,18 @@ OK_BUTTON = """QPushButton { background: green; color: white; font-weight: bold} 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; +} +""" \ No newline at end of file