Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make search button a toggle #2053

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blueman/gui/manager/ManagerProgressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, blueman: "Blueman", cancellable: bool = True, text: str = _("

self.show()
if not self.cancellable:
self.eventbox.props.sensitive = False
self.eventbox.set_visible(False)

self.pulsing = False
self.finalized = False
Expand Down
45 changes: 38 additions & 7 deletions blueman/gui/manager/ManagerToolbar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from gettext import gettext as _
import logging
from typing import TYPE_CHECKING, Callable, Tuple, Optional
from typing import TYPE_CHECKING, Callable, Tuple, Optional, Union

import gi

Expand All @@ -24,8 +24,8 @@ def __init__(self, blueman: "Blueman") -> None:
self.blueman.List.connect("adapter-changed", self.on_adapter_changed)
self.blueman.List.connect("adapter-property-changed", self.on_adapter_property_changed)

self.b_search = blueman.builder.get_widget("b_search", Gtk.ToolButton)
self.b_search.connect("clicked", lambda button: blueman.inquiry())
self.b_search = blueman.builder.get_widget("b_search", Gtk.ToggleToolButton)
self.b_search.connect("toggled", self.on_search_toggled)

self.b_bond = blueman.builder.get_widget("b_bond", Gtk.ToolButton)
self.b_bond.connect("clicked", self.on_action, self.blueman.bond)
Expand Down Expand Up @@ -56,14 +56,45 @@ def on_action(self, _button: Gtk.ToolButton, func: Callable[[Device], None]) ->
if device is not None:
func(device)

def _update_search_toggle(self, button: Gtk.ToggleToolButton, searching: bool) -> None:
icon_widget: Union[Gtk.Image, Gtk.Spinner]
if searching:
icon_widget = Gtk.Spinner(visible=True)
icon_widget.start()
label = _("Searching")
tooltip = _("Click to stop searching")
else:
icon_widget = Gtk.Image(icon_name="edit-find-symbolic", icon_size=Gtk.IconSize.LARGE_TOOLBAR, visible=True)
label = _("Search")
tooltip = _("Search for nearby devices")

button.set_active(searching)
button.set_icon_widget(icon_widget)
button.set_label(label)
button.set_tooltip_text(tooltip)

def on_search_toggled(self, button: Gtk.ToggleToolButton) -> None:
if not self.blueman.List.discovering and button.get_active():
self.blueman.inquiry()
self._update_search_toggle(button, True)
elif self.blueman.List.discovering:
self.blueman.List.stop_discovery()
self._update_search_toggle(button, False)

def on_adapter_property_changed(self, _lst: ManagerDeviceList, _adapter: Adapter,
key_value: Tuple[str, object]) -> None:
key, value = key_value
if key == "Discovering":
if value:
self.b_search.props.sensitive = False
else:
self.b_search.props.sensitive = True
if value and not self.blueman.List.discovering:
# It's not blueman discovering
self.b_search.set_sensitive(False)
elif not value:
self.b_search.set_sensitive(True)

# Block or we end in an infinite loop
self.b_search.handler_block_by_func(self.on_search_toggled)
self._update_search_toggle(self.b_search, True if value else False)
self.b_search.handler_unblock_by_func(self.on_search_toggled)

def on_adapter_changed(self, _lst: ManagerDeviceList, adapter_path: Optional[str]) -> None:
logging.debug(f"toolbar adapter {adapter_path}")
Expand Down
3 changes: 1 addition & 2 deletions blueman/main/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def on_progress(_lst: ManagerDeviceList, frac: float) -> None:
else:
prog.fraction(frac)

prog = ManagerProgressbar(self, text=_("Searching"))
prog.connect("cancelled", lambda x: self.List.stop_discovery())
prog = ManagerProgressbar(self, text=_("Searching"), cancellable=False)

def on_error(e: Exception) -> None:
prog.finalize()
Expand Down
12 changes: 9 additions & 3 deletions data/ui/manager-main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkImage" id="discover_widget">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">edit-find-symbolic</property>
<property name="icon_size">3</property>
</object>
<object class="GtkImage" id="ib_more_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -289,14 +295,14 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkToolButton" id="b_search">
<object class="GtkToggleToolButton" id="b_search">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">Search for nearby devices</property>
<property name="is-important">True</property>
<property name="label" translatable="yes" comments="translators: toolbar item: keep it as short as possible">Search</property>
<property name="icon-name">edit-find-symbolic</property>
<property name="label" translatable="yes">Search</property>
<property name="icon-widget">discover_widget</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down
4 changes: 4 additions & 0 deletions stubs/gi/repository/GObject.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ class Object():

def handler_block(self, handler_id: builtins.int) -> None: ...

def handler_block_by_func(self, handlerr: function) -> None: ...

def handler_is_connected(self, handler_id: int) -> bool: ...

def handler_unblock(self, handler_id: builtins.int) -> None: ...

def handler_unblock_by_func(self, handler: function) -> None: ...

@staticmethod
def interface_find_property(g_iface: TypeInterface, property_name: builtins.str) -> ParamSpec: ...

Expand Down
1 change: 1 addition & 0 deletions stubs/gi/repository/Gtk.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7052,6 +7052,7 @@ class Image(Misc):
def __init__(self,
*,
icon_name: typing.Optional[str] = None,
icon_size: typing.Optional[int] = 4,
pixel_size: int = -1,
# Widget
halign: Align = Align.FILL,
Expand Down