SHARE
TWEET

Untitled

a guest May 30th, 2016 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import serial
  4. import time
  5. from datetime import datetime
  6.  
  7. import gi
  8. gi.require_version('Gtk', '3.0')
  9. from gi.repository import Gtk
  10.  
  11. from threading import Thread
  12.  
  13.  
  14. class MyWindow(Gtk.Window):
  15.  
  16.     txmode = 1
  17.     message = ""
  18.     freq = ""
  19.  
  20.    
  21.  
  22.     def __init__(self):
  23.  
  24.         self.ser = serial.Serial("/dev/ttyUSB0", 9600)
  25.  
  26.         Gtk.Window.__init__(self, title="JT GUI by SQ3SWF")
  27.  
  28.         vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
  29.         self.add(vbox)
  30.  
  31.         label = Gtk.Label("Message:");
  32.         vbox.pack_start(label, True, True, 0)
  33.  
  34.         self.entry_msg = Gtk.Entry()
  35.         self.entry_msg.set_text("cq dx")
  36.         vbox.pack_start(self.entry_msg, True, True, 0)
  37.  
  38.         label = Gtk.Label("Frequency:");
  39.         vbox.pack_start(label, True, True, 0)
  40.  
  41.         self.entry_freq = Gtk.Entry()
  42.         self.entry_freq.set_text("500")
  43.         vbox.pack_start(self.entry_freq, True, True, 0)
  44.  
  45.         hbox = Gtk.Box(spacing=6)
  46.         vbox.add(hbox)
  47.  
  48.         button1 = Gtk.RadioButton.new_with_label_from_widget(None, "JT65")
  49.         button1.connect("toggled", self.on_button_toggled, "JT65")
  50.         hbox.pack_start(button1, False, False, 0)
  51.  
  52.         button2 = Gtk.RadioButton.new_from_widget(button1)
  53.         button2.set_label("JT9")
  54.         button2.connect("toggled", self.on_button_toggled, "JT9")
  55.         hbox.pack_start(button2, False, False, 0)
  56.  
  57.         self.button = Gtk.Button(label="Enable TX")
  58.         self.button.connect("clicked", self.startTX)
  59.         self.set_size_request(200, 200)
  60.  
  61.         vbox.add(self.button)
  62.  
  63.     def on_button_toggled(self, button, name):
  64.         if name == "JT65" and button.get_active() == True:
  65.             self.txmode = 1
  66.         if name == "JT9" and button.get_active() == True:
  67.             self.txmode = 2
  68.    
  69.         print "TX mode =", self.txmode
  70.  
  71.     def startTX(self, widget):
  72.         self.message = self.entry_msg.get_text()
  73.         self.freq = self.entry_freq.get_text()
  74.         txmsg = str(self.txmode) + "\n" + self.message + "\n" + self.freq + "\n"
  75.         print txmsg
  76.         thread = Thread(target = self.waitAndTransmit, args = (txmsg, ))
  77.         thread.start()
  78.  
  79.  
  80.     def waitAndTransmit(self, command):
  81.         if datetime.now().second > 5:
  82.             time.sleep(60-datetime.now().second)
  83.  
  84.         print command
  85.         self.ser.write(command)
  86.            
  87.  
  88.  
  89.  
  90. win = MyWindow()
  91. win.connect("delete-event", Gtk.main_quit)
  92. win.show_all()
  93.  
  94.  
  95. Gtk.main()
  96.  
  97. print "byebye"
  98. win.ser.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top