Skip to content

Overlay window with gearing info #456

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

Closed
wants to merge 2 commits into from
Closed
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
93 changes: 84 additions & 9 deletions pythoncode/FortiusAntGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Version info
#-------------------------------------------------------------------------------
__version__ = "2022-01-05"
# 2024-01-24 Addition of an overlay window with gearing info
# 2022-01-05 MinHeigth/MinWidth replaced by Size() for consistency
# 2022-01-04 text-fields on top of other controls were flickering, because
# the parent was not the on-top control #353
Expand Down Expand Up @@ -158,7 +159,12 @@ class frmFortiusAntGui(wx.Frame):
StatusLedsXr = None # Right side of rightmost status-led-label
StatusLedsYb = None # Bottom of status-led-row


def __init__(self, parent, pclv):
self.child = ChildFrame(self)

#self.child.Show(True)

# ----------------------------------------------------------------------
# Create frame and panel for TAB-handling
# (First versions did not use panel, and that's why TABs did not work)
Expand Down Expand Up @@ -474,8 +480,8 @@ def __init__(self, parent, pclv):
# Assign A Font To The Center Text

Min = 0
NrIntervals = 10
Step = 40
NrIntervals = 12
Step = 50
Max = Min + Step * NrIntervals
self.PowerMax = Max
self.PowerArray = numpy.array([0,0,0,0,0,0,0,0,0,0]) # Array for running everage
Expand All @@ -489,7 +495,7 @@ def __init__(self, parent, pclv):
ticks = [str(interval) for interval in intervals] # Assign The Ticks: Here They Are Simply The String Equivalent Of The Intervals
self.Power.SetTicks(ticks)
self.Power.SetTicksColour(wx.WHITE) # Set The Ticks/Tick Markers Colour
self.Power.SetNumberOfSecondaryTicks(5) # We Want To Draw 5 Secondary Ticks Between The Principal Ticks
self.Power.SetNumberOfSecondaryTicks(4) # We Want To Draw 5 Secondary Ticks Between The Principal Ticks

self.Power.SetTicksFont(wx.Font(TicksFontSize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
# Set The Font For The Ticks Markers
Expand Down Expand Up @@ -663,6 +669,13 @@ def __init__(self, parent, pclv):
self.btnStop.SetPosition((ButtonX, self.btnStart.Position[1] + self.btnStart.Size[1] + Margin))
self.btnStop.Disable()
self.Bind(wx.EVT_BUTTON, self.OnClick_btnStop, self.btnStop)

#Button to show/hide an overlay window with info on gearing
self.btnOverlay = wx.ToggleButton(self.panel, label="Overlay", size=(ButtonW, -1))
self.btnOverlay.SetToolTip ("Show Overlay")
self.btnOverlay.SetPosition((ButtonX, self.btnStop.Position[1] + self.btnStop.Size[1] + Margin))
self.btnOverlay.Enable()
self.Bind(wx.EVT_TOGGLEBUTTON, self.OnClick_btnOverlay, self.btnOverlay)

b = wx.Image(sponsor_bmp) # Must fit, no rescale
b = wx.Bitmap(b)
Expand Down Expand Up @@ -886,10 +899,11 @@ def SetValues(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTargetGra
iTacx, iHeartRate, \
iCrancksetIndex, iCassetteIndex, fReduction)


def SetValuesGUI(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTargetGrade, \
iTacx, iHeartRate, \
iCrancksetIndex, iCassetteIndex, fReduction):

# ----------------------------------------------------------------------
# When zero, display default setting
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -973,7 +987,7 @@ def SetValuesGUI(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTarget
if iTacx == 0:
self.txtTacx.SetValue ("")
else:
self.txtTacx.SetValue ("%i" % iTacx + suffix)
self.txtTacx.SetValue ("%.1f" % fReduction + suffix)
fTargetPower = "%iW"
else:
if self.clv.imperial:
Expand All @@ -989,18 +1003,18 @@ def SetValuesGUI(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTarget
self.txtTarget.SetValue(fTargetPower % iTargetPower + suffix)

elif iTargetMode == mode_Grade:
s = "%2.0f%%" % fTargetGrade
s = "%.1f%%" % fTargetGrade
s += "%iW" % iTargetPower # Target power added for reference
# Can be negative!
self.txtTarget.SetValue(s + suffix)

else:
self.txtTarget.SetValue("No target" + suffix)
self.txtTarget.SetValue("No target"+ suffix)

if logfile.IsOpen() and debug.on(debug.Data1 | debug.Data2):
Elapsed = time.time() - self.LastFields
logfile.Write ("SetValues() done in %s ms" % int(Elapsed*1000))

# ----------------------------------------------------------------------
# If there is a HeartRate, bounce the image
# We pass here every 0.250 second = 400 times/minute
Expand Down Expand Up @@ -1057,6 +1071,9 @@ def SetValuesGUI(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTarget
self.txtCranckset.Show()

self.txtCranckset.SetValue ("%i" % self.clv.Cranckset[self.CrancksetIndex])
# send info also to child window
self.child.txtCranckset.SetValue ("%i" % self.clv.Cranckset[self.CrancksetIndex])

bRefreshRequired = True # So that Cranckset is painted

else:
Expand All @@ -1076,6 +1093,8 @@ def SetValuesGUI(self, fSpeed, iRevs, iPower, iTargetMode, iTargetPower, fTarget
teeth = self.clv.Cassette[self.CassetteIndex]

self.txtCassette.SetValue ("%i" % int(round(teeth / self.Reduction) ) )
# send info also to child window
self.child.txtCassette.SetValue ("%i" % int(round(teeth / self.Reduction) ) )
bRefreshRequired = True # So that Cassette is painted

else:
Expand Down Expand Up @@ -1470,6 +1489,27 @@ def OnClick_btnStop(self, event=False):
if __name__ == "__main__": print ("OnClick_btnStop()")
self.RunningSwitch = False
self.btnStop.Disable()

# --------------------------------------------------------------------------
# O n C l i c k _ b t n Overlay
# --------------------------------------------------------------------------
# input: [Overlay] pressed
#
# Description: Displays/Hides Overlay Window with Gearing Info
#
# Output: None
# --------------------------------------------------------------------------
def OnClick_btnOverlay(self, event=False):
if __name__ == "__main__": print ("OnClick_btnOverlay()")
state = event.GetEventObject().GetValue()
if state == True:
self.child.Show()
self.btnOverlay.SetToolTip ("Hide Overlay")
else:
self.child.Hide()
self.btnOverlay.SetToolTip ("Show Overlay")



# --------------------------------------------------------------------------
# O n C l i c k _ b t n S p o n s o r
Expand Down Expand Up @@ -1530,6 +1570,42 @@ def OnClose(self, event):
else: # No thread is running;
event.Skip() # Do default actions (stop program)


# --------------------------------------------------------------------------
# Overlay window
# --------------------------------------------------------------------------
# Child window with info on gearing.
# Semi-transparent and always-on-top
# Meant to be overlayed to the CTP window to keep track of the virtual gearing
# --------------------------------------------------------------------------

class ChildFrame(wx.Frame):
def __init__(self, parent):
style = (wx.CAPTION | wx.STAY_ON_TOP | wx.FRAME_TOOL_WINDOW)
wx.Frame.__init__(self, None, title='Overlay', size = (120,150), style = style)
self.SetTransparent( 140 )
TextCtrlFont = wx.Font(36, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
# ----------------------------------------------------------------------
# self.Cranckset, shown to the right of the Cranckset image
# ----------------------------------------------------------------------
self.txtCranckset = wx.TextCtrl(self, value="--", size=(80,50), style=wx.TE_CENTER | wx.TE_READONLY)
self.txtCranckset.SetBackgroundColour(bg)
self.txtCranckset.SetPosition(( 10, 5))

# ----------------------------------------------------------------------
# self.Cassette, shown to the right of the Cassette image
# ----------------------------------------------------------------------
self.txtCassette = wx.TextCtrl(self, value="--", size=(80,50), style=wx.TE_CENTER | wx.TE_READONLY)
self.txtCassette.SetBackgroundColour(bg)
self.txtCassette.SetPosition(( 10, 60))

self.txtCranckset.SetFont(TextCtrlFont)
self.txtCassette.SetFont(TextCtrlFont)





# ------------------------------------------------------------------------------
# our normal wxApp-derived class, as usual
# ------------------------------------------------------------------------------
Expand All @@ -1541,5 +1617,4 @@ def OnClose(self, event):
app.SetTopWindow(frame)
frame.Show()
frame.Autostart()

app.MainLoop()