replace toggle item for connection with GtkSwitch

This commit is contained in:
coderkun 2016-06-04 12:17:02 +02:00
commit 7509a0d672
2 changed files with 26 additions and 9 deletions

View file

@ -646,17 +646,26 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_arrow">False</property>
<child>
<object class="GtkToggleToolButton" id="headerbar-connect">
<object class="GtkToolItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">gtk-disconnect</property>
<signal name="toggled" handler="on_headerbar-connect_toggled" swapped="no"/>
<child>
<object class="GtkSwitch" id="headerbar-connection">
<property name="visible">True</property>
<property name="can_focus">True</property>
<signal name="notify::active" handler="on_headerbar-connection_active_notify" swapped="no"/>
<signal name="state-set" handler="on_headerbar-connection_state_set" swapped="no"/>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -690,6 +699,9 @@
<class name="no-bg"/>
</style>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="title">
<object class="GtkStackSwitcher" id="header-panelswitcher">

View file

@ -426,7 +426,7 @@ class Window():
class HeaderBar(mcg.Base):
SIGNAL_STACK_SWITCHED = 'stack-switched'
SIGNAL_CONNECT = 'on_headerbar-connect_toggled'
SIGNAL_CONNECT = 'on_headerbar-connection_active_notify'
SIGNAL_PLAYPAUSE = 'on_headerbar-playpause_toggled'
SIGNAL_SET_VOLUME = 'set-volume'
@ -441,14 +441,15 @@ class HeaderBar(mcg.Base):
# Widgets
self._header_bar = builder.get_object('headerbar')
self._stack_switcher = StackSwitcher(builder)
self._buttons[HeaderBar.SIGNAL_CONNECT] = builder.get_object('headerbar-connect')
self._buttons[HeaderBar.SIGNAL_CONNECT] = builder.get_object('headerbar-connection')
self._buttons[HeaderBar.SIGNAL_PLAYPAUSE] = builder.get_object('headerbar-playpause')
self._buttons[HeaderBar.SIGNAL_SET_VOLUME] = builder.get_object('headerbar-volume')
# Signals
self._stack_switcher.connect_signal(StackSwitcher.SIGNAL_STACK_SWITCHED, self.on_stack_switched)
self._button_handlers = {
'on_headerbar-connect_toggled': self._callback_from_widget,
'on_headerbar-connection_active_notify': self._callback_from_widget,
'on_headerbar-connection_state_set': self.on_connection_state_set,
'on_headerbar-playpause_toggled': self._callback_from_widget,
'on_headerbar-volume_value_changed': self.on_volume_changed,
'on_headerbar-volume_button_press_event': self.on_volume_press,
@ -471,6 +472,10 @@ class HeaderBar(mcg.Base):
self._buttons[HeaderBar.SIGNAL_CONNECT].set_sensitive(not connecting)
def on_connection_state_set(self, widget, state):
return True
def on_stack_switched(self, widget):
self._callback(HeaderBar.SIGNAL_STACK_SWITCHED, widget)
@ -496,8 +501,8 @@ class HeaderBar(mcg.Base):
self._buttons[HeaderBar.SIGNAL_CONNECT].handler_block_by_func(
self._button_handlers[HeaderBar.SIGNAL_CONNECT]
)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_stock_id(Gtk.STOCK_CONNECT)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_active(True)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_state(True)
self._buttons[HeaderBar.SIGNAL_CONNECT].handler_unblock_by_func(
self._button_handlers[HeaderBar.SIGNAL_CONNECT]
)
@ -507,8 +512,8 @@ class HeaderBar(mcg.Base):
self._buttons[HeaderBar.SIGNAL_CONNECT].handler_block_by_func(
self._button_handlers[HeaderBar.SIGNAL_CONNECT]
)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_stock_id(Gtk.STOCK_DISCONNECT)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_active(False)
self._buttons[HeaderBar.SIGNAL_CONNECT].set_state(False)
self._buttons[HeaderBar.SIGNAL_CONNECT].handler_unblock_by_func(
self._button_handlers[HeaderBar.SIGNAL_CONNECT]
)
@ -545,7 +550,7 @@ class HeaderBar(mcg.Base):
self._buttons[HeaderBar.SIGNAL_SET_VOLUME].set_visible(False)
def _callback_from_widget(self, widget):
def _callback_from_widget(self, widget, *args):
if widget is self._buttons[HeaderBar.SIGNAL_CONNECT]:
self._callback(self.SIGNAL_CONNECT)
elif widget is self._buttons[HeaderBar.SIGNAL_PLAYPAUSE]: