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

Is it possible to add a Adw.ViewStack? #8

Open
qwersyk opened this issue Jun 20, 2022 · 2 comments
Open

Is it possible to add a Adw.ViewStack? #8

qwersyk opened this issue Jun 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@qwersyk
Copy link

qwersyk commented Jun 20, 2022

I came across your project and I really liked it, you added a lot of examples for widgets, but I noticed that you don't have Adw.ViewStack. I have already used this widget and if you want I can help add it.
Group 1

@natorsc
Copy link
Owner

natorsc commented Jun 20, 2022

Hi @qwersyk.

It would be awesome to have your contribution 😃.

If you can send a pull request I would greatly appreciate it.

@natorsc natorsc added the enhancement New feature or request label Jun 20, 2022
@qwersyk
Copy link
Author

qwersyk commented Jun 20, 2022

I haven't fully figured out how to make pull requests yet, but I've made a small sample code here for widget- Adw.ViewStack.
`import gi

gi.require_version(namespace='Gtk', version='4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Adw, Gio, Gtk

Adw.init()

class ExampleWindow(Gtk.ApplicationWindow):

def __init__(self, **kwargs):
    super().__init__(**kwargs)
    self.hb=Adw.HeaderBar()
    self.set_titlebar(self.hb)

    application=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

    stack=Adw.ViewStack(vexpand=True)
    application.append(stack)

    stack.add_titled(Gtk.Label(label="Page1"),"page1","page1")
    stack.add_titled(Gtk.Label(label="Page2"),"page2","page2")

    self.switcher_title=Adw.ViewSwitcherTitle()
    self.switcher_title.set_stack(stack)
    self.switcher_title.set_title("")
    self.hb.set_title_widget(self.switcher_title)

    self.switcher_bar=Adw.ViewSwitcherBar()
    self.switcher_bar.set_stack(stack)
    self.switcher_bar.set_reveal(True)
    application.append(self.switcher_bar)

    self.set_child(application)
    self.switcher_title.connect("notify::title-visible",self.change_bar)
def change_bar(self,*data):
    if self.switcher_title.get_title_visible():
        self.switcher_bar.set_reveal(True)
    else:
        self.switcher_bar.set_reveal(False)

class ExampleApplication(Adw.Application):

def __init__(self):
    super().__init__(application_id='br.com.justcode.Example',
                     flags=Gio.ApplicationFlags.FLAGS_NONE)

    self.create_action('quit', self.exit_app, ['<primary>q'])
    self.create_action('preferences', self.on_preferences_action)

def do_activate(self):
    win = self.props.active_window
    if not win:
        win = ExampleWindow(application=self)
    win.present()

def do_startup(self):
    Gtk.Application.do_startup(self)

def do_shutdown(self):
    Gtk.Application.do_shutdown(self)

def on_preferences_action(self, action, param):
    print('Ação app.preferences foi ativa.')

def exit_app(self, action, param):
    self.quit()

def create_action(self, name, callback, shortcuts=None):
    action = Gio.SimpleAction.new(name, None)
    action.connect('activate', callback)
    self.add_action(action)
    if shortcuts:
        self.set_accels_for_action(f'app.{name}', shortcuts)

if name == 'main':
import sys

app = ExampleApplication()
app.run(sys.argv)`

Снимок экрана от 2022-06-20 17-41-42
Снимок экрана от 2022-06-20 17-41-49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants