python-gtk-pygobject icon indicating copy to clipboard operation
python-gtk-pygobject copied to clipboard

Is it possible to add a Adw.ViewStack?

Open qwersyk opened this issue 3 years ago • 2 comments

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

qwersyk avatar Jun 20 '22 14:06 qwersyk

Hi @qwersyk.

It would be awesome to have your contribution 😃.

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

natorsc avatar Jun 20 '22 14:06 natorsc

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

qwersyk avatar Jun 20 '22 15:06 qwersyk