Skip to content

Commit

Permalink
Add app_state provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Nov 17, 2023
1 parent d8acb89 commit 4c04303
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
26 changes: 22 additions & 4 deletions bureau/content_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,36 @@
# SOFTWARE.
#
# SPDX-License-Identifier: MIT


from gi.repository import Gtk
import inject
from gi.repository import Gtk, GObject, Adw

from bureau.components.sidebar.column import SidebarColumn
from bureau.providers.app_state import AppStateProvider


@Gtk.Template(resource_path='/com/tenderowl/bureau/ui/content_page.ui')
class ContentPage(Gtk.Box):
__gtype_name__ = 'ContentPage'

outer: Adw.OverlaySplitView = Gtk.Template.Child()
sidebar_column: SidebarColumn = Gtk.Template.Child()
toggle_sidebar_btn: Gtk.ToggleButton = Gtk.Template.Child()

app_state: AppStateProvider

def __init__(self, **kwargs):
@inject.autoparams()
def __init__(self, app_state: AppStateProvider, **kwargs):
super().__init__(**kwargs)
self.app_state = app_state

self.app_state.bind_property('sidebar_collapsed', self.outer, 'collapsed', GObject.BindingFlags.BIDIRECTIONAL)
self.toggle_sidebar_btn.bind_property('visible', self.app_state, 'sidebar_collapsed',
GObject.BindingFlags.BIDIRECTIONAL)
self.toggle_sidebar_btn.bind_property('active', self.outer, 'show-sidebar', GObject.BindingFlags.BIDIRECTIONAL)
# self.sidebar_column.connect('notify::show-sidebar', self._on_sidebar_collapsed)

# @Gtk.Template.Callback()
# def _on_sidebar_collapsed(self, state: bool):
# print('Collapsed ', state)
# self.app_state.sidebar_collapsed = state
# self.toggle_sidebar_btn.set_visible(state)
6 changes: 4 additions & 2 deletions bureau/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@

from .window import BureauWindow
from bureau.providers.account import AccountProvider
from bureau.providers.app_state import AppStateProvider
from bureau.providers.imap import ImapProvider


def configure_providers(binder: inject.Binder):
binder.bind(ImapProvider, ImapProvider('imap.yandex.ru'))
binder.bind(AccountProvider, AccountProvider())
binder.bind(AppStateProvider, AppStateProvider())


class BureauApplication(Adw.Application):
Expand Down Expand Up @@ -74,12 +76,12 @@ def do_activate(self):
def on_about_action(self, widget, _):
"""Callback for the app.about action."""
about = Adw.AboutWindow(transient_for=self.props.active_window,
application_name='bureau',
application_name='Bureau',
application_icon='com.tenderowl.bureau',
developer_name='TenderOwl',
version=self.version or '0.1.0',
developers=['Andrey Maksimov'],
copyright='© 2023 Andrey Maksimov')
copyright='© 2023 TenderOwl')
about.present()

def on_preferences_action(self, widget, _):
Expand Down
17 changes: 17 additions & 0 deletions bureau/providers/app_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from gi.repository import GObject


class AppStateProvider(GObject.GObject):
__gtype_name__ = "AppStateProvider"

# Props
sidebar_collapsed = GObject.Property(type=bool, default=True)
mail_column_collapsed = GObject.Property(type=bool, default=True)

# Signals
__gsignals__ = {
'sidebar-changed': (GObject.SIGNAL_RUN_FIRST, None, (bool,))
}

def __init__(self):
super().__init__()
8 changes: 7 additions & 1 deletion data/ui/content_page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template $ContentPage : Box {

Adw.NavigationSplitView inner {
min-sidebar-width: 360;
max-sidebar-width: 600;
max-sidebar-width: 500;
sidebar-width-fraction: 0.40;

sidebar: Adw.NavigationPage {
Expand All @@ -43,6 +43,12 @@ template $ContentPage : Box {
[top]
Adw.HeaderBar {
show-title: false;

ToggleButton toggle_sidebar_btn {
icon-name: "sidebar-show-symbolic";
tooltip-text: "Toggle Sidebar";
visible: false;
}
}
}
};
Expand Down

0 comments on commit 4c04303

Please sign in to comment.