TOP
SSV Software Systems Register  Register
Log in to check your private messages  Log in to check your private messages
Startseite FAQ Search Mitglieder Profile  Log in 
SSV Support-Forum
Python und GTK …

 
Post new topic   Reply to topic    SSV-Forum Forum Index >>> eSOM/2x86
<<< Previous topic - Next topic >>>  
Display posts from previous:   
Author Message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 28.09.2012, 15:34    Post subject: Python und GTK … Reply with quote

Hallo Forum.

Für den eSOM/2586 ist jetzt auch eine Python/GTK-Implementierung verfügbar. Damit lassen sich sehr einfach recht anspruchsvolle graphische Benutzeroberflächen realisieren, die darüber hinaus auch noch Plattformunabhängig sind. Hier der Quellcode für ein „Hallo Welt“:

Code:
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class HelloWorld:
   def destroy(self, widget, data=None):
      gtk.main_quit()

   def __init__(self):
      self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
      self.window.set_size_request(640, 480)
      self.window.connect("destroy", self.destroy)
      self.button=gtk.Button("Hello World")
      self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
      self.window.add(self.button)
      self.button.show()
      self.window.show()

   def main(self):
      gtk.main()

if __name__ == "__main__":
   hello = HelloWorld()
   hello.main()


Der Code erzeugt in der Mitte eines VGA-LCDs (siehe self.window.set_size_request(640, 480)) eine „Hallo Welt“-Meldung und wartet auf die ENTER-Taste.

Wenn Sie diesen Code einmal ausprobieren wollen, erzeugen Sie einfach auf Ihrem Entwicklungs-PC eine entsprechende Datei „hello.py“. Achten Sie auf die Besonderheiten von Python (Code muss entsprechend eingerückt werden usw.). Am besten ist, Sie verwenden gleich einen Editor mit einem Syntax-Highlighter (auf einem Windows-PC zum Beispiel PSPad). Erzeugen Sie dann eine FTP-Session als Benutzer user (Passwort user) auf dem eSOM/2586 und übertragen Sie die Datei in das Verzeichnis /home/user. Starten Sie dann innerhalb einer Telnet-Session (Benutzer user, Passwort user) das Beispiel durch die folgende Eingabe:

Code:
DISPLAY=“:0“ python hello.py


Weitere Infos zu Python/GTK findet man unter http://pygtk.org/

Ein Python Videotutorial gibt es unter http://www.youtube.com/watch?v=MxYl3cnn4yw

Gruß KDW
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SSV-Forum Forum Index >>> eSOM/2x86 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

SSV Software Systems GmbH

Dünenweg 5
30419 Hannover

Fon: +49(0)511  ·  40 000-0
Fax: +49(0)511  ·  40 000-40

sales@ssv-embedded.de


Impressum    ·    Datenschutz    ·    AGB

© 2023 SSV SOFTWARE SYSTEMS GmbH. Alle Rechte vorbehalten.

ISO 9001:2015