class RoomsTable gtk Table def __init__ self db images_directory gtk T

  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
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
class RoomsTable(gtk.Table):
def __init__(self, db, images_directory):
gtk.Table.__init__(self)
self.widgets = []
self.IMAGES_DIRECTORY = images_directory
self.db = db
def attach_rooms_rows(self, row):
self.rooms = self.db.select_rooms()
if self.rooms:
j = 0
for i in self.rooms:
self.widgets.append(
{
"id": i[0],
"type": "room",
"places": int(i[2]),
"tooltip": """Комната № %s
Количество мест: %s""" % (i[1], i[2]),
"widgets": [gtk.Button(i[1])]
}
)
self.widgets[-1]["widgets"][0].set_tooltip_text(
self.widgets[-1]["tooltip"]
)
self.widgets[-1]["widgets"][0].set_size_request(50, -1)
self.attach(
self.widgets[-1]["widgets"][0], 0, 1, row+j, row+j+1
)
j += 1
def attach_days_columns(self, row):
j = 1
for i in self.dates:
self.widgets.append(
{
"date" : i,
"tooltip" : "%i, %s, %i" % (
i[2],
month_list[i[1]-1],
i[0]
),
"widgets" : [
gtk.Button("%i" % i[2])
]
}
)
self.widgets[-1]["widgets"][0].set_tooltip_text(
self.widgets[-1]["tooltip"]
)
self.widgets[-1]["widgets"][0].set_size_request(25, -1)
self.attach(
self.widgets[-1]["widgets"][0], j, j+1, row, row+1
)
j += 1
def attach_months_columns(self, row):
head = 1; tail = 2
print self.dates
for i in xrange(0, len(self.dates)-1):
print self.dates[i][1]
if self.dates[i][1] == self.dates[i+1][1]:
tail += 1
else:
self.widgets.append(
{
"date" : i,
"tooltip" : "%s, %i" % (
month_list[self.dates[i][1]-1],
self.dates[i][0],
),
"widgets" : [
gtk.Button("%s" % month_list[self.dates[i][1]-1])
]
}
)
self.widgets[-1]["widgets"][0].set_tooltip_text(
self.widgets[-1]["tooltip"]
)
self.widgets[-1]["widgets"][0].set_size_request(25, -1)
self.attach(
self.widgets[-1]["widgets"][0], head, tail, row, row+1
)
head = tail + 1
#tail += 1
def clear(self, *args):
for i in self.widgets:
for j in i["widgets"]:
j.destroy()
del self.widgets[:]
def show_rooms(self, date1, date2):
self.clear()
self.dates = date_range(date1, date2)
self.attach_months_columns(0)
self.attach_days_columns(1)
self.attach_rooms_rows(2)
self.show_all()