|
|||||||
![]() |
índice del forox > Soporte tecnico acerca de software > Foro general | ||
manejo del puerto paralelo con Python |
|||
| | | Versión para imprimir |
|
aztk | ||||||||
|
Chale, pss pondre este tema aquí ya que no hay un foro para 'desarrollo'. PHP Formatted Code #!/usr/bin/env python # # pparaleloaztk.py # # CopyLeft 2008 Aztk # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # IMPORTANT - To run the program you need superuser permissions # "parport" is a library from # http://pyparport.sourceforge.net/ # Thanks to the parport's developers from parport import ParallelPort import pygtk pygtk.require('2.0') import gtk p = ParallelPort(0x378) pdatax = 0 class ParalellX: # This callback write a data in parallel port def callback(self, widget, data=None): global pdatax # When the button is hold on if (widget.get_active()): pdatax = pdatax + data print "data = %s" %(pdatax) p.write(pdatax) # When the button is hold off else: pdatax = pdatax - data print "data = %s" %(pdatax) p.write(pdatax) # This callback quits the program def delete_event(self, widget, event, data=None): p.write(0) return gtk.FALSE def destroy(self, widget, data=None): p.write(0) print "data = 0" print "Good Wave" gtk.main_quit() def __init__(self): # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("ParalellX") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(20) # Create a vertical box vbox = gtk.VBox(gtk.TRUE, 2) self.window.add(vbox) # Create the data buttons (D0...D7) #D0 button = gtk.ToggleButton("D0") button.connect("toggled", self.callback, 1) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D1 button = gtk.ToggleButton("D1") button.connect("toggled", self.callback, 2) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D2 button = gtk.ToggleButton("D2") button.connect("toggled", self.callback, 4) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D3 button = gtk.ToggleButton("D3") button.connect("toggled", self.callback, 8) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D4 button = gtk.ToggleButton("D4") button.connect("toggled", self.callback, 16) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D5 button = gtk.ToggleButton("D5") button.connect("toggled", self.callback, 32) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D6 button = gtk.ToggleButton("D6") button.connect("toggled", self.callback, 64) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() #D7 button = gtk.ToggleButton("D7") button.connect("toggled", self.callback, 128) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() # Add a separator for the quitbutton separator = gtk.HSeparator() separator.set_size_request(120, 5) vbox.pack_start(separator, gtk.FALSE, gtk.TRUE, 5) separator.show() # Create "Quit" button button = gtk.Button("Quit") button.connect("clicked", self.destroy, None) vbox.pack_start(button, gtk.TRUE, gtk.TRUE, 2) button.show() # Add a label #label = gtk.Label("Aztk CopyLeft08") #label.set_alignment(0, 0) #vbox.pack_start(label, gtk.FALSE, gtk.FALSE, 0) #label.show() vbox.show() self.window.show() def main(): gtk.main() return 0 if __name__ == "__main__": ParalellX() main() # This code is inspirated in a munguis' code # Thanks munguis # http://www.pygtk.org/pygtk2tutorial-es/ # A great tuto about pygtk
El conocimiento NO! debe ser privado |
![]() Ubuntero Activo ![]() Estado: desconectado
Identificado: 10/12/08 |
||||||||
|
|||||||||
|
|
| Todas las horas son CST. Hora actual 10:26 . |
|
|