klippyGtk: fixup possible issues with spinner and busy state
This commit is contained in:
parent
7f00a37244
commit
f77e382252
@ -8,15 +8,24 @@ gi.require_version("Gtk", "3.0")
|
|||||||
from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, Pango
|
from gi.repository import Gdk, GdkPixbuf, Gio, Gtk, Pango
|
||||||
|
|
||||||
|
|
||||||
def format_label(widget, lines=2):
|
def find_widget(widget, wanted_type):
|
||||||
if isinstance(widget, Gtk.Label):
|
# Returns a widget of wanted_type or None
|
||||||
widget.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
if isinstance(widget, wanted_type):
|
||||||
widget.set_line_wrap(True)
|
return widget
|
||||||
widget.set_ellipsize(Pango.EllipsizeMode.END)
|
if isinstance(widget, (Gtk.Container, Gtk.Bin, Gtk.Button, Gtk.Alignment, Gtk.Box)):
|
||||||
widget.set_lines(lines)
|
|
||||||
elif isinstance(widget, (Gtk.Container, Gtk.Bin, Gtk.Button, Gtk.Alignment, Gtk.Box)):
|
|
||||||
for _ in widget.get_children():
|
for _ in widget.get_children():
|
||||||
format_label(_, lines)
|
result = find_widget(_, wanted_type)
|
||||||
|
if result is not None:
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def format_label(widget, lines=2):
|
||||||
|
label = find_widget(widget, Gtk.Label)
|
||||||
|
if label is not None:
|
||||||
|
label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
|
||||||
|
label.set_line_wrap(True)
|
||||||
|
label.set_ellipsize(Pango.EllipsizeMode.END)
|
||||||
|
label.set_lines(lines)
|
||||||
|
|
||||||
|
|
||||||
class KlippyGtk:
|
class KlippyGtk:
|
||||||
@ -179,20 +188,23 @@ class KlippyGtk:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def Button_busy(widget, busy):
|
def Button_busy(widget, busy):
|
||||||
box = widget.get_child().get_child()
|
spinner = find_widget(widget, Gtk.Spinner)
|
||||||
|
image = find_widget(widget, Gtk.Image)
|
||||||
if busy:
|
if busy:
|
||||||
widget.set_sensitive(False)
|
widget.set_sensitive(False)
|
||||||
widget.set_always_show_image(False)
|
if image:
|
||||||
box.get_children()[0].hide()
|
widget.set_always_show_image(False)
|
||||||
if isinstance(box.get_children()[1], Gtk.Spinner):
|
image.hide()
|
||||||
box.get_children()[1].start()
|
if spinner:
|
||||||
box.get_children()[1].show()
|
spinner.start()
|
||||||
|
spinner.show()
|
||||||
else:
|
else:
|
||||||
box.get_children()[0].show()
|
if image:
|
||||||
if isinstance(box.get_children()[1], Gtk.Spinner):
|
widget.set_always_show_image(True)
|
||||||
box.get_children()[1].stop()
|
image.show()
|
||||||
box.get_children()[1].hide()
|
if spinner:
|
||||||
widget.set_always_show_image(True)
|
spinner.stop()
|
||||||
|
spinner.hide()
|
||||||
widget.set_sensitive(True)
|
widget.set_sensitive(True)
|
||||||
|
|
||||||
def Dialog(self, screen, buttons, content, callback=None, *args):
|
def Dialog(self, screen, buttons, content, callback=None, *args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user