Skip to content

Commit

Permalink
Replace custom MessageArea with standard widget + animation
Browse files Browse the repository at this point in the history
A Gtk.InfoBar already has a Gtk.Revealer which animates perfectly fine for
our use.
  • Loading branch information
infirit committed Jul 10, 2022
1 parent 9724a12 commit 39c6690
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 122 deletions.
2 changes: 1 addition & 1 deletion blueman/gui/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SUBDIRS = \
manager

bluemandir = $(pythondir)/blueman/gui
blueman_PYTHON = MessageArea.py Animation.py GsmSettings.py CommonUi.py DeviceList.py DeviceSelectorDialog.py DeviceSelectorList.py DeviceSelectorWidget.py GenericList.py GtkAnimation.py __init__.py Notification.py
blueman_PYTHON = Animation.py GsmSettings.py CommonUi.py DeviceList.py DeviceSelectorDialog.py DeviceSelectorList.py DeviceSelectorWidget.py GenericList.py GtkAnimation.py __init__.py Notification.py

CLEANFILES = \
$(BUILT_SOURCES)
Expand Down
105 changes: 0 additions & 105 deletions blueman/gui/MessageArea.py

This file was deleted.

7 changes: 2 additions & 5 deletions blueman/gui/manager/ManagerDeviceMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from blueman.gui.manager.ManagerProgressbar import ManagerProgressbar
from blueman.main.Builder import Builder
from blueman.main.DBusProxies import AppletService, DBusProxyFailed
from blueman.gui.MessageArea import MessageArea
from blueman.Sdp import (
ServiceUUID,
AUDIO_SOURCE_SVCLASS_ID,
Expand Down Expand Up @@ -130,8 +129,6 @@ def success(_obj: AppletService, _result: None, _user_data: None) -> None:
logging.info("success")
prog.message(_("Success!"))

MessageArea.close()

self.unset_op(device)

def fail(_obj: Optional[AppletService], result: GLib.Error, _user_data: None) -> None:
Expand Down Expand Up @@ -177,7 +174,7 @@ def ok(_obj: AppletService, _result: None, _user_date: None) -> None:
def err(_obj: Optional[AppletService], result: GLib.Error, _user_date: None) -> None:
logging.warning(f"disconnect failed {result}")
msg, tb = e_(result.message)
MessageArea.show_message(_("Disconnection Failed: ") + msg, tb)
self.Blueman.infobar_update(_("Disconnection Failed: ") + msg, bt=tb)
self.generate()

if self._appl is None:
Expand Down Expand Up @@ -215,7 +212,7 @@ def _handle_error_message(self, error: GLib.Error) -> None:
msg = error.message.split(":", 3)[-1].strip()

if msg != "Cancelled":
MessageArea.show_message(_("Connection Failed: ") + msg)
self.Blueman.infobar_update(_("Connection Failed: ") + msg)

@staticmethod
def _get_errno(error: GLib.Error) -> Optional[int]:
Expand Down
46 changes: 39 additions & 7 deletions blueman/main/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from blueman.main.Config import Config
from blueman.main.DBusProxies import AppletService, DBusProxyFailed
from blueman.gui.CommonUi import ErrorDialog
from blueman.gui.MessageArea import MessageArea
from blueman.gui.Notification import Notification
from blueman.main.PluginManager import PluginManager
import blueman.plugins.manager
Expand Down Expand Up @@ -72,17 +71,16 @@ def do_activate(self) -> None:
# Connect to configure event to store new window position and size
self.window.connect("configure-event", self._on_configure)

grid = self.builder.get_widget("grid", Gtk.Grid)

toolbar = self.builder.get_widget("toolbar", Gtk.Toolbar)
statusbar = self.builder.get_widget("statusbar", Gtk.Box)

self._infobar = self.builder.get_widget("message_area", Gtk.InfoBar)
self._infobar.connect("response", self._infobar_response)
self._infobar_bt: str = "empty"

self.Plugins = PluginManager(ManagerPlugin, blueman.plugins.manager, self)
self.Plugins.load_plugin()

area = MessageArea()
grid.attach(area, 0, 3, 1, 1)

self._applethandlerid: Optional[int] = None

# Add margin for resize grip or it will overlap
Expand Down Expand Up @@ -208,13 +206,47 @@ def on_progress(_lst: ManagerDeviceList, frac: float) -> None:

def on_error(e: Exception) -> None:
prog.finalize()
MessageArea.show_message(*e_(e))
self.infobar_update(*e_(e))

self.List.discover_devices(error_handler=on_error)

s1 = self.List.connect("discovery-progress", on_progress)
s2 = self.List.connect("adapter-property-changed", prop_changed)

def infobar_update(self, message: str, bt: Optional[str] = None, icon_name: str = "dialog-warning") -> None:
if icon_name == "dialog-warning":
self._infobar.set_message_type(Gtk.MessageType.WARNING)
else:
self._infobar.set_message_type(Gtk.MessageType.INFO)

more_button = self.builder.get_widget("ib_more_button", Gtk.Button)
image = self.builder.get_widget("ib_icon", Gtk.Image)
msg_lbl = self.builder.get_widget("ib_message", Gtk.Label)
image.set_from_icon_name(icon_name, 16)

if bt is not None:
msg_lbl.set_text(f"{message}…")
self._infobar_bt = f"{message}\n{bt}"
more_button.show()
else:
more_button.hide()
msg_lbl.set_text(f"{message}")

self._infobar.set_visible(True)
self._infobar.set_revealed(True)

def _infobar_response(self, info_bar: Gtk.InfoBar, response_id: int) -> None:
logging.debug(f"Response: {response_id}")
if response_id == Gtk.ResponseType.CLOSE:
info_bar.set_revealed(False)
GLib.timeout_add(250, lambda: info_bar.set_visible(False)) # transition is 250.
elif response_id == 0:
dialog = Gtk.MessageDialog(parent=self.window, type=Gtk.MessageType.INFO, modal=True,
buttons=Gtk.ButtonsType.CLOSE, text=self._infobar_bt)
dialog.connect("response", lambda d, _i: d.destroy())
dialog.connect("close", lambda d: d.destroy())
dialog.show()

@staticmethod
def bond(device: Device) -> None:
def error_handler(e: Exception) -> None:
Expand Down
3 changes: 1 addition & 2 deletions blueman/plugins/manager/PulseAudioProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from blueman.plugins.ManagerPlugin import ManagerPlugin
from blueman.main.PulseAudioUtils import PulseAudioUtils, EventType
from blueman.gui.manager.ManagerDeviceMenu import ManagerDeviceMenu, MenuItemsProvider, DeviceMenuItem
from blueman.gui.MessageArea import MessageArea
from blueman.Functions import create_menuitem
from blueman.Sdp import AUDIO_SOURCE_SVCLASS_ID, AUDIO_SINK_SVCLASS_ID, ServiceUUID

Expand Down Expand Up @@ -84,7 +83,7 @@ def on_selection_changed(self, item: Gtk.CheckMenuItem, device: Device, profile:

def on_result(res: int) -> None:
if not res:
MessageArea.show_message(_("Failed to change profile to %s" % profile))
self.parent.infobar_update(_("Failed to change profile to %s" % profile))

pa.set_card_profile(c["index"], profile, on_result)

Expand Down
81 changes: 80 additions & 1 deletion data/ui/manager-main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkImage" id="ib_more_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">dialog-information</property>
</object>
<object class="GtkApplicationWindow" id="manager_window">
<property name="can-focus">False</property>
<property name="icon-name">blueman</property>
Expand Down Expand Up @@ -217,7 +222,81 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkInfoBar" id="message_area">
<property name="name">MessageArea</property>
<property name="can-focus">False</property>
<property name="show-close-button">True</property>
<property name="revealed">False</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="spacing">8</property>
<child>
<object class="GtkButton" id="ib_more_button">
<property name="label" translatable="yes">More</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">ib_more_icon</property>
<property name="relief">none</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="spacing">16</property>
<child>
<object class="GtkImage" id="ib_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">16</property>
<property name="icon-name">dialog-warning</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ib_message">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="selectable">True</property>
<property name="single-line-mode">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<action-widgets>
<action-widget response="0">ib_more_button</action-widget>
</action-widgets>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
</object>
</child>
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ blueman/gui/manager/ManagerToolbar.py
blueman/gui/manager/__init__.py
blueman/gui/GtkAnimation.py
blueman/gui/DeviceSelectorDialog.py
blueman/gui/MessageArea.py
blueman/gui/Animation.py
blueman/gui/DeviceSelectorList.py
blueman/gui/CommonUi.py
Expand Down

0 comments on commit 39c6690

Please sign in to comment.