Commits

Anonymous committed 8d82d84

got pygtk working for basic matrix input

  • Participants
  • Parent commits abd5de9

Comments (0)

Files changed (1)

 import gtk
 
-label = gtk.Label("Nice label")
-dialog = gtk.Dialog("My dialog",
-        None,
-        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
-        (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
-        gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
-dialog.vbox.pack_start(label)
-label.show()
-checkbox = gtk.CheckButton("Useless checkbox")
-dialog.action_area.pack_end(checkbox)
-checkbox.show()
+class MatrixEntry(gtk.Dialog):
+        def __init__(self, rows, columns):
+                """
+                """
+                super(MatrixEntry, self).__init__("Matrix Transformation", None,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,gtk.STOCK_OK, gtk.RESPONSE_OK))
+
+                self.matrix = [[gtk.Entry() for j in range(columns)] for i in range(rows)]
+
+                table = gtk.Table(3, 3, False)
+                for r in range(rows):
+                        for c in range(columns):
+                                entry = self.matrix[r][c]
+                                entry.set_width_chars(5)
+                                if r <> c:
+                                        entry.set_text("0.0")
+                                else:
+                                        entry.set_text("1.0")
+                                table.attach(entry, c, c+1, r, r+1, xoptions=0, xpadding=12)
+
+                self.vbox.pack_start(table, False, False)
+
+                self.vbox.show_all()
+        def run(self):
+                result = super(MatrixEntry, self).run()
+                if result == gtk.RESPONSE_OK:
+                        return [[float(e.get_text())] for r in self.matrix for e in r]
+
+                return None
+
+dialog = MatrixEntry(3,3)
 response = dialog.run()
 dialog.destroy()