Skip to content

Commit

Permalink
Added xmllint and fleka8 (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored Dec 13, 2023
1 parent 0ee90f5 commit d5a0d10
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 94 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a format job. Pre-commit has a first-party GitHub action, so we use
# that: https://github.com/pre-commit/action

name: Format

on:
workflow_dispatch:
pull_request:

jobs:
pre-commit:
name: Format
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: 3.10.6
- uses: pre-commit/[email protected]
with:
extra_args: --all-files --hook-stage manual
84 changes: 84 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
exclude_types: [rst]
- id: fix-byte-order-marker


# Python hooks
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py36-plus]

# Flake8
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
args: ["--extend-ignore=E501"]

# Cmake hooks
- repo: local
hooks:
- id: ament_lint_cmake
name: ament_lint_cmake
description: Check format of CMakeLists.txt files.
stages: [commit]
entry: ament_lint_cmake
language: system
files: CMakeLists\.txt$

# Docs - RestructuredText hooks
- repo: https://github.com/PyCQA/doc8
rev: 0.10.1
hooks:
- id: doc8
args: ['--max-line-length=100', '--ignore=D001']
exclude: CHANGELOG\.rst$

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: rst-backticks
exclude: CHANGELOG\.rst$
- id: rst-directive-colons
- id: rst-inline-touching-normal

# Spellcheck in comments and docs
# skipping of *.svg files is not working...
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: ['--write-changes']
exclude: CHANGELOG\.rst|\.(svg|pyc)$
5 changes: 4 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>rqt_gauges_2</name>
<version>0.0.1</version>
<description>Visualization plugin for several sensors.</description>

<maintainer email="[email protected]">Eloy Bricneo</maintainer>

<license file="LICENSE">BSD Clause 3</license>
Expand All @@ -16,6 +16,9 @@
<exec_depend>rqt_gui</exec_depend>
<exec_depend>rqt_gui_py</exec_depend>

<test_depend>ament_flake8</test_depend>
<test_depend>ament_xmllint</test_depend>

<export>
<architecture_independent/>
<build_type>ament_python</build_type>
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
junit_family=xunit2
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'rqt_gauges_2 is a Python GUI plugin providing a visualization tool for several sensors.'
),
license='BSD Clause 3',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'rqt_gauges_2 = ' + package_name + '.main:main',
Expand Down
2 changes: 1 addition & 1 deletion src/rqt_gauges_2/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys

from rqt_gui.main import Main
from rqt_gauges_2.speedometer import Speedometer


def main():
plugin = 'rqt_gauges_2.speedometer.Speedometer'
main = Main(filename=plugin)
sys.exit(main.main(sys.argv, standalone=plugin))


if __name__ == '__main__':
main()
8 changes: 4 additions & 4 deletions src/rqt_gauges_2/speedometer.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from qt_gui.plugin import Plugin
from .speedometer_widget import *

from .speedometer_widget import SpeedometerWidget


class Speedometer(Plugin):

def __init__(self, context):
super(Speedometer, self).__init__(context)
super().__init__(context)
self.setObjectName('Speedometer')

self._context = context
self._node = context.node

self._widget = SpeedometerWidget(self._node)
context.add_widget(self._widget)


76 changes: 41 additions & 35 deletions src/rqt_gauges_2/speedometer_gauge.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import math

from PyQt5.QtCore import QObject, QPoint, QPointF, Qt
from PyQt5.QtGui import (QColor, QConicalGradient, QFont, QFontMetrics, QPainter, QPen,
QPolygon, QPolygonF, QRadialGradient)
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QPolygon, QPolygonF, QColor, QPen, QFont, QPainter, QFontMetrics, QConicalGradient, QRadialGradient
from PyQt5.QtCore import Qt, QPoint, QPointF, QObject


class SpeedometerGauge(QWidget):
# This class creates a gauge object that contains several elements such as a needle, big and small scales
# and different circles painted with different colors to look like a car Speedometer. It has the ability to
# modify the minimum and maximum values of the gauge and the units the numbers are displaying. The class contains
# methods used to modify the values explained before, the marked number of the gauge and the whole design as well.
# This class creates a gauge object that contains several elements such as a needle,
# big and small scales and different circles painted with different colors to look like
# a car Speedometer. It has the ability to modify the minimum and maximum values of the
# gauge and the units the numbers are displaying. The class contains methods used to modify
# the values explained before, the marked number of the gauge and the whole design as well.

def __init__(self, parent=None):
# Constructor method of the class, initializes all the variables needed to create the gauge.
# Constructor method of the class, initializes all the variables needed to create
# the gauge.

super(SpeedometerGauge, self).__init__(parent)
super().__init__(parent)

# Needle Attributes
self.NeedleColor = QColor(0, 0, 0, 255)
Expand Down Expand Up @@ -50,18 +54,18 @@ def __init__(self, parent=None):

# Scale Text Attributes
self.enable_scale_text = True
self.scale_fontname = "Verdana"
self.scale_fontname = 'Verdana'
self.initial_scale_fontsize = 14
self.scale_fontsize = self.initial_scale_fontsize

# Speed Text Attributes
self.enable_value_text = True
self.value_fontname = "Verdana"
self.value_fontname = 'Verdana'
self.initial_value_fontsize = 40
self.value_fontsize = self.initial_value_fontsize
self.text_radius_factor = 0.5

self.units = ""
self.units = ''

# Gauge Attributes flags
self.enableBarGraph = True
Expand All @@ -81,11 +85,13 @@ def __init__(self, parent=None):
self.rescale_method()

def setGaugeTheme(self):
# This method defines the theme of the gauge, it is used to stablish the colors for each section of the gauge.
# This method defines the theme of the gauge, it is used to stablish the colors for each
# section of the gauge.

self.scale_polygon_colors = [[.00, Qt.red],
[.18, Qt.yellow],
[.35, Qt.green],
[1, Qt.transparent]]
[.18, Qt.yellow],
[.35, Qt.green],
[1, Qt.transparent]]

self.needle_center_bg = [
[0, QColor(35, 40, 3, 255)],
Expand All @@ -98,10 +104,9 @@ def setGaugeTheme(self):
[1, QColor(30, 40, 3, 255)]
]

self.outer_circle_bg = [
self.outer_circle_bg = [
[0, QColor(255, 255, 255, 255)],
[1, QColor(0, 0, 0, 255)]
]
[1, QColor(0, 0, 0, 255)]]

def rescale_method(self):
# This method adjust the gauge to the window size.
Expand Down Expand Up @@ -140,7 +145,7 @@ def updateValue(self, value):
self.value = value
self.update()

def setMinValue(self, min):
def setMinValue(self, min_value):
# Modifies the minimum value of the gauge
# Args:
# min: Value to update the minimum value of the gauge.
Expand All @@ -149,11 +154,11 @@ def setMinValue(self, min):
if min >= self.maxValue:
self.minValue = self.maxValue - 1
else:
self.minValue = min
self.minValue = min_value

self.update()

def setMaxValue(self, max):
def setMaxValue(self, max_value):
# Modifies the maximum value of the gauge
# Args:
# max: Value to update the maximum value of the gauge.
Expand All @@ -162,11 +167,11 @@ def setMaxValue(self, max):
if max <= self.minValue:
self.maxValue = self.minValue + 1
else:
self.maxValue = max
self.maxValue = max_value

self.update()

def create_polygon_pie(self, outer_radius, inner_radius, start, lenght, bar_graph = True):
def create_polygon_pie(self, outer_radius, inner_radius, start, length, bar_graph=True):
# Creates the outer and inner circle of the gauge. Uses the

polygon_pie = QPolygonF()
Expand All @@ -176,19 +181,20 @@ def create_polygon_pie(self, outer_radius, inner_radius, start, lenght, bar_grap
y = 0

if not self.enableBarGraph and bar_graph:
lenght = int(round((lenght / (self.maxValue - self.minValue)) * (self.value - self.minValue)))
length = int(round((length / (self.maxValue - self.minValue)) *
(self.value - self.minValue)))
pass

# Outer Circle
for i in range(lenght+1):
for i in range(length+1):
t = w * i + start - self.angle_offset
x = outer_radius * math.cos(math.radians(t))
y = outer_radius * math.sin(math.radians(t))
polygon_pie.append(QPointF(x, y))

# Inner Circle
for i in range(lenght+1):
t = w * (lenght - i) + start - self.angle_offset
for i in range(length+1):
t = w * (length - i) + start - self.angle_offset
x = inner_radius * math.cos(math.radians(t))
y = inner_radius * math.sin(math.radians(t))
polygon_pie.append(QPointF(x, y))
Expand All @@ -207,12 +213,14 @@ def draw_filled_polygon(self, outline_pen_with=0):
painter_filled_polygon.setPen(self.pen)

colored_scale_polygon = self.create_polygon_pie(
((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_outer_radius_factor,
(((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_inner_radius_factor),
((self.widget_diameter / 2) - (self.pen.width() / 2)) *
self.gauge_color_outer_radius_factor,
(((self.widget_diameter / 2) - (self.pen.width() / 2)) *
self.gauge_color_inner_radius_factor),
self.scale_angle_start_value, self.scale_angle_size)

grad = QConicalGradient(QPointF(0, 0), - self.scale_angle_size - self.scale_angle_start_value +
self.angle_offset - 1)
grad = QConicalGradient(QPointF(0, 0), - self.scale_angle_size -
self.scale_angle_start_value + self.angle_offset - 1)

for eachcolor in self.scale_polygon_colors:
grad.setColorAt(eachcolor[0], eachcolor[1])
Expand Down Expand Up @@ -275,7 +283,8 @@ def create_fine_scaled_marker(self):

my_painter.setPen(self.fineScaleColor)
my_painter.rotate(self.scale_angle_start_value - self.angle_offset)
steps_size = (float(self.scale_angle_size) / float(self.scalaCount * self.scala_subdiv_count))
steps_size = (float(self.scale_angle_size) / float(self.scalaCount
* self.scala_subdiv_count))
scale_line_outer_start = self.widget_diameter/2
scale_line_lenght = (self.widget_diameter / 2) - (self.widget_diameter / 40)
for i in range((self.scalaCount * self.scala_subdiv_count)+1):
Expand Down Expand Up @@ -329,7 +338,6 @@ def create_units_text(self):
h = fm.height()
painter.setFont(QFont(self.value_fontname, int(self.value_fontsize / 2.5), QFont.Bold))


angle_end = float(self.scale_angle_start_value + self.scale_angle_size + 180)
angle = (angle_end - self.scale_angle_start_value) / 2 + self.scale_angle_start_value

Expand All @@ -354,7 +362,6 @@ def draw_big_needle_center_point(self):
grad.setColorAt(eachcolor[0], eachcolor[1])
painter.setBrush(grad)


painter.drawPolygon(colored_scale_polygon)

def draw_outer_circle(self):
Expand All @@ -371,7 +378,6 @@ def draw_outer_circle(self):
for eachcolor in self.outer_circle_bg:
radialGradient.setColorAt(eachcolor[0], eachcolor[1])


painter.setBrush(radialGradient)

painter.drawPolygon(colored_scale_polygon)
Expand Down
Loading

0 comments on commit d5a0d10

Please sign in to comment.