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

More tests and ci fixes #237

Merged
merged 12 commits into from
Jun 19, 2024
101 changes: 101 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,106 @@ def create_numbers(key, value, old=False, bad=False, fail=False, annunciate=Fals
fix.db.get_item("ROT").bad = False
fix.db.get_item("ROT").fail = False

fix.db.define_item(
"HIDEBUTTON",
"Hide or show buttons",
"bool",
None,
None,
'',
50000,
''
)
fix.db.set_value("HIDEBUTTON", False)
fix.db.get_item("HIDEBUTTON").bad = False
fix.db.get_item("HIDEBUTTON").fail = False

for i in range(5):
fix.db.define_item(
f"TSBTN1{i}",
f"Touch Button {i}",
"bool",
None,
None,
'',
50000,
''
)
fix.db.set_value(f"TSBTN1{i}", False)
fix.db.get_item(f"TSBTN1{i}").bad = False
fix.db.get_item(f"TSBTN1{i}").fail = False


fix.db.define_item(
"MAVREQADJ",
"",
"bool",
None,
None,
'',
50000,
''
)
fix.db.set_value("MAVREQADJ", False)
fix.db.get_item("MAVREQADJ").bad = False
fix.db.get_item("MAVREQADJ").fail = False


fix.db.define_item(
"MAVADJ",
"",
"bool",
None,
None,
'',
50000,
''
)
fix.db.set_value("MAVADJ", False)
fix.db.get_item("MAVADJ").bad = False
fix.db.get_item("MAVADJ").fail = False


fix.db.define_item(
"MAVSTATE",
"",
"str",
None,
None,
'',
50000,
''
)
fix.db.set_value("MAVSTATE", "INIT")
fix.db.get_item("MAVSTATE").bad = False
fix.db.get_item("MAVSTATE").fail = False

fix.db.define_item(
"MAVMODE",
"",
"str",
None,
None,
'',
50000,
''
)
fix.db.set_value("MAVMODE", "TRIM")
fix.db.get_item("MAVMODE").bad = False
fix.db.get_item("MAVMODE").fail = False

fix.db.define_item(
"BARO",
"",
"float",
0,
35.0,
'inHg',
50000,
''
)
fix.db.set_value("BARO", 29.92)
fix.db.get_item("BARO").bad = False
fix.db.get_item("BARO").fail = False

return fix
6 changes: 3 additions & 3 deletions src/pyefis/config/includes/ahrs/virtual_vfr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ instruments:
columns: 9
options:
text: "pyefis:"
font_mask: "pyefis:"
font_mask: "gateway:"
alignment: AlignRight
- type: value_text
disabled: VERSION_DISPLAY
Expand All @@ -312,7 +312,7 @@ instruments:
font_mask: X.X.XX
- type: static_text
disabled: VERSION_DISPLAY
row: 107
row: 107.5
column: 0
span:
rows: 2.5
Expand All @@ -323,7 +323,7 @@ instruments:
alignment: AlignRight
- type: value_text
disabled: VERSION_DISPLAY
row: 107
row: 107.5
column: 9
span:
rows: 2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ instruments:
row: 0
column: 29
span:
rows: 4
rows: 5
columns: 27
preferences: TEXT3
options:
text: "Active:"
font_mask: "XXXXXX:"
font_mask: "XXXXXXX:"
alignment: AlignLeft
- type: static_text
row: 0
Expand Down
1 change: 0 additions & 1 deletion src/pyefis/instruments/NumericalDisplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def redraw(self):
if self._bad or self._old:
prest = ""
self.pre_scroll_text.setText(prest)
print(dir(self.pre_scroll_text.text))
if not (self._bad or self._old or self._fail):
self.scrolling_area.value = scroll_value

Expand Down
3 changes: 1 addition & 2 deletions src/pyefis/instruments/airspeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ def __init__(
def resizeEvent(self, event):
if self.font_percent:
self.fontsize = qRound(self.width() * self.font_percent)
self.pph = qRound(self.fontsize * 0.4)

self.pph = self.height() / 100
w = self.width()
h = self.height()
self.markWidth = w / 5
Expand Down
4 changes: 1 addition & 3 deletions src/pyefis/instruments/altimeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ def __init__(
def resizeEvent(self, event):
if self.font_percent:
self.fontsize = qRound(self.width() * self.font_percent)
self.pph = self.fontsize / (self.height() / 20)

self.pph = self.height() / 1000
w = self.width()
w_2 = w / 2
h = self.height()
Expand All @@ -281,7 +280,6 @@ def resizeEvent(self, event):
self.height_pixel = (
self.maxalt * 2 * self.pph + h
) # + abs(self.minalt*self.pph)

dialPen = QPen(QColor(Qt.white))
dialPen.setWidth(int(self.height() * 0.005))

Expand Down
2 changes: 1 addition & 1 deletion src/pyefis/instruments/gauges/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def resizeEvent(self, event):
self.font_size = self.height()

if self.font_mask:
self.font_size = helpers.fit_to_mask(self.width(),self.height(),self.font_mask,self.font_family,self.units_font_mask,self.small_font_percent)
self.font_size = helpers.fit_to_mask(self.width(),self.height(),self.font_mask,self.font_family,self.units_font_mask,self.small_font_percent,True)
self.bigFont = QFont(self.font_family)
self.bigFont.setPointSizeF(self.font_size)
self.smallFont = QFont(self.font_family)
Expand Down
91 changes: 38 additions & 53 deletions src/pyefis/instruments/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,47 @@
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *

def fit_to_mask(iwidth,iheight,mask,font,units_mask=None, units_ratio=0.8):

# Could not get font metrics to work perfectly
# Seems like text it rendered starting slightly to the right
# rsulting in the right side of the text getting cut off
# Fitting to a slightly smaller width and height
# seems to resolve the issue.
width = iwidth * 0.95
height = iheight * 0.96
font_size = height
text_font = QFont(font, int(font_size))
units_font = QFont(font, int(font_size * units_ratio))
fm = QFontMetrics(text_font)
text_width = fm.tightBoundingRect(mask).width()
text_height = fm.tightBoundingRect(mask).height()
units_width = 0
units_height = 0
if units_mask:
fmu = QFontMetrics(units_font)
units_width = fmu.tightBoundingRect(units_mask).width()
units_height = fmu.tightBoundingRect(units_mask).height()

# IF needed, shrink until it fits
while ( (text_width + units_width > width) or text_height > height ) and font_size > 0.5:
font_size -= 0.2
text_font.setPointSizeF(font_size)
fm = QFontMetrics(text_font)
text_width = fm.tightBoundingRect(mask).width()
text_height = fm.tightBoundingRect(mask).height()
if units_mask:
units_font.setPointSizeF(font_size * units_ratio)
fmu = QFontMetrics(units_font)
units_width = fmu.tightBoundingRect(units_mask).width()
units_height = fmu.tightBoundingRect(units_mask).height()
# If needed, grow until it fills
while (text_width + units_width < width) and text_height < height:
font_size += 0.2
def fit_to_mask(width,height,mask,font,units_mask=None, units_ratio=0.8, numeric=False):
font_size = 100
error = 100
minerror = 100
goal = 0.02
count = 0
while ( error > goal):
count += 1
text_font = QFont(font)
text_font.setPointSizeF(font_size)
fm = QFontMetrics(text_font)
text_width = fm.tightBoundingRect(mask).width()
text_height = fm.tightBoundingRect(mask).height()
fm = QFontMetricsF(text_font)
text_width = fm.horizontalAdvance(mask)
if numeric:
text_height = fm.tightBoundingRect(mask).height()
else:
text_height = fm.boundingRect(mask).height()
units_width = 0
units_height = 0
if units_mask:
units_font = QFont(font)
units_font.setPointSizeF(font_size * units_ratio)
fmu = QFontMetrics(units_font)
units_width = fmu.tightBoundingRect(units_mask).width()
units_height = fmu.tightBoundingRect(units_mask).height()

font_size -= 0.2

# The above took care of the width, this addresses the height:
while (text_height >= height) and font_size > 0.5:
font_size -= 0.2
text_font.setPointSizeF(font_size)
fm = QFontMetrics(text_font)
text_width = fm.tightBoundingRect(mask).width()
fmu = QFontMetricsF(units_font)
units_width = fmu.horizontalAdvance(units_mask)
hfactor = height / text_height
wfactor = width / ( text_width + units_width)
if hfactor < 1 and wfactor < 1:
factor = min(hfactor, wfactor)
elif hfactor > 1 and wfactor > 1:
factor = max(hfactor,wfactor)
elif hfactor < 1 and wfactor > 1:
factor = hfactor
else:
factor = wfactor
error = abs(factor - 1)
if factor > 1:
if error < minerror:
minerror = error
else:
break
font_size = font_size * factor
return font_size

return(font_size)


2 changes: 2 additions & 0 deletions src/pyefis/instruments/listbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, parent=None, lists=[], replace=None, font_family="DejaVu Sans

self.active_list = list(self.tlists.keys())[0]
self.header = misc.StaticText(text=self.active_list, color=QColor(Qt.white), parent=self)
self.header.font_mask = self.active_list
self.selected_row = 0
self.columns = len(self.tlists[self.active_list]['display']['columns'])
self.rows = len(self.tlists[self.active_list]['list'])
Expand Down Expand Up @@ -196,6 +197,7 @@ def loadList(self):
self.table.setRowCount(0)
self.header.hide()
self.header.text = self.active_list
self.header.font_mask = self.active_list
self.header.show()

self.column_names = [ item['name'] for item in self.tlists[self.active_list]['display']['columns'] ]
Expand Down
13 changes: 13 additions & 0 deletions tests/data/buttons/repeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: repeat
text: "+"
dbkey: TSBTN{id}3
transparent: true
# If repeats too fast can cause VARO set loops
# This is more of an issue when the variable, BARO in this case, is ued
# by the compute plugin in Fix Gateway
repeat_interval: 200
repeat_delay: 500
conditions:
- when: "CLICKED eq true"
actions:
- change value: "BARO, 0.01"
30 changes: 30 additions & 0 deletions tests/data/buttons/simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type: simple
text: "Units"
dbkey: TSBTN{id}0
hover_show: True
condition_keys:
- HIDEBUTTON
conditions:
- when: "HIDEBUTTON"
actions:
#- button: disable
- set text: "Show\nMenu"
#- set bg color: "#00000000"
#- set fg color: "#00000000"
continue: true
- when: "not HIDEBUTTON"
actions:
#- button: enable
- set text: "Units"
#- set bg color: lightgray
#- set fg color: black
continue: true
- when: "CLICKED eq true and HIDEBUTTON"
actions:
- set text: Units
- set value: HIDEBUTTON,False
- when: "CLICKED eq true and not HIDEBUTTON"
actions:
- Set Instrument Units: "OAT,OILT1,Temperature,Pressure,Altitude:Toggle"
- set value: HIDEBUTTON,False

37 changes: 37 additions & 0 deletions tests/data/buttons/toggle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type: toggle
text: "AP\nAdjust"
dbkey: TSBTN{id}2
condition_keys:
- MAVMODE
- MAVSTATE
- MAVADJ
conditions:
- when: "MAVMODE eq 'TRIM'"
actions:
- button: disable
- set bg color: "#5d5b59"
- button: unchecked
# Maybethis should be done in the mavlink plugin?
- set value: MAVREQADJ, false
- when: "CLICKED eq true and DBKEY eq false and MAVMODE ne 'TRIM'"
actions:
- set bg color: yellow
- set value: MAVREQADJ, false
- when: "CLICKED eq true and DBKEY eq true and MAVMODE ne 'TRIM'"
actions:
- set bg color: yellow
- set value: MAVREQADJ, true
- when: "MAVSTATE eq 'ARMED' and MAVMODE ne 'TRIM' and MAVADJ eq true"
actions:
- set bg color: green
- button: checked
- button: enabled
continue: true
- when: "MAVSTATE eq 'ARMED' and MAVMODE ne 'TRIM' and MAVADJ eq false"
actions:
- set bg color: lightgray
- button: unchecked
- button: enable
continue: true


Empty file.
Loading
Loading