Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved and cleaned up ui for progressbar stylesheets #430

Merged
merged 2 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cfclient/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def main():
from PyQt5.QtGui import QIcon

app = QApplication(sys.argv)
from cfclient.utils.ui import UiUtils
app.setStyleSheet(UiUtils.progressbar_stylesheet(UiUtils.COLOR_BLUE))

# Create and set an event loop that combines qt and asyncio
loop = QSelectorEventLoop(app)
Expand Down
6 changes: 3 additions & 3 deletions src/cfclient/ui/dialogs/logconfigdialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import struct

import cfclient
from cfclient.utils.ui import UiUtils
from PyQt5 import QtWidgets, uic, QtGui
from PyQt5.QtCore import Qt, QTimer

Expand All @@ -53,7 +54,6 @@
TYPE_FIELD = 2
SIZE_FIELD = 3
MAX_LOG_SIZE = 26
COLOR_GREEN = '#7cdb37'


class LogConfigDialogue(QtWidgets.QWidget, logconfig_widget_class):
Expand Down Expand Up @@ -404,13 +404,13 @@ def updatePacketSizeBar(self):
self.packetSize.setFormat("%v%")
self.packetSize.setValue(self.currentSize / MAX_LOG_SIZE * 100)
self.packetSize.setStyleSheet(
'QProgressBar::chunk { background: red;}')
UiUtils.progressbar_stylesheet('red'))
else:
self.packetSize.setMaximum(MAX_LOG_SIZE)
self.packetSize.setFormat("%p%")
self.packetSize.setValue(self.currentSize)
self.packetSize.setStyleSheet(
'QProgressBar::chunk { background: %s;}' % COLOR_GREEN)
UiUtils.progressbar_stylesheet(UiUtils.COLOR_GREEN))

def addNewVar(self, logTreeItem, target):
parentName = logTreeItem.parent().text(NAME_FIELD)
Expand Down
66 changes: 5 additions & 61 deletions src/cfclient/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from cfclient.utils.config_manager import ConfigManager
from cfclient.utils.input import JoystickReader
from cfclient.utils.logconfigreader import LogConfigReader
from cfclient.utils.ui import UiUtils
from cfclient.utils.zmq_led_driver import ZMQLEDDriver
from cfclient.utils.zmq_param import ZMQParamAccess
from cflib.crazyflie import Crazyflie
Expand Down Expand Up @@ -95,24 +96,6 @@ class BatteryStates:
BATTERY, CHARGING, CHARGED, LOW_POWER = list(range(4))


COLOR_BLUE = '#3399ff'
COLOR_GREEN = '#00ff60'
COLOR_RED = '#cc0404'


def progressbar_stylesheet(color):
return """
QProgressBar {
border: 1px solid #333;
background-color: transparent;
}

QProgressBar::chunk {
background-color: """ + color + """;
}
"""


class MainUI(QtWidgets.QMainWindow, main_window_class):
connectionLostSignal = pyqtSignal(str, str)
connectionInitiatedSignal = pyqtSignal(str)
Expand All @@ -137,42 +120,6 @@ def __init__(self, *args):
except KeyError:
pass

######################################################
# By lxrocks
# 'Skinny Progress Bar' tweak for Yosemite
# Tweak progress bar - artistic I am not - so pick your own colors !!!
# Only apply to Yosemite
######################################################
import platform

if platform.system() == 'Darwin':

(Version, junk, machine) = platform.mac_ver()
logger.info("This is a MAC - checking if we can apply Progress "
"Bar Stylesheet for Yosemite Skinny Bars ")
yosemite = (10, 10, 0)
tVersion = tuple(map(int, (Version.split("."))))

if tVersion >= yosemite:
logger.info("Found Yosemite - applying stylesheet")

tcss = """
QProgressBar {
border: 1px solid grey;
border-radius: 5px;
text-align: center;
}
QProgressBar::chunk {
background-color: """ + COLOR_BLUE + """;
}
"""
self.setStyleSheet(tcss)

else:
logger.info("Pre-Yosemite - skinny bar stylesheet not applied")

######################################################

self.cf = Crazyflie(ro_cache=None,
rw_cache=cfclient.config_path + "/cache")

Expand Down Expand Up @@ -275,10 +222,7 @@ def __init__(self, *args):
self._log_error_signal.connect(self._logging_error)

self.batteryBar.setTextVisible(False)
self.batteryBar.setStyleSheet(progressbar_stylesheet(COLOR_BLUE))

self.linkQualityBar.setTextVisible(False)
self.linkQualityBar.setStyleSheet(progressbar_stylesheet(COLOR_BLUE))

# Connect link quality feedback
self.cf.link_quality_updated.add_callback(self.linkQualitySignal.emit)
Expand Down Expand Up @@ -559,15 +503,15 @@ def _show_connect_dialog(self):
def _update_battery(self, timestamp, data, logconf):
self.batteryBar.setValue(int(data["pm.vbat"] * 1000))

color = COLOR_BLUE
color = UiUtils.COLOR_BLUE
# TODO firmware reports fully-charged state as 'Battery',
# rather than 'Charged'
if data["pm.state"] in [BatteryStates.CHARGING, BatteryStates.CHARGED]:
color = COLOR_GREEN
color = UiUtils.COLOR_GREEN
elif data["pm.state"] == BatteryStates.LOW_POWER:
color = COLOR_RED
color = UiUtils.COLOR_RED

self.batteryBar.setStyleSheet(progressbar_stylesheet(color))
self.batteryBar.setStyleSheet(UiUtils.progressbar_stylesheet(color))
self._aff_volts.setText(("%.3f" % data["pm.vbat"]))

def _connected(self):
Expand Down
18 changes: 0 additions & 18 deletions src/cfclient/ui/tabs/QualisysTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,6 @@ class FlightModeStates(Enum):
RECORD = 8


COLOR_BLUE = '#3399ff'
COLOR_GREEN = '#00ff60'
COLOR_RED = '#cc0404'


def progressbar_stylesheet(color):
return """
QProgressBar {
border: 1px solid #AAA;
background-color: transparent;
}

QProgressBar::chunk {
background-color: """ + color + """;
}
"""


def start_async_task(task):
return asyncio.ensure_future(task)

Expand Down
53 changes: 53 additions & 0 deletions src/cfclient/utils/ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
#
# ,---------, ____ _ __
# | ,-^-, | / __ )(_) /_______________ _____ ___
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
# | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2020 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.


__author__ = 'Bitcraze AB'
__all__ = ['UiUtils']


class UiUtils:

COLOR_GREEN = '#7cdb37'
COLOR_BLUE = '#3399ff'
COLOR_RED = '#cc0404'

@staticmethod
def progressbar_stylesheet(color):
return """
QProgressBar {
border: 1px solid gray;
border-radius: 2px;
background-color: transparent;
text-align: center;
}

QProgressBar::chunk {
border-radius: 2px;
background-color: """ + color + """;
}
"""