Description: Add the demod bandpass filter shadow.
Author: Terry, WB4JFI
Last-Update: 2012-01-25
Reviewed-By: A. Maitland Bottoms <bottoms@debian.org>

--- a/quisk.py
+++ b/quisk.py
@@ -7,6 +7,11 @@
 
 """The main program for Quisk, a software defined radio.
 
+# NOTE:  THIS FILE HAD BEEN MODIFIED BY WB4JFI TO ADD A FILTER SHADOW
+	#			ON THE DISPLAY TO INDICATE FILTER BANDWIDTH.  LINES WITH
+	#			"WB4JFI" IN THE COMMENTS HAVE BEEN ADDED TO James
+	#			Ahlstrom's ORIGINAL CODE.  DO NOT bug HIM ABOUT IT!!
+
 Usage:  python quisk.py [-c | --config config_file_path]
 This can also be installed as a package and run as quisk.main().
 """
@@ -422,6 +427,12 @@
     self.max_height = application.screen_height
     self.tuningPenTx = wx.Pen('Red', 1)
     self.tuningPenRx = wx.Pen('Green', 1)
+    self.fltrPen = wx.Pen(conf.color_bandwidth, 1)				# WB4JFI ADD filter shadow
+    self.fltrBrush = wx.Brush(conf.color_bandwidth, wx.SOLID)	# WB4JFI ADD filter shadow 
+    self.fltr_disp_start = -100									# WB4JFI ADD filter shadow
+    self.fltr_disp_size = 100									# WB4JFI ADD filter shadow
+    self.fltr_disp_fill = -99									# WB4JFI ADD filter shadow
+    self.fltr_disp_show = 0										# WB4JFI ADD filter shadow
     self.backgroundPen = wx.Pen(self.GetBackgroundColour(), 1)
     self.horizPen = wx.Pen(conf.color_gl, 1, wx.SOLID)
     if sys.platform == 'win32':
@@ -432,9 +443,17 @@
   def OnPaint(self, event):
     #print 'GraphDisplay', self.GetUpdateRegion().GetBox()
     dc = wx.PaintDC(self)
+    x = self.tune_tx									# setx x to tune freq horizontal position (WB4JFI MOVED)
+    self.UpdateFilterDisplay()									# WB4JFI ADD filter shadow
+    if self.fltr_disp_show == 3:								# WB4JFI ADD filter shadow
+        dc.SetPen(self.fltrPen)									# WB4JFI ADD filter shadow
+        dc.SetBrush(self.fltrBrush)								# WB4JFI ADD filter shadow
+        dc.DrawRectangle(x + self.fltr_disp_start, 0,			# WB4JFI ADD filter shadow
+            self.fltr_disp_size, self.max_height)				# WB4JFI ADD filter shadow
+        dc.FloodFill(x + self.fltr_disp_fill, 1, conf.color_bandwidth, 1) # WB4JFI ADD filter shadow
     dc.SetPen(wx.BLACK_PEN)
     dc.DrawLines(self.line)
-    x = self.tune_tx
+    #x = self.tune_tx											# WB4JFI moved to above
     dc.SetPen(self.tuningPenTx)
     dc.DrawLine(x, 0, x, self.max_height)
     if self.tune_rx:
@@ -487,6 +506,31 @@
     self.y_max = y_max
     self.line = line
     self.Refresh() #rect=rect)
+  def UpdateFilterDisplay(self):							# WB4JFI ADD - Update filter display
+    if application.fltr_display:							# WB4JFI, check if OK to display filter
+      self.fltr_disp_show = self.fltr_disp_show | 1			# set bit 0, show OK from OUTSIDE
+    else:													# otherwise, OUTSIDE don't display
+      self.fltr_disp_show = self.fltr_disp_show & 2			# by clearing bit 0
+    if application.screen == application.graph or application.screen == application.waterfall:
+      self.fltr_disp_show = self.fltr_disp_show | 2			# bit 1 shows proper screen to display
+    else:
+      self.fltr_disp_show = self.fltr_disp_show & 1			# clear bit 1 to indicate not proper display
+    self.filter_pixels = ((application.filterbw / application.zoom) / (application.sample_rate /application.data_width) + 0.5)
+    if self.filter_pixels < 2:								# if calculated less than 2 pixels
+      self.filter_pixels = 2									# make it at least 2 pixels wide
+    if application.mode == 'LSB' or application.mode == 'CWL':	# if filter on lower sideband...
+      self.fltr_disp_start = -(self.filter_pixels - 1)			# set start to be at lower side
+      self.fltr_disp_size = self.filter_pixels					# and set rectangle size
+      self.fltr_disp_fill = self.fltr_disp_start				# start filling at rectangle start
+    if application.mode == 'USB' or application.mode == 'CWU':	# if filter on upper sideband...
+      self.fltr_disp_start = 0									# start is at tuning freq
+      self.fltr_disp_size = self.filter_pixels					# set rectangle size
+      self.fltr_disp_fill = 1									# start filling at beginning of tune
+    if application.mode == 'AM' or application.mode == 'FM':	# if filter is centered at tune freq
+      self.fltr_disp_start = -((self.filter_pixels - 1) /2)		# set start at 1/2 bandidth
+      self.fltr_disp_size = self.filter_pixels					# set size to cover both sidebands
+      self.fltr_disp_fill = self.filter_pixels					# start filling at lower edge
+	#															# WB4JFI - end of filter add
   def SetTuningLine(self, tune_tx, tune_rx):
     dc = wx.ClientDC(self)
     dc.SetPen(self.backgroundPen)
@@ -1480,6 +1524,8 @@
     self.zoom_deltaf = 0
     self.zooming = False
     self.split_rxtx = False	# Are we in split Rx/Tx mode?
+    self.filterbw = 0								# WB4JFI Added for filter display
+    self.fltr_display = conf.filter_display			# WB4JFI added filter display 1=OK, 0=do not display
     self.savedState = {}
     self.pttButton = None
     # get the screen size - thanks to Lucian Langa
@@ -2048,6 +2094,8 @@
     else:		# called by button
       btn = event.GetEventObject()
       bw = int(btn.GetLabel())
+    self.filterbw = int(self.filterButns.GetLabel())		# WB4JFI ADD - udate filter bandwidth
+    application.graph.display.UpdateFilterDisplay()			# WB4JFI ADD - update the filter disp
     mode = self.mode
     if mode in ("CWL", "CWU"):
       N = 1000
@@ -2074,12 +2122,14 @@
       self.screen = self.graph
       self.screen.SetTxFreq(self.txFreq, self.rxFreq)
       self.freqDisplay.Display(self.VFO + self.txFreq)
+      application.graph.display.UpdateFilterDisplay()	# WB4JFI ADD - update the filter disp
       self.screen.PeakHold(name)
     elif name == 'WFall':
       self.screen = self.waterfall
       self.screen.SetTxFreq(self.txFreq, self.rxFreq)
       self.freqDisplay.Display(self.VFO + self.txFreq)
       sash = self.screen.GetSashPosition()
+      application.graph.display.UpdateFilterDisplay()	# WB4JFI ADD - update the filter disp
     elif name == 'Scope':
       if win.direction:				# Another push on the same button
         self.scope.running = 1 - self.scope.running		# Toggle run state
@@ -2367,6 +2417,7 @@
       self.SetRit(0)
       self.MakeFilterButtons(conf.FilterBwEXT)
       self.OnBtnFilter(None, 12000)
+    application.graph.display.UpdateFilterDisplay()		# WB4JFI ADD - update the filter disp
   def OnBtnBand(self, event):
     band = self.lastBand	# former band in use
     try:
--- a/quisk_conf_defaults.py
+++ b/quisk_conf_defaults.py
@@ -66,6 +66,7 @@
 scope_y_zero  = 0		# Currently doesn't do anything
 filter_y_scale = 90
 filter_y_zero  = 0
+filter_display = 0
 
 # Quisk can save its current state in a file on exit, and restore it when you restart.
 # State includes band, frequency and mode, but not every item of state (not screen).
@@ -93,6 +94,7 @@
 color_freq		= 'lightcyan1'			# background color of frequency and s-meter
 color_entry		= color_freq			# frequency entry box
 color_disable	= 'white'				# text color for a disabled button
+color_bandwidth	= 'lemonchiffon2'		# audio bandwidth on spectrum display # WB4JFI ADD filter shadow
 
 # These are the palettes for the waterfall.  The one used is named waterfallPallette,
 # so to use a different one, overwrite this name in your .quisk_conf.py.
