coding utf-8 import pygtk pygtk require import gtk class Place def __i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
import pygtk; pygtk.require('2.0')
import gtk
class Place:
def __init__(self,widget):
self.widget = widget
def __ror__(self, other):
vbox = gtk.VBox()
vbox.pack_start(other.widget, True, True, 0)
vbox.pack_start(self.widget, True, True, 0)
return Place(widget=vbox)
def __add__(self, other):
vbox = gtk.HBox()
vbox.pack_start(self.widget, True, True, 0)
vbox.pack_start(other.widget, True, True, 0)
return Place(widget=vbox)
@classmethod
def TextEntry(cls):
return Place(widget = gtk.Entry())
@classmethod
def Label(cls, message=None):
return Place(gtk.Label(message))
@classmethod
def OKCancel(cls):
bbox = gtk.HButtonBox()
bbox.add(gtk.Button(stock=gtk.STOCK_OK))
bbox.add(gtk.Button(stock=gtk.STOCK_CANCEL))
return Place(bbox)
class Field:
@classmethod
def TextEntry(cls, name="text_entry"):
return Place.Label(name) + Place.TextEntry()
class SampleForm:
login = Field.TextEntry(u'имя')
password = Field.TextEntry(u'пароль')
layout = login + password | Place.OKCancel()
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.add(SampleForm.layout.widget)
window.show_all()
if __name__ == '__main__':
SampleForm()
gtk.main()