Reputation: 415
I have a window which has two dropdown lists (country and club) which should never be visible at the same time.
When the app loads, neither should be visible. A third dropdown list (tournament type), with nothing selected by default, decides which of the club or country lists should display. Clicking on a button at the top of the screen populates the dropdown lists, selecting the appropriate tournament type and the associated club/or country.
What actually happens: When it loads, both dropdown lists are visible. When the tournament type is selected, both lists are visible. When I click the button at the top the club list is available and the country list is not. The latter is exactly as it should be.
I'm using the same function (set_visible()) to show or hide the lists in each case so I'm at a loss as to why it works in one case but not in the other two.
The code below should run. The bit after #Add Tournaments Tab creates the widgets and unsuccessfully tries to hide the combo boxes. The function on_type_combo changed unsuccessfully tries to hide one of the combo boxes. The function on_tournament_details successfully hides the appropriate box.
#!/usr/bin/python
# coding=utf-8
from gi.repository import Gtk
import wikipedia
class NotebookWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Rugby Database")
#Initialise data
self.country_store = Gtk.ListStore(int, str, str)
self.club_store = Gtk.ListStore(int, str, str, int, int)
self.tournament_store = Gtk.ListStore(int, str, int, str, int)
self.cur_id = 0
self.cur_club = ''
self.cur_club_id = 0
self.update_club_id = 0
self.update_tournament_id = 0
self.initialise_lists()
#Create Application Window
self.set_border_width(10)
self.set_default_size(800, 600)
self.set_position(Gtk.WindowPosition.CENTER)
#Add external container (box)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
#Add tabbed window
self.nbook = Gtk.Notebook()
vbox.pack_start(self.nbook, True, True, 0)
self.nbook.show()
#Add Tournaments tab
frame = Gtk.Frame()
frame.show()
self.t_type_id = -1
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.tournament_box = Gtk.FlowBox()
self.tournament_box.set_valign(Gtk.Align.START)
self.tournament_box.set_max_children_per_line(4)
self.tournament_box.set_selection_mode(Gtk.SelectionMode.SINGLE)
self.tournament_box.set_activate_on_single_click(True)
vbox.pack_start(self.tournament_box, True, True, 0)
self.wiki_label = Gtk.Label()
self.wiki_label.set_line_wrap(True)
vbox.add(self.wiki_label)
tournament_grid = Gtk.Grid()
tournament_grid.set_column_spacing(5)
tournament_label = Gtk.Label(" Tournament Name: ")
tournament_logo_label = Gtk.Label("Logo:")
self.tournament_logo_entry = Gtk.Entry()
self.tournament_entry = Gtk.Entry()
self.t_type_combo = Gtk.ComboBoxText()
self.t_holder_combo_country = Gtk.ComboBoxText()
self.t_holder_combo_club = Gtk.ComboBoxText()
self.t_holder_combo_country = Gtk.ComboBox.new_with_model(self.country_store)
renderer_text = Gtk.CellRendererText()
self.t_holder_combo_country.pack_start(renderer_text, True)
self.t_holder_combo_country.add_attribute(renderer_text, "text", 1)
self.t_holder_combo_club = Gtk.ComboBox.new_with_model(self.club_store)
renderer_text = Gtk.CellRendererText()
self.t_holder_combo_club.pack_start(renderer_text, True)
self.t_holder_combo_club.add_attribute(renderer_text, "text", 1)
self.t_type_combo.append_text("Club")
self.t_type_combo.append_text("International")
self.t_type_combo.connect("changed", self.on_type_combo_changed)
renderer_text = Gtk.CellRendererText()
self.t_type_combo.pack_start(renderer_text, True)
self.t_type_combo.add_attribute(renderer_text, "text", 1)
type_label = Gtk.Label(" Type: ")
holder_label = Gtk.Label(" Holder: ")
tournament_add = Gtk.Button(" Save ")
tournament_grid.add(tournament_label)
tournament_grid.add(self.tournament_entry)
tournament_grid.add(type_label)
tournament_grid.add(self.t_type_combo)
tournament_grid.add(tournament_logo_label)
tournament_grid.add(self.tournament_logo_entry)
tournament_grid.add(holder_label)
tournament_grid.add(self.t_holder_combo_club)
tournament_grid.add(self.t_holder_combo_country)
tournament_grid.add(tournament_add)
vbox.add(tournament_grid)
self.t_holder_combo_club.set_visible(False)
self.t_holder_combo_country.set_visible(False)
self.tournament_message = Gtk.Label("\n")
vbox.add(self.tournament_message)
label = Gtk.Label()
label.set_markup("<b><big>Tournaments</big></b>")
frame.add(vbox)
self.nbook.append_page(frame, label)
self.load_boxes()
##### Function definitions #####
def initialise_lists(self):
self.country_store.clear()
self.country_store.append([1, 'Ireland', ''])
self.club_store.clear()
self.club_store.append([1, 'Leinster', '',1,1])
self.tournament_store.clear()
self.tournament_store.append([1, 'Pro 12', 1,'',1])
def reset_forms(self):
self.tournament_entry.set_text('')
self.update_club_id = 0
self.update_tournament_id = 0
self.tournament_entry.set_text('')
self.tournament_logo_entry.set_text('')
self.wiki_label.set_text('\n')
def load_boxes(self):
self.tournament_box.foreach(lambda widget: self.tournament_box.remove(widget))
for tournament in range(0, len(self.tournament_store)):
button = Gtk.Button(self.tournament_store[tournament][1])
self.tournament_box.add(button)
button.connect('clicked', self.on_tournament_details, tournament)
self.tournament_box.show_all()
def on_club_combo_changed(self, combo):
tree_iter = combo.get_active_iter()
if tree_iter is not None:
model = combo.get_model()
self.cur_club_id = model[tree_iter][0]
def on_type_combo_changed(self, combo):
tree_iter = combo.get_active_iter()
if tree_iter is not None:
model = combo.get_model()
self.t_type_id = model[tree_iter][0]
if self.t_type_id is "Club":
self.t_holder_combo_country.set_visible(False)
self.t_holder_combo_club.set_visible(True)
elif self.t_type_id is "International":
self.t_holder_combo_club.set_visible(False)
self.t_holder_combo_country.set_visible(True)
def on_tournament_details(self, button, tournament):
self.tournament_entry.set_text(self.tournament_store[tournament][1])
self.t_type_combo.set_active(self.tournament_store[tournament][2]-1)
self.tournament_logo_entry.set_text(self.tournament_store[tournament][3])
self.update_tournament_id = self.tournament_store[tournament][0]
self.tournament_message.set_text('\n')
self.wiki_label.set_text(wikipedia.summary(self.tournament_store[tournament][1], sentences=2))
if self.t_type_id == "Club":
self.t_holder_combo_country.set_visible(False)
self.t_holder_combo_club.set_visible(True)
self.t_holder_combo_club.set_active(self.tournament_store[tournament][4]-1)
elif self.t_type_id == "International":
self.t_holder_combo_club.set_visible(False)
self.t_holder_combo_country.set_visible(True)
self.t_holder_combo_country.set_active(self.tournament_store[tournament][4]-1)
win = NotebookWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
Upvotes: 1
Views: 1866
Reputation: 39853
Tell the dropdown lists not to show, when you call win.show_all()
. This can be accomblished by calling set_no_show_all
on the widget, that should not be shown.
Upvotes: 5