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

Added support for themes in cfclient and other minor improvements. #431

Merged
merged 7 commits into from
Aug 12, 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
6 changes: 4 additions & 2 deletions src/cfclient/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ def main():

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)
asyncio.set_event_loop(loop)

app.setWindowIcon(QIcon(cfclient.module_path + "/icon-256.png"))
app.setWindowIcon(QIcon(cfclient.module_path + "/ui/icons/icon-256.png"))
# Make sure the right icon is set in Windows 7+ taskbar
if os.name == 'nt':
import ctypes
Expand All @@ -159,7 +158,10 @@ def main():
pass

main_window = MainUI()
app.setStyleSheet(UiUtils.progressbar_stylesheet(UiUtils.COLOR_BLUE))
app.setFont(UiUtils.FONT)
main_window.show()
main_window.set_default_theme()
sys.exit(app.exec_())


Expand Down
5 changes: 4 additions & 1 deletion src/cfclient/ui/dialogs/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
The about dialog.
"""

import os
import sys

import cfclient
Expand Down Expand Up @@ -139,8 +140,10 @@ def __init__(self, helper, *args):

# Open the Credits file and show it in the UI
credits = ""
src = os.path.dirname(cfclient.module_path)
path = os.path.join(os.path.dirname(src), 'CREDITS.txt')
try:
with open("CREDITS.txt", encoding='utf-8', mode='r') as f:
with open(path, encoding='utf-8') as f:
for line in f:
credits += "{}<br>".format(line)
except IOError:
Expand Down
16 changes: 13 additions & 3 deletions src/cfclient/ui/dialogs/about.ui
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="About">
<attribute name="title">
Expand All @@ -39,7 +39,7 @@
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Copyright (c) 2011-2017, Bitcraze AB</string>
<string>Copyright (c) 2011-2020, Bitcraze AB</string>
</property>
</widget>
</item>
Expand All @@ -48,6 +48,12 @@
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;The Crazyflie client is a multi-platform client&lt;br/&gt;for controlling, bootloading and logging the Crazyflie.&lt;br/&gt;For more info visit our homepage.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.bitcraze.io&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Bitcraze Homepage&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;a href=&quot;http://wiki.bitcraze.io/doc:crazyflie:client:pycfclient:index&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Client documentation on Bitcraze Wiki&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;a href=&quot;http://forum.bitcraze.se&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Bitcraze Forum&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
<item row="3" column="0">
Expand Down Expand Up @@ -84,7 +90,11 @@
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTextEdit" name="_credits"/>
<widget class="QTextEdit" name="_credits">
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</item>
Expand Down
Binary file added src/cfclient/ui/icons/checkmark_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/cfclient/ui/icons/checkmark_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/cfclient/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,41 @@ def __init__(self, *args):

self._mapping_support = True

# Add checkbuttons for theme-selection.
self._theme_group = QActionGroup(self.menuThemes)
self._theme_group.setExclusive(True)
self._theme_checkboxes = []
for theme in UiUtils.THEMES:
node = QAction(theme, self.menuThemes, checkable=True)
node.setObjectName(theme)
node.toggled.connect(self._theme_selected)
self._theme_checkboxes.append(node)
self._theme_group.addAction(node)
self.menuThemes.addAction(node)

def _theme_selected(self, *args):
""" Callback when a theme is selected. """
for checkbox in self._theme_checkboxes:
if checkbox.isChecked():
theme = checkbox.objectName()
app = QtWidgets.QApplication.instance()
app.setStyleSheet(UiUtils.select_theme(theme))
Config().set('theme', theme)

def _check_theme(self, theme_name):
# Check the default theme.
for theme in self._theme_checkboxes:
if theme.objectName() == theme_name:
theme.setChecked(True)
self._theme_selected(True)

def set_default_theme(self):
try:
theme = Config().get('theme')
except KeyError:
theme = 'Default'
self._check_theme(theme)

def disable_input(self, disable):
"""
Disable the gamepad input to be able to send setpoint from a tab
Expand Down
24 changes: 18 additions & 6 deletions src/cfclient/ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
</property>
<property name="minimumSize">
<size>
<width>48</width>
<height>20</height>
<width>60</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>48</width>
<height>20</height>
<width>60</width>
<height>40</height>
</size>
</property>
<property name="alignment">
Expand Down Expand Up @@ -199,9 +199,15 @@
</item>
<item>
<widget class="HexSpinBox" name="address">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>140</width>
<width>158</width>
<height>0</height>
</size>
</property>
Expand Down Expand Up @@ -249,7 +255,7 @@
<x>0</x>
<y>0</y>
<width>852</width>
<height>498</height>
<height>493</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -346,12 +352,18 @@
<addaction name="_menuitem_rescandevices"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuThemes">
<property name="title">
<string>Themes</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuConnect"/>
<addaction name="_menu_inputdevice"/>
<addaction name="menuSettings"/>
<addaction name="menuView"/>
<addaction name="menuHelp"/>
<addaction name="menuThemes"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="menuItemConnect">
Expand Down
6 changes: 3 additions & 3 deletions src/cfclient/ui/tabs/LEDTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import cfclient
from cfclient.ui.tab import Tab
from cfclient.utils.ui import UiUtils

from cflib.crazyflie.mem import MemoryElement

Expand Down Expand Up @@ -125,9 +126,8 @@ def _select(self, nbr):
if col.isValid() and self._mem:
logger.info(col.red())
self._mem.leds[nbr].set(r=col.red(), g=col.green(), b=col.blue())
self.sender().setStyleSheet("background-color: rgb({},{},{})"
.format(col.red(), col.green(),
col.blue()))
UiUtils.set_background_color(self.sender(), col.red(), col.green(),
col.blue())
self._write_led_output()

def _intensity_change(self, value):
Expand Down
8 changes: 4 additions & 4 deletions src/cfclient/ui/tabs/qualisysTab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
<widget class="QLineEdit" name="posHoldPathBox">
<property name="maximumSize">
<size>
<width>30</width>
<width>45</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -528,7 +528,7 @@
<widget class="QLineEdit" name="radiusBox">
<property name="maximumSize">
<size>
<width>30</width>
<width>45</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -548,7 +548,7 @@
<widget class="QLineEdit" name="posHoldCircleBox">
<property name="maximumSize">
<size>
<width>30</width>
<width>45</width>
<height>16777215</height>
</size>
</property>
Expand All @@ -568,7 +568,7 @@
<widget class="QLineEdit" name="resolutionBox">
<property name="maximumSize">
<size>
<width>30</width>
<width>45</width>
<height>16777215</height>
</size>
</property>
Expand Down
Loading