Index: usrp_nbfm_ptt.py =================================================================== --- usrp_nbfm_ptt.py (Revision 7391) +++ usrp_nbfm_ptt.py (Arbeitskopie) @@ -49,7 +49,8 @@ self.frame = frame self.space_bar_pressed = False - + self.button_clicked = False + parser = OptionParser (option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B") @@ -72,7 +73,7 @@ if options.freq < 1e6: options.freq *= 1e6 - + self.txpath = transmit_path(options.tx_subdev_spec, options.audio_input) self.rxpath = receive_path(options.rx_subdev_spec, options.rx_gain, options.audio_output) self.connect(self.txpath) @@ -92,14 +93,18 @@ self.rxpath.set_enable(not(enabled)) if enabled: self.frame.SetStatusText ("Transmitter ON", 1) + self.button_tl.SetLabel ("TALK") + self.button_tl.SetValue (True) else: - self.frame.SetStatusText ("Receiver ON", 1) + self.frame.SetStatusText ("Receiver ON") + self.button_tl.SetLabel ("LISTEN") + self.button_tl.SetValue (False) def set_rx_gain(self, gain): self.myform['rx_gain'].set_value(gain) # update displayed value self.rxpath.set_gain(gain) - + def set_tx_gain(self, gain): self.txpath.set_gain(gain) @@ -125,11 +130,10 @@ def _form_set_freq(kv): return self.set_freq(kv['freq']) - + self.panel = panel - - # FIXME This REALLY needs to be replaced with a hand-crafted button - # that sends both button down and button up events + + # Title hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add((10,0), 1) self.status_msg = wx.StaticText(panel, -1, "Press Space Bar to Transmit") @@ -139,6 +143,24 @@ hbox.Add((10,0), 1) vbox.Add(hbox, 0, wx.EXPAND | wx.ALIGN_CENTER) + # Talk button + hbox = wx.BoxSizer(wx.HORIZONTAL) + hbox.Add((3,0), 1) + self.button_tl = wx.ToggleButton(panel, -1, "LISTEN") + of = self.button_tl.GetFont() + self.button_tl.SetFont(wx.Font(15, of.GetFamily(), of.GetStyle(), wx.FONTWEIGHT_BOLD)) + hbox.Add(self.button_tl, 4, wx.EXPAND) + hbox.Add((3,0), 1) + vbox.Add(hbox, 1, wx.EXPAND | wx.ALIGN_CENTER) + + hbox = wx.BoxSizer(wx.HORIZONTAL) + hbox.Add((1,0), 0) + vbox.Add(hbox, 1, wx.EXPAND | wx.ALIGN_CENTER) + + # All the event handlers needed for the button + self.button_tl.Bind(wx.EVT_LEFT_DOWN, self._on_mouse_down, self.button_tl) + self.button_tl.Bind(wx.EVT_LEFT_UP, self._on_mouse_up, self.button_tl) + panel.Bind(wx.EVT_KEY_DOWN, self._on_key_down) panel.Bind(wx.EVT_KEY_UP, self._on_key_up) panel.Bind(wx.EVT_KILL_FOCUS, self._on_kill_focus) @@ -149,14 +171,14 @@ sample_rate=self.rxpath.if_rate, ref_level=80, y_per_div=20) self.connect (self.rxpath.u, rx_fft) - vbox.Add (rx_fft.win, 1, wx.EXPAND) + vbox.Add (rx_fft.win, 4, wx.EXPAND) if 1 and not(no_gui): rx_fft = fftsink2.fft_sink_c(panel, title="Post s/w DDC", fft_size=512, sample_rate=self.rxpath.quad_rate, ref_level=80, y_per_div=20) self.connect (self.rxpath.ddc, rx_fft) - vbox.Add (rx_fft.win, 1, wx.EXPAND) + vbox.Add (rx_fft.win, 4, wx.EXPAND) if 0 and not(no_gui): foo = scopesink2.scope_sink_f(panel, title="Squelch", @@ -164,13 +186,13 @@ self.connect (self.rxpath.fmrx.div, (foo,0)) self.connect (self.rxpath.fmrx.gate, (foo,1)) self.connect (self.rxpath.fmrx.squelch_lpf, (foo,2)) - vbox.Add (foo.win, 1, wx.EXPAND) + vbox.Add (foo.win, 4, wx.EXPAND) if 0 and not(no_gui): tx_fft = fftsink2.fft_sink_c(panel, title="Tx Output", fft_size=512, sample_rate=self.txpath.usrp_rate) self.connect (self.txpath.amp, tx_fft) - vbox.Add (tx_fft.win, 1, wx.EXPAND) + vbox.Add (tx_fft.win, 4, wx.EXPAND) # add control area at the bottom @@ -246,15 +268,26 @@ def _set_status_msg(self, msg, which=0): self.frame.GetStatusBar().SetStatusText(msg, which) + def _on_mouse_down(self, evt): + if not self.space_bar_pressed: + self.button_clicked = True + self.set_transmit(True) + self.button_tl.SetValue(True) + def _on_key_down(self, evt): # print "key_down:", evt.m_keyCode - if evt.m_keyCode == wx.WXK_SPACE and not(self.space_bar_pressed): + if evt.m_keyCode == wx.WXK_SPACE and not(self.space_bar_pressed) and not(self.button_clicked): self.space_bar_pressed = True self.set_transmit(True) + def _on_mouse_up(self, evt): + if self.button_clicked: + self.button_clicked = False + self.set_transmit(False) + def _on_key_up(self, evt): # print "key_up", evt.m_keyCode - if evt.m_keyCode == wx.WXK_SPACE: + if evt.m_keyCode == wx.WXK_SPACE and not self.button_clicked: self.space_bar_pressed = False self.set_transmit(False)