Source

python-fu-matrix-transform / test.py

bworkman abd5de9 

bworkman 8d82d84 





























bworkman abd5de9 


import gtk

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()

print(response)