set_keep_below() makes buttons unclickable
I am trying to create a rain meter like widget. When I use the option set_keep_below(True) in my python code, it makes the button on my widget unclickable. Otherwise the window stays on top of all other windows. Heres some of the code:
### Code for the class with the buttons ###
class NowPlayingWidget(Gtk.Grid):
def __init__(self):
super().__init__()
self.set_name('now-playing')
self.set_row_spacing(10)
self.set_column_spacing(10)
self.set_halign(Gtk.Align.CENTER)
self.set_valign(Gtk.Align.CENTER)
self.now_playing_label = Gtk.Label()
self.now_playing_label.set_name('now-playing-label')
self.now_playing_label.set_halign(Gtk.Align.CENTER)
self.now_playing_label.set_valign(Gtk.Align.CENTER)
self.attach(self.now_playing_label, 0, 0, 2, 1) # Centered label over two columns
self.artist_label = Gtk.Label() # Add an artist label
self.artist_label.set_name('artist-label')
self.artist_label.set_halign(Gtk.Align.CENTER)
self.attach(self.artist_label, 0, 1, 2, 1) # Centered artist label over two columns
self.progress_bar = Gtk.ProgressBar()
self.progress_bar.set_hexpand(True)
self.attach(self.progress_bar, 0, 2, 2, 1) # Centered progress bar over two columns
self.current_time_label = Gtk.Label()
self.current_time_label.set_name('current-time-label')
self.current_time_label.set_halign(Gtk.Align.START)
self.attach(self.current_time_label, 0, 3, 1, 1)
self.total_time_label = Gtk.Label()
self.total_time_label.set_name('total-time-label')
self.total_time_label.set_halign(Gtk.Align.END)
self.attach(self.total_time_label, 1, 3, 1, 1)
# Create a separate container for the buttons
buttons_box = Gtk.ButtonBox(orientation=Gtk.Orientation.HORIZONTAL, spacing=20)
buttons_box.set_halign(Gtk.Align.CENTER)
buttons_box.set_valign(Gtk.Align.CENTER)
self.attach(buttons_box, 0, 4, 2, 1) # Place the button container below the main interface
# Create buttons for play, pause, next, and previous
prev_button = Gtk.Button()
prev_button.set_halign(Gtk.Align.START)
prev_button.set_valign(Gtk.Align.CENTER)
prev_button.get_style_context().add_class("button") # Apply the "button" class to the button
prev_button_image = Gtk.Image.new_from_icon_name("media-seek-backward", Gtk.IconSize.BUTTON)
prev_button_image.get_style_context().add_class("icon") # Apply the "icon" class to the button's image
prev_button.add(prev_button_image)
prev_button.get_style_context().add_class('button')
prev_button.connect("clicked", self.prev_media)
prev_button.connect("enter-notify-event", self.on_hover)
prev_button.connect("leave-notify-event", self.on_leave)
buttons_box.add(prev_button)
play_button = Gtk.Button()
play_button.set_halign(Gtk.Align.START)
play_button.set_valign(Gtk.Align.CENTER)
play_button.get_style_context().add_class("button") # Apply the "button" class to the button
play_button_image = Gtk.Image.new_from_icon_name("media-playback-start", Gtk.IconSize.BUTTON)
play_button_image.get_style_context().add_class("icon") # Apply the "icon" class to the button's image
play_button.add(play_button_image)
play_button.get_style_context().add_class('button')
play_button.connect("clicked", self.play_media)
play_button.connect("enter-notify-event", self.on_hover)
play_button.connect("leave-notify-event", self.on_leave)
buttons_box.add(play_button)
buttons_box.add(play_button)
pause_button = Gtk.Button()
pause_button.set_halign(Gtk.Align.START)
pause_button.set_valign(Gtk.Align.CENTER)
pause_button.get_style_context().add_class("button")
pause_button_image = Gtk.Image.new_from_icon_name("media-playback-pause", Gtk.IconSize.BUTTON)
pause_button_image.get_style_context().add_class("icon")
pause_button.add(pause_button_image)
pause_button.get_style_context().add_class('button')
pause_button.connect("clicked", self.pause_media)
pause_button.connect("enter-notify-event", self.on_hover)
pause_button.connect("leave-notify-event", self.on_leave)
buttons_box.add(pause_button)
buttons_box.add(pause_button)
next_button = Gtk.Button()
next_button.set_halign(Gtk.Align.START)
next_button.set_valign(Gtk.Align.CENTER)
next_button.get_style_context().add_class("button") # Apply the "button" class to the button
next_button_image = Gtk.Image.new_from_icon_name("media-seek-forward", Gtk.IconSize.BUTTON)
next_button_image.get_style_context().add_class("icon") # Apply the "icon" class to the button's image
next_button.add(next_button_image)
next_button.get_style_context().add_class('button')
next_button.connect("clicked", self.next_media)
next_button.connect("enter-notify-event", self.on_hover)
next_button.connect("leave-notify-event", self.on_leave)
buttons_box.add(next_button)
buttons_box.add(next_button)
self.update_song_info()
##....
## OTHER CODE AND METHODS###
### Heres the driver code ###
class Run():
def __init__(self):
style_provider = Gtk.CssProvider()
style_provider.load_from_path('styles.css')
win = Gtk.Window(name='toplevel')
win.set_title('Desktop Clock')
win.set_position(Gtk.WindowPosition.CENTER)
win.set_default_size(600, 500)
win.set_decorated(False)
win.set_skip_taskbar_hint(True)
win.set_skip_pager_hint(True)
win.set_keep_below(True)
win.connect('destroy', Gtk.main_quit)
screen = win.get_screen()
visual = screen.get_rgba_visual()
if visual:
win.set_visual(visual)
else:
print('Your screen may not support transparency')
grid = Gtk.Grid()
grid.set_name('grid')
grid.set_column_homogeneous(True)
clock_widget = clock_date.DesktopClockWidget()
now_playing_widget = now_playing.NowPlayingWidget()
weather_widget = weather_data.WeatherWidget()
weather_widget.set_margin_top(40) # Adjust the pixel value as needed
grid.attach(clock_widget, 0, 0, 1, 1)
grid.attach(now_playing_widget, 0, 1, 1, 1)
grid.attach(weather_widget, 0, 2, 1, 1)
win.add(grid)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
win.show_all()
Gtk.main()
I want to understand why the buttons are disabled when the window goes back, the cursor doesnt change either as it does otherwise.
Edited by Arjan Molenaar