class
ViewCategory:
def
flatten(
self
, iterable):
stack
=
deque(iterable)
while
stack:
item
=
stack.popleft()
if
isinstance
(item,
list
):
stack.extendleft(item)
else
:
yield
item
def
viewCategoryItems(
self
):
global
food_category_list
global
confectionery_category_list
global
dairy_category_list
global
fruit_veg_category_list
global
meat_fish_chicken_category_list
global
diy_category_list
global
other_category_list
self
.sel_category.destroy()
self
.categoryViewer
=
Tk()
self
.categoryViewer.title(
"View category items"
)
self
.categoryViewer.attributes(
"-toolwindow"
,
1
)
self
.categoryViewer.resizable(
0
,
0
)
category_items
=
Listbox(
self
.categoryViewer)
category_items.pack()
flat_food_category_list
=
list
(
self
.flatten(food_category_list))
flat_confectionery_category_list
=
list
(
self
.flatten(confectionery_category_list))
flat_dairy_category_list
=
list
(
self
.flatten(dairy_category_list))
flat_fruit_veg_category_list
=
list
(
self
.flatten(fruit_veg_category_list))
flat_meat_fish_chicken_category_list
=
list
(
self
.flatten(meat_fish_chicken_category_list))
flat_diy_category_list
=
list
(
self
.flatten(diy_category_list))
flat_other_category_list
=
list
(
self
.flatten(other_category_list))
lastItem
=
self
.radioButtonList[
-
1
]
if
lastItem
=
=
"0"
:
for
i
in
range
(
0
,
len
(flat_food_category_list)):
category_items.insert(i,
str
(flat_food_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"1"
:
for
i
in
range
(
0
,
len
(flat_confectionery_category_list)):
category_items.insert(i,
str
(flat_confectionery_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"2"
:
for
i
in
range
(
0
,
len
(flat_dairy_category_list)):
category_items.insert(i,
str
(flat_dairy_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"3"
:
for
i
in
range
(
0
,
len
(flat_fruit_veg_category_list)):
category_items.insert(i,
str
(flat_fruit_veg_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"4"
:
for
i
in
range
(
0
,
len
(flat_meat_fish_chicken_category_list)):
category_items.insert(i,
str
(flat_meat_fish_chicken_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"5"
:
for
i
in
range
(
0
,
len
(flat_diy_category_list)):
category_items.insert(i,
str
(flat_diy_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
elif
lastItem
=
=
"6"
:
for
i
in
range
(
0
,
len
(flat_other_category_list)):
category_items.insert(i,
str
(flat_other_category_list[i]).replace(
"{"
, "
").replace("
}
", "
"))
self
.radioButtonList.clear()
def
foodAppend(
self
):
self
.radioButtonList.append(
"0"
)
def
confectioneryAppend(
self
):
self
.radioButtonList.append(
"1"
)
def
dairyAppend(
self
):
self
.radioButtonList.append(
"2"
)
def
fruitVegAppend(
self
):
self
.radioButtonList.append(
"3"
)
def
meatFishChickenAppend(
self
):
self
.radioButtonList.append(
"4"
)
def
diyAppend(
self
):
self
.radioButtonList.append(
"5"
)
def
otherAppend(
self
):
self
.radioButtonList.append(
"6"
)
def
__init__(
self
):
self
.tkVariable
=
IntVar()
self
.radioButtonList
=
[]
self
.sel_category
=
Tk()
self
.sel_category.title(
"Select category to view"
)
self
.sel_category.attributes(
"-toolwindow"
,
1
)
self
.sel_category.attributes(
"-topmost"
,
1
)
self
.sel_category.geometry(
"300x600"
)
Label(
self
.sel_category, text
=
"Select item category to view"
, font
=
(
"Helvetica"
,
23
)).pack(padx
=
30
, pady
=
30
)
self
.foodOption
=
Radiobutton(
self
.sel_category, text
=
"Food"
, variable
=
self
.tkVariable, value
=
1
, command
=
self
.foodAppend)
self
.foodOption.pack()
self
.confectioneryOption
=
Radiobutton(
self
.sel_category, text
=
"Confectionery"
, variable
=
self
.tkVariable, value
=
2
, command
=
self
.confectioneryAppend)
self
.confectioneryOption.pack()
self
.dairyOption
=
Radiobutton(
self
.sel_category, text
=
"Dairy"
, variable
=
self
.tkVariable, value
=
3
, command
=
self
.dairyAppend)
self
.dairyOption.pack()
self
.fruitVegOption
=
Radiobutton(
self
.sel_category, text
=
"Fruit & Vegetables"
, variable
=
self
.tkVariable, value
=
4
, command
=
self
.fruitVegAppend)
self
.fruitVegOption.pack()
self
.meatFishChickenOption
=
Radiobutton(
self
.sel_category, text
=
"Meat, Fish & Chicken"
, variable
=
self
.tkVariable, value
=
5
, command
=
self
.meatFishChickenAppend)
self
.meatFishChickenOption.pack()
self
.diyOption
=
Radiobutton(
self
.sel_category, text
=
"DIY"
, variable
=
self
.tkVariable, value
=
6
, command
=
self
.diyAppend)
self
.diyOption.pack()
self
.otherOption
=
Radiobutton(
self
.sel_category, text
=
"Other"
, variable
=
self
.tkVariable, value
=
7
, command
=
self
.otherAppend)
self
.otherOption.pack()
Label(
self
.sel_category).pack()
self
.viewCategoryBtn
=
Button(
self
.sel_category, text
=
"View category items"
, width
=
65
, state
=
NORMAL, command
=
self
.viewCategoryItems)
self
.viewCategoryBtn.pack()