начал статью в вике
http://www.roboforum.ru/mediawiki/index.php/Python_%D0%B8_Com_Port
обсуждаем здесь
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- autor: vooon -*-
# -*- date: 2007/06/30 -*-
import pygtk
pygtk.require('2.0')
import gtk, guidef, serdef
class serialSetup:
"""реализует графическую оболочку"""
def portCallback(self, widget, data=None):
print "1# self.port = %d" % self.port
self.port = data
print "2# self.port = %d" % self.port
def baudCallback(self, widget, data=None):
print "1# self.baud = %d" % self.baud
self.baud = data
print "2# self.baud = %d" % self.baud
def okButton(self, widget, data=None):
self.ok = False
def __init__(self):
"""init"""
self.ok = True
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", lambda w: gtk.main_quit())
self.window.set_title("Terminal::Port_Option")
self.window.set_border_width(0)
box1 = gtk.VBox(False, 3)
box2 = gtk.HBox(True, 3)
#>>>--- Ok/Cancel --->>>
button1 = gtk.Button("Ok")
button1.connect('clicked', lambda w, d=None: self.window.destroy())
button2 = gtk.Button("Cancel")
button2.connect('clicked', lambda w, d=None: gtk.main_quit())
box2.pack_start(button1, True, True, 0) # Ok
box2.pack_start(button2, True, True, 0) # Cancel
button1.show()
button2.show()
box2.show()
box1.pack_end(box2, False, False, 0)
#<<<--- Ok/Cancel ---<<<
frame1 = gtk.Frame("Basics")
box1.pack_start(frame1, False, False, 0)
table1 = gtk.Table(2, 2, homogeneous = True)
#>>>--- Port list --->>>
label1 = gtk.Label("Port")
table1.attach(label1, 0, 1, 0, 1)
label1.show()
opt1 = gtk.OptionMenu()
menu1 = gtk.Menu()
for (d,s) in serdef.availPorts():
item1 = guidef.make_menu_item(s, self.portCallback, d)
menu1.append(item1)
opt1.set_menu(menu1)
menu1.activate_item
table1.attach(opt1, 1, 2, 0, 1)
opt1.show()
self.port = serdef.availPorts()[0][0]
#<<<--- Port list ---<<<
#>>>--- Baud rate list --->>>
label1 = gtk.Label("Baud")
table1.attach(label1, 0, 1, 1, 2)
label1.show()
opt1 = gtk.OptionMenu()
menu1 = gtk.Menu()
for b in serdef.availBauds():
item1 = guidef.make_menu_item("%d" % b, self.baudCallback, b)
menu1.append(item1)
opt1.set_menu(menu1)
table1.attach(opt1, 1, 2, 1, 2)
opt1.show()
self.baud = serdef.availBauds()[0]
#<<<--- Baud rate list ---<<<
frame1.add(table1)
frame1.show()
self.window.add(box1)
self.window.show_all()
def main(self):
gtk.main()
if __name__ == "__main__":
setup = serialSetup()
setup.main()
Виталий писал(а):С++ + Qt =)
Виталий писал(а):С++ + Qt
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 5