Commits

Virgil Dupras committed 39f81b0

Added gtk (trhough PyGObject) UI layer.

Comments (0)

Files changed (7)

  - ObjP from http://bitbucket.org/hsoft/objp
 tk:
  - None
+gtk:
+ - PyGObject 3.0
 
 NOTES
 
 
 I lied to you, it's not all GUI supported by Python that are included here, just a few, but that's
 because I don't know them all! Please, feel free to contribute your own skeleton project! Repository
-is at http://bitbucket.org/hsoft/guiskel
+is at http://bitbucket.org/hsoft/guiskel
 import os.path as op
 import shutil
 
-PROJNAMES = ['qt', 'cocoa', 'tk']
+PROJNAMES = ['qt', 'cocoa', 'tk', 'gtk']
 
 def build_cocoa():
     import objp.o2p

gtk/__init__.py

Empty file added.
+from .textholder import TextHolder
+
+class LineEdit(TextHolder):
+    def __init__(self, view):
+        TextHolder.__init__(self, view)
+        self.view.connect('changed', self.handleTextEdited)
+    
+    def handleTextEdited(self, widget):
+        self.model.text = self.view.get_text()
+    

gtk/mainwindow.py

+from gi.repository import Gtk
+
+from core.mainwindow import MainWindow as MainWindowModel
+from .textholder import TextHolder
+from .lineedit import LineEdit
+
+class MainWindow(Gtk.Window):
+    def __init__(self):
+        Gtk.Window.__init__(self, title="guiskel")
+        self._setupUi()
+        self.model = MainWindowModel()
+        self.nameEntry = LineEdit(view=self.nameEntryView)
+        self.helloLabel = TextHolder(view=self.helloLabelView)
+        self.model.set_children(self.nameEntry.model, self.helloLabel.model)
+        self.randomNameButton.connect('clicked', self.randomNameButtonClicked)
+        self.sayHelloButton.connect('clicked', self.sayHelloButtonClicked)
+        self.connect('delete-event', Gtk.main_quit)
+    
+    def _setupUi(self):
+        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+        self.add(self.box)
+        self.nameEntryView = Gtk.Entry()
+        self.box.pack_start(self.nameEntryView, False, False, 0)
+        self.helloLabelView = Gtk.Label()
+        self.box.pack_start(self.helloLabelView, False, False, 0)
+        self.buttonBox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
+        self.randomNameButton = Gtk.Button(label="Random Name")
+        self.sayHelloButton = Gtk.Button(label="Say Hello")
+        self.buttonBox.pack_end(self.sayHelloButton, False, False, 0)
+        self.buttonBox.pack_end(self.randomNameButton, False, False, 0)
+        self.box.pack_start(self.buttonBox, False, False, 0)
+    
+    def randomNameButtonClicked(self, widget):
+        self.model.select_random_name()
+    
+    def sayHelloButtonClicked(self, widget):
+        self.model.say_hello()
+

gtk/runtemplate.py

+import sys
+
+from gi.repository import Gtk
+from gtk.mainwindow import MainWindow
+
+def main(argv):
+    mw = MainWindow()
+    mw.show_all()
+    return Gtk.main()
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))

gtk/textholder.py

+from core.textholder import TextHolder as TextHolderModel
+
+class TextHolder:
+    def __init__(self, view):
+        self.view = view
+        self.model = TextHolderModel(view=self)
+    
+    #--- model --> view
+    def update_text(self):
+        text = self.model.text
+        if text != self.view.get_text():
+            self.view.set_text(text)
+