restore files

This commit is contained in:
Alperen İsa Nalbant 2022-06-17 17:42:29 +03:00 committed by GitHub
parent 172bbf558e
commit cc295c020d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 1667 additions and 4 deletions

View File

@ -1,5 +1,27 @@
# PyGTK examples
# PyGObject examples
| libhandy | screenshot |
| ------------------ | ---------------------------------------------------------- |
| 1-box.py | ![box](screenshots/handy/1-box-py.png) |
| 2-headerbar.py | ![headerbar](screenshots/handy/2-headerbar-py.png) |
| 3-revealer.py | ![revealer](screenshots/handy/3-revealer-py.png) |
| 4-stack.py | ![stack](screenshots/handy/4-stack-py.png) |
| 5-style-classes.py | ![style-classes](screenshots/handy/5-style-classes-py.png) |
| 6-deck.py | ![deck](screenshots/handy/6-deck-py.png) |
| libadwaita | screenshot |
| ------------------ | -------------------------------------------------------------- |
| 1-hello-world.py | ![helloworld](screenshots/libadwaita/1-hello-world-py.png) |
| 2-buttons.py | ![buttons](screenshots/libadwaita/2-buttons-py.png) |
| 3-leaflet.py | ![leaflet](screenshots/libadwaita/3-leaflet-py.png) |
| 4-clamp.py | ![clamp](screenshots/libadwaita/4-clamp-py.png) |
| 5-lists.py | ![lists](screenshots/libadwaita/5-lists-py.png) |
| 6-view-switcher.py | ![viewswitcher](screenshots/libadwaita/6-view-switcher-py.png) |
| 7-carousel.py | ![carousel](screenshots/libadwaita/7-carousel-py.png) |
## Requirements:
* Python 3
* GTK+ 3.0
* Handy 1.0 (dev)
- Python 3
- GTK+ 3.0 (4.0 for libadwaita)
- Handy 1.0
- Libadwaita 1.0

63
handy/5-style-classes.py Normal file
View File

@ -0,0 +1,63 @@
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Handy", "1")
from gi.repository import Gtk, Handy
Handy.init()
class MyWindow(Handy.Window):
def __init__(self):
super().__init__(title="Hello World")
self.set_default_size(900, 300)
self.handle = Handy.WindowHandle()
self.add(self.handle)
# Window box
self.winbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.handle.add(self.winbox)
## Headerbar
self.hb = Handy.HeaderBar()
self.hb.set_show_close_button(True)
self.hb.props.title = "Style Classes Example"
self.winbox.pack_start(self.hb, False, True, 0)
# MainBox
self.mainbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)
self.winbox.pack_start(self.mainbox, True, True, 0)
## Button box
self.btn_box = Gtk.ButtonBox(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER, spacing=6)
self.mainbox.pack_start(self.btn_box, True, True, 0)
### Normal button
self.btn = Gtk.Button(label="Normal")
self.btn_box.pack_start(self.btn, False, False, 0)
### Suggested button
self.btn_suggested = Gtk.Button(label="Suggested")
self.btn_suggested.get_style_context().add_class("suggested-action")
self.btn_box.pack_start(self.btn_suggested, False, False, 0)
### Destructive button
self.btn_destructive = Gtk.Button(label="Destructive")
self.btn_destructive.get_style_context().add_class("destructive-action")
self.btn_box.pack_start(self.btn_destructive, False, False, 0)
## Flat button box
self.btn_box2 = Gtk.ButtonBox(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER, spacing=6)
self.mainbox.pack_start(self.btn_box2, True, True, 0)
### Normal button
self.btn_flat = Gtk.Button(label="Flat")
self.btn_flat.get_style_context().add_class("flat")
self.btn_box.pack_start(self.btn_flat, False, False, 0)
### Suggested button
self.btn_suggested_flat = Gtk.Button(label="Suggested Flat")
self.btn_suggested_flat.get_style_context().add_class("suggested-action")
self.btn_suggested_flat.get_style_context().add_class("flat")
self.btn_box.pack_start(self.btn_suggested_flat, False, False, 0)
### Destructive button
self.btn_destructive_flat = Gtk.Button(label="Destructive Flat")
self.btn_destructive_flat.get_style_context().add_class("destructive-action")
self.btn_destructive_flat.get_style_context().add_class("flat")
self.btn_box.pack_start(self.btn_destructive_flat, False, False, 0)
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

194
handy/6-deck.py Normal file
View File

@ -0,0 +1,194 @@
import gi
gi.require_version ('Gtk', '3.0')
gi.require_version ('Handy', '1')
from gi.repository import Gtk, Handy
Handy.init ()
class MyWindow (Handy.Window):
def __init__ (self):
super() .__init__(
title = 'Hello World'
)
self.set_default_size (900, 300)
# WindowHandle
self.hdl = Handy.WindowHandle ()
self.add (self.hdl)
# Deck
self.deck = Handy.Deck ()
self.deck.set_can_swipe_back (True)
self.hdl.add (self.deck)
# Main Page
self.mainpage = Gtk.Box(
spacing = 6,
orientation = Gtk.Orientation.VERTICAL
)
self.hb = Handy.HeaderBar()
self.hb.set_show_close_button(True)
self.hb.props.title = "Handy Deck Example"
self.mainpage.pack_start(
self.hb,
False,
True,
0
)
self.deck.add (self.mainpage)
# Page 1
self.page1 = Gtk.Box(
spacing = 6,
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.lbl_page1 = Gtk.Label (
label = 'Page 1',
)
self.btn_prev1 = Gtk.Button (
label = 'Previous',
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.btn_prev1.connect(
'clicked', self.on_prev_clicked
)
self.page1.pack_start(
self.lbl_page1,
True,
True,
0
)
self.page1.pack_start(
self.btn_prev1,
True,
True,
0
)
self.deck.add (self.page1)
# Page 2
self.page2 = Gtk.Box(
spacing = 6,
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.lbl_page2 = Gtk.Label (
label = 'Page 2'
)
self.btn_prev2 = Gtk.Button (
label = 'Previous',
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.btn_prev2.connect(
'clicked', self.on_prev_clicked
)
self.page2.pack_start(
self.lbl_page2,
True,
True,
0
)
self.page2.pack_start(
self.btn_prev2,
True,
True,
0
)
self.deck.add (self.page2)
# Page 3
self.page3 = Gtk.Box(
spacing = 6,
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.btn_prev3 = Gtk.Button (
label = 'Previous',
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.btn_prev3.connect(
'clicked', self.on_prev_clicked
)
self.lbl_page3 = Gtk.Label (
label = 'Page 3'
)
self.page3.pack_start(
self.lbl_page3,
True,
True,
0
)
self.page3.pack_start(
self.btn_prev3,
True,
True,
0
)
self.deck.add (self.page3)
# Main page
self.btn_box = Gtk.ButtonBox (
spacing = 6,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.btn_page1 = Gtk.Button (
label = 'Page 1',
)
self.btn_box.add (self.btn_page1)
self.btn_page1.connect(
'clicked',
self.on_btn_page1_clicked
)
self.btn_page2 = Gtk.Button (
label = 'Page 2',
)
self.btn_page2.connect(
'clicked', self.on_btn_page2_clicked
)
self.btn_box.add (self.btn_page2)
self.btn_page3 = Gtk.Button (
label = 'Page 3'
)
self.btn_page3.connect(
'clicked',
self.on_btn_page3_clicked
)
self.btn_box.add (self.btn_page3)
self.mainpage.pack_start(
self.btn_box,
True,
True,
0
)
def on_btn_page1_clicked (self, widget):
self.deck.set_visible_child (self.page1)
def on_btn_page2_clicked (self, widget):
self.deck.set_visible_child (self.page2)
def on_btn_page3_clicked (self, widget):
self.deck.set_visible_child (self.page3)
def on_prev_clicked (self, widget):
self.deck.set_visible_child (self.mainpage)
win = MyWindow ()
win.connect ('destroy', Gtk.main_quit)
win.show_all ()
Gtk.main ()

108
libadwaita/1-hello-world.py Normal file
View File

@ -0,0 +1,108 @@
import sys
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, GLib, Gio
class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.set_default_size(300, 400)
self.set_title("Merhaba dünya!")
GLib.set_application_name("Merhaba Dünya!")
GLib.set_prgname('Merhaba Dünya!')
self.main_box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
spacing = 6, # Öğeler arasında boşluk
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER # Öğeleri ortaya sabitledik
)
self.set_child(self.main_box)
self.lbl_hello = Gtk.Label(
label = "Merhaba dünya"
)
self.main_box.append(self.lbl_hello)
self.btn_hello = Gtk.Button(
label = "Bana tıkla"
)
self.btn_hello.connect(
"clicked",
self.btn_hello_clicked
)
self.main_box.append(self.btn_hello)
self.hb = Gtk.HeaderBar()
self.set_titlebar(self.hb)
self.btn_open = Gtk.Button(
label = ""
)
self.btn_open.set_icon_name("document-open-symbolic")
self.hb.pack_start(self.btn_open)
self.dyl_open = Gtk.FileChooserNative.new(
title = "Bir dosya seçin",
parent = self,
action = Gtk.FileChooserAction.OPEN
)
self.dyl_open.connect("response", self.open_response)
self.btn_open.connect("clicked", self.show_open_dialog)
self.lbl_filepath = Gtk.Label()
menuAction = Gio.SimpleAction.new("birseyler", None)
menuAction.connect("activate", self.print_something)
self.add_action(menuAction)
menu = Gio.Menu.new()
menu.append("Bir şeyler yap!", "win.birseyler")
self.popover = Gtk.PopoverMenu()
self.popover.set_menu_model(menu)
self.hamburger = Gtk.MenuButton()
self.hamburger.set_popover(self.popover)
self.hamburger.set_icon_name("open-menu-symbolic")
self.hb.pack_end(self.hamburger)
app = self.get_application()
sm = app.get_style_manager()
sm.set_color_scheme(Adw.ColorScheme.PREFER_DARK)
self.main_box.set_margin_top(10)
self.main_box.set_margin_bottom(10)
self.main_box.set_margin_start(10)
self.main_box.set_margin_end(10)
def print_something(self, action, param):
print("Bir şeyler!")
def open_response(self, dialog, response):
if response == Gtk.ResponseType.ACCEPT:
file = dialog.get_file()
filename = file.get_path()
self.lbl_filepath.set_label(filename)
self.main_box.append(self.lbl_filepath)
def show_open_dialog(self, button):
self.dyl_open.show()
def btn_hello_clicked(self, button):
print("Merhaba dünya!")
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = MainWindow(application=app)
self.win.present()
app = MyApp(application_id="net.teteos.example")
app.run(sys.argv)

172
libadwaita/2-buttons.py Normal file
View File

@ -0,0 +1,172 @@
import sys
import gi
import os
gi.require_version (
'Gtk', '4.0'
)
gi.require_version (
'Adw', '1'
)
from gi.repository import Gtk, Adw, GLib, Gio, Gdk
class MainWindow (Gtk.ApplicationWindow):
def __init__ (self, *args, **kwargs):
super ().__init__ (*args, **kwargs)
GLib.set_application_name ('Adwaita Buttons')
GLib.set_prgname ('Adwaita Examples by Afacanc38')
self.set_default_size (500, 600)
css_provider = Gtk.CssProvider()
css_provider.load_from_file(Gio.File.new_for_path(f'{os.path.dirname(os.path.realpath(__file__))}/resources/2-buttons.css'))
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.hb = Gtk.HeaderBar ()
self.set_titlebar (self.hb)
self.scroll = Gtk.ScrolledWindow ()
self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.set_child (self.scroll)
self.main_box = Gtk.Box (
spacing = 10,
orientation = Gtk.Orientation.VERTICAL
)
self.main_box.set_margin_top (20)
self.main_box.set_margin_bottom (20)
self.main_box.set_margin_start (20)
self.main_box.set_margin_end (20)
self.scroll.set_child(self.main_box)
self.box_normal_buttons_group = Gtk.Box (
spacing = 6,
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.START,
valign = Gtk.Align.CENTER
)
self.main_box.append (self.box_normal_buttons_group)
self.lbl_normal_buttons_title = Gtk.Label (
label = 'Normal Buttons',
halign = Gtk.Align.START
)
self.lbl_normal_buttons_title.get_style_context().add_class ('title-1')
self.box_normal_buttons_group.append (self.lbl_normal_buttons_title)
self.box_normal_buttons = Gtk.Box (
spacing = 6
)
self.box_normal_buttons_group.append (self.box_normal_buttons)
self.normal_button_regular = Gtk.Button (
label = 'Regular'
)
self.box_normal_buttons.append (self.normal_button_regular)
self.normal_button_flat = Gtk.Button (
label = 'Flat'
)
self.normal_button_flat.get_style_context().add_class ('flat')
self.box_normal_buttons.append (self.normal_button_flat)
self.normal_button_suggested = Gtk.Button (
label = 'Suggested'
)
self.normal_button_suggested.get_style_context ().add_class ('suggested-action')
self.box_normal_buttons.append (self.normal_button_suggested)
self.normal_button_destructive = Gtk.Button (
label = 'Destructive'
)
self.normal_button_destructive.get_style_context ().add_class ('destructive-action')
self.box_normal_buttons.append (self.normal_button_destructive)
self.box_custom_buttons = Gtk.Box (
spacing = 6
)
self.box_normal_buttons_group.append (self.box_custom_buttons)
self.custom_button_green = Gtk.Button (
label = 'Custom'
)
self.custom_button_green.get_style_context ().add_class ('green')
self.box_custom_buttons.append (self.custom_button_green)
self.custom_button_purple = Gtk.Button (
label = 'Custom'
)
self.custom_button_purple.get_style_context ().add_class ('purple')
self.box_custom_buttons.append (self.custom_button_purple)
self.custom_button_yellow = Gtk.Button (
label = 'Custom'
)
self.custom_button_yellow.get_style_context ().add_class ('yellow')
self.box_custom_buttons.append (self.custom_button_yellow)
self.custom_button_orange = Gtk.Button (
label = 'Custom'
)
self.custom_button_orange.get_style_context ().add_class ('orange')
self.box_custom_buttons.append (self.custom_button_orange)
self.box_other_buttons_group = Gtk.Box (
spacing = 6,
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.START,
valign = Gtk.Align.CENTER
)
self.main_box.append (self.box_other_buttons_group)
self.lbl_ohter_buttons_title = Gtk.Label (
label = 'Other Buttons',
halign = Gtk.Align.START
)
self.lbl_ohter_buttons_title.get_style_context ().add_class ('title-1')
self.box_other_buttons_group.append (self.lbl_ohter_buttons_title)
self.box_other_buttons = Gtk.Box (
spacing = 6
)
self.box_other_buttons_group.append (self.box_other_buttons)
self.circular_button_1 = Gtk.Button.new_from_icon_name ('go-home-symbolic')
self.circular_button_1.get_style_context().add_class ('circular')
self.box_other_buttons.append (self.circular_button_1)
self.circular_button_2 = Gtk.Button.new_from_icon_name ('document-save-symbolic')
self.circular_button_2.get_style_context().add_class ('circular')
self.box_other_buttons.append (self.circular_button_2)
self.circular_button_3 = Gtk.Button.new_from_icon_name ('document-properties-symbolic')
self.circular_button_3.get_style_context().add_class ('circular')
self.box_other_buttons.append (self.circular_button_3)
self.box_other_buttons_2 = Gtk.Box (
spacing = 6
)
self.box_other_buttons_group.append (self.box_other_buttons_2)
self.pill_button = Gtk.Button (
label = 'Pill Button'
)
self.pill_button.get_style_context ().add_class ('pill')
self.box_other_buttons_2.append (self.pill_button)
class MyApp (Adw.Application):
def __init__ (self, **kwargs):
super ().__init__ (**kwargs)
self.connect (
'activate',
self.on_activate
)
def on_activate (self, app):
self.win = MainWindow (
application = app
)
self.win.present ()
app = MyApp(
application_id = 'io.github.afacanc38.adw-buttons'
)
app.run(sys.argv)

165
libadwaita/3-leaflet.py Normal file
View File

@ -0,0 +1,165 @@
import sys
import gi
import os
gi.require_version (
'Gtk', '4.0'
)
gi.require_version (
'Adw', '1'
)
from gi.repository import Gtk, Adw, GLib, Gio, Gdk
class MainWindow (Gtk.ApplicationWindow):
def __init__ (self, *args, **kwargs):
super ().__init__ (
*args,
**kwargs
)
GLib.set_application_name (
'Adwaita Leaflet'
)
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
self.set_default_size (300, 300)
self.hb = Gtk.HeaderBar ()
self.set_titlebar (self.hb)
self.lf_main = Adw.Leaflet (
halign = Gtk.Align.FILL,
valign = Gtk.Align.FILL
)
self.lf_main.set_can_unfold (False)
self.set_child (
self.lf_main
)
# Home Page
self.pg_home = Gtk.Box (
spacing = 6,
halign = Gtk.Align.FILL,
valign = Gtk.Align.FILL,
hexpand = True,
vexpand = True,
orientation = Gtk.Orientation.VERTICAL
)
self.pg_home.set_margin_top (20)
self.pg_home.set_margin_bottom (20)
self.pg_home.set_margin_start (20)
self.pg_home.set_margin_end (20)
self.lf_main.append (
self.pg_home
)
self.btn_go_second = Gtk.Button (
label = "Go to second page"
)
self.btn_go_second.connect (
'clicked',
self.on_btn_go_second
)
self.btn_go_second.get_style_context ().add_class ('pill')
self.pg_home.append (
self.btn_go_second
)
self.sw_box_set_can_unfold = Gtk.Box (
spacing = 6,
orientation = Gtk.Orientation.HORIZONTAL
)
self.pg_home.append (
self.sw_box_set_can_unfold
)
self.sw_set_can_unfold = Gtk.Switch ()
self.sw_set_can_unfold.set_active (True)
self.sw_set_can_unfold.connect (
'notify::active',
self.on_set_can_unfold
)
self.sw_box_set_can_unfold.append (
self.sw_set_can_unfold
)
self.sw_lbl_set_can_unfold = Gtk.Label (
label = 'Can unfold'
)
self.sw_box_set_can_unfold.append (
self.sw_lbl_set_can_unfold
)
# Second page
self.pg_second = Gtk.Box (
spacing = 6,
halign = Gtk.Align.FILL,
valign = Gtk.Align.FILL,
hexpand = True,
vexpand = True,
orientation = Gtk.Orientation.VERTICAL
)
self.pg_second.set_margin_top (20)
self.pg_second.set_margin_bottom (20)
self.pg_second.set_margin_start (20)
self.pg_second.set_margin_end (20)
self.lf_main.append (
self.pg_second
)
self.lbl_pg2 = Gtk.Label (
label = 'Second Page'
)
self.pg_second.append (
self.lbl_pg2
)
self.btn_go_home = Gtk.Button (
label = "Retrun to home"
)
self.btn_go_home.get_style_context ().add_class ('pill')
self.pg_second.append (
self.btn_go_home
)
self.btn_go_home.connect (
'clicked',
self.on_btn_go_home
)
def on_set_can_unfold (self, switch, gparam):
if self.sw_set_can_unfold.get_active() == False:
self.lf_main.set_can_unfold (True)
else:
self.lf_main.set_can_unfold (False)
def on_btn_go_second (self, widget):
self.lf_main.set_visible_child (self.pg_second)
def on_btn_go_home (self, widget):
self.lf_main.set_visible_child (self.pg_home)
class MyApp (Adw.Application):
def __init__ (self, **kwargs):
super ().__init__ (
**kwargs
)
self.connect (
'activate',
self.on_activate
)
def on_activate (self, app):
self.win = MainWindow (
application = app
)
self.win.present ()
app = MyApp (
application_id = 'io.github.afacanc38.adw-leaflet'
)
app.run (sys.argv)

109
libadwaita/4-clamp.py Normal file
View File

@ -0,0 +1,109 @@
import sys
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, GLib
class MainWindow (Adw.ApplicationWindow):
def __init__ (self, *args, **kwargs):
super ().__init__ (
*args,
**kwargs
)
# Set application name
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
GLib.set_application_name (
'Adwaita Clamp'
)
self.box_main = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL
)
self.set_content (
self.box_main
)
# Headerbar
self.hb = Gtk.HeaderBar ()
self.box_main.append (
self.hb
)
# Clamp widget
self.clamp = Adw.Clamp ()
self.box_main.append (
self.clamp
)
# Wrapper inside Adw.Clamp
self.box_wrapper = Gtk.Box (
spacing = 10,
margin_start = 20,
margin_end = 20,
margin_top = 20,
margin_bottom = 20,
orientation = Gtk.Orientation.VERTICAL
)
self.clamp.set_child (
self.box_wrapper
)
# Label
self.lbl1 = Gtk.Label (
label = 'This widget is inside the Clamp.',
halign = Gtk.Align.CENTER
)
self.lbl1.get_style_context ().add_class (
'title-1'
)
self.lbl1.set_wrap (
True
)
self.box_wrapper.append (
self.lbl1
)
# Sample box
self.box_sample = Gtk.Box ()
self.box_sample.get_style_context ().add_class (
'card'
)
self.box_wrapper.append (
self.box_sample
)
# Label inside sample box
self.lbl2 = Gtk.Label (
label = "I am a box",
margin_start = 10,
margin_end = 10,
margin_top = 10,
margin_bottom = 10,
)
self.box_sample.append (
self.lbl2
)
class MyApp (Adw.Application):
def __init__ (self, **kwargs):
super ().__init__ (
**kwargs
)
self.connect (
'activate',
self.on_activate
)
def on_activate (self, app):
self.win = MainWindow (
application = app
)
self.win.present ()
app = MyApp (
application_id = 'io.github.afacanc38.adw-clamp'
)
app.run (sys.argv)

360
libadwaita/5-lists.py Normal file
View File

@ -0,0 +1,360 @@
import sys
import gi
import os
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, GLib, Gio, Gdk
class MainWindow (Gtk.Window):
def __init__ (self, *args, **kwargs):
super ().__init__ (*args, **kwargs)
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
GLib.set_application_name (
'Adwaita ListBox'
)
self.set_default_size (650, 500)
self.set_size_request (400, 400)
self.scroll = Gtk.ScrolledWindow ()
self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.set_child (self.scroll)
self.box_main = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL
)
self.scroll.set_child (
self.box_main
)
# HeaderBar
self.hb = Gtk.HeaderBar ()
self.set_titlebar (
self.hb
)
# Clamp
self.clamp = Adw.Clamp ()
self.box_main.append (
self.clamp
)
# Wrapper
self.box_wrapper = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL,
margin_top = 20,
margin_bottom = 20,
margin_start = 20,
margin_end = 20
)
self.clamp.set_child (
self.box_wrapper
)
# Header
self.box_header = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL,
margin_bottom = 10
)
self.box_wrapper.append (
self.box_header
)
# Title
self.lbl_title = Gtk.Label (
label = "Lists",
halign = Gtk.Align.CENTER,
wrap = True
)
self.lbl_title.get_style_context ().add_class ('title-1')
self.box_header.append (
self.lbl_title
)
self.box_listbox_wrapper = Gtk.Box (
spacing = 20,
orientation = Gtk.Orientation.VERTICAL
)
self.box_wrapper.append (
self.box_listbox_wrapper
)
# ListBox
self.listbox1 = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox1.get_style_context ().add_class ('boxed-list')
self.box_listbox_wrapper.append (
self.listbox1
)
# Row 1
self.row_listbox1_1 = Adw.ActionRow (
title = 'ActionRow',
subtitle = 'This ActionRow has subtitle and icon',
icon_name = 'emblem-system-symbolic'
)
self.listbox1.append (
self.row_listbox1_1
)
# Row 2
self.row_listbox1_2 = Adw.ActionRow (
title = 'ActionRow can have suffix widgets',
icon_name = 'go-home-symbolic',
subtitle = 'This listbox has subtitle, suffix widget and icon'
)
self.btn_listbox1_2_suffix = Gtk.Button (
label = 'Button',
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER,
)
self.row_listbox1_2.add_suffix (
self.btn_listbox1_2_suffix
)
self.listbox1.append (
self.row_listbox1_2
)
# ListBox 2
self.listbox2 = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox2.get_style_context ().add_class ('boxed-list')
self.box_listbox_wrapper.append (
self.listbox2
)
# Row 1
self.row_listbox2_1 = Adw.ActionRow (
title = 'ActionRow can have prefix widgets',
activatable = True
)
self.rd_listbox2_1_prefix = Gtk.CheckButton ()
self.row_listbox2_1.add_prefix (
self.rd_listbox2_1_prefix
)
self.row_listbox2_1.set_activatable_widget (
self.rd_listbox2_1_prefix
)
self.listbox2.append (
self.row_listbox2_1
)
# Row 2
self.row_listbox2_2 = Adw.ActionRow (
title = 'ActionRow can have prefix widgets',
activatable = True
)
self.rd_listbox2_2_prefix = Gtk.CheckButton ()
self.row_listbox2_2.add_prefix (
self.rd_listbox2_2_prefix
)
self.rd_listbox2_2_prefix.set_group (
self.rd_listbox2_1_prefix
)
self.row_listbox2_2.set_activatable_widget (
self.rd_listbox2_2_prefix
)
self.listbox2.append (
self.row_listbox2_2
)
# ListBox 3
self.prfgr_listbox3 = Adw.PreferencesGroup (
title = 'Expander Rows',
margin_top = 10
)
self.box_wrapper.append (
self.prfgr_listbox3
)
self.listbox3 = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox3.get_style_context ().add_class ('boxed-list')
self.prfgr_listbox3.add (
self.listbox3
)
# ExpanderRow 1
self.row_listbox3_1 = Adw.ExpanderRow (
title = 'ExpanderRow',
subtitle = 'This ActionRow has subtitle and icon',
icon_name = 'emblem-system-symbolic'
)
self.listbox3.append (
self.row_listbox3_1
)
for x in range(3):
self.row_listbox3_1.add_row (
Adw.ActionRow (
title = 'Nested row',
)
)
# ExpanderRow 2
self.row_listbox3_2 = Adw.ExpanderRow (
title = 'ExpanderRow',
subtitle = 'With an action',
icon_name = 'emblem-system-symbolic'
)
self.btn_listbox3_2_action = Gtk.Button.new_from_icon_name (
'edit-copy-symbolic',
)
self.btn_listbox3_2_action.set_halign (Gtk.Align.CENTER)
self.btn_listbox3_2_action.set_valign (Gtk.Align.CENTER)
self.row_listbox3_2.add_action (
self.btn_listbox3_2_action
)
self.listbox3.append (
self.row_listbox3_2
)
for x in range(3):
self.row_listbox3_2.add_row (
Adw.ActionRow (
title = 'Nested row',
)
)
# ListBox 4
self.prfgr_listbox4 = Adw.PreferencesGroup (
title = 'Preferences Group has a suffix',
margin_top = 10
)
self.btn_prfgr_listbox4_suffix = Gtk.Button ()
self.btn_prfgr_listbox4_suffix.get_style_context ().add_class (
'image-text-button'
)
self.btn_prfgr_listbox4_suffix.get_style_context ().add_class (
'flat'
)
self.btn_prfgr_listbox4_suffix_content = Adw.ButtonContent (
label = 'Button',
icon_name = 'view-pin-symbolic'
)
self.btn_prfgr_listbox4_suffix.set_child (
self.btn_prfgr_listbox4_suffix_content
)
self.prfgr_listbox4.set_header_suffix (
self.btn_prfgr_listbox4_suffix
)
self.box_wrapper.append (
self.prfgr_listbox4
)
self.listbox4 = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox4.get_style_context ().add_class ('boxed-list')
self.prfgr_listbox4.add (
self.listbox4
)
# ExpanderRow 1
self.row_listbox4_1 = Adw.ExpanderRow (
title = 'ExpanderRow',
subtitle = 'This ActionRow has subtitle and icon',
icon_name = 'emblem-system-symbolic'
)
self.listbox4.append (
self.row_listbox4_1
)
for x in range(3):
self.row_listbox4_1.add_row (
Adw.ActionRow (
title = 'Nested row',
)
)
# ExpanderRow 2
self.row_listbox4_2 = Adw.ExpanderRow (
title = 'ExpanderRow',
subtitle = 'This ActionRow has subtitle and icon',
icon_name = 'emblem-system-symbolic',
show_enable_switch = True
)
self.listbox4.append (
self.row_listbox4_2
)
for x in range(3):
self.row_listbox4_2.add_row (
Adw.ActionRow (
title = 'Nested row',
)
)
# ListBox 5
self.prfgr_listbox5 = Adw.PreferencesGroup (
title = 'Combo Rows',
margin_top = 10
)
self.box_wrapper.append (
self.prfgr_listbox5
)
self.listbox5 = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox5.get_style_context ().add_class ('boxed-list')
self.prfgr_listbox5.add (
self.listbox5
)
self.strlist_listbox5_1 = Gtk.StringList ()
self.strlist_listbox5_1.append ('Foo')
self.strlist_listbox5_1.append ('Bar')
self.strlist_listbox5_1.append ('Baz')
# Row 1
self.row_listbox5_1 = Adw.ComboRow (
title = 'This a combo row'
)
self.row_listbox5_1.connect (
'notify::selected-item',
self.on_row_listbox5_1_select
)
self.row_listbox5_1.set_model (
self.strlist_listbox5_1
)
self.listbox5.append (
self.row_listbox5_1
)
def on_row_listbox5_1_select (self, widget, event):
print (f'"{self.row_listbox5_1.get_selected_item ().get_string ()}" is selected.')
class MyApp (Adw.Application):
def __init__ (self, **kwargs):
super ().__init__ (
**kwargs
)
self.connect (
'activate',
self.on_activate
)
def on_activate (self, app):
self.win = MainWindow (
application = app
)
self.win.present ()
app = MyApp (
application_id = 'io.github.afacanc38.adw-listbox'
)
app.run (sys.argv)

View File

@ -0,0 +1,184 @@
import sys
import gi
gi.require_version (
"Gtk",
"4.0"
)
gi.require_version(
"Adw",
"1"
)
from gi.repository import Gtk, Adw, GLib
class MainWindow (Adw.ApplicationWindow):
def __init__ (self, *args, **kwargs):
super ().__init__ (
*args,
**kwargs
)
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
GLib.set_application_name (
'Adwaita ViewSwitcher'
)
self.set_name (
'ViewSwitcherDemo'
)
self.set_default_size (600, 300)
self.box_main = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL,
halign = Gtk.Align.FILL,
valign = Gtk.Align.FILL,
hexpand = True,
vexpand = True
)
self.set_content (
self.box_main
)
self.hb = Adw.HeaderBar ()
self.box_main.append (self.hb)
self.stack = Adw.ViewStack ()
self.box_main.append (
self.stack
)
# Squieezer
self.sq_viewswitcher = Adw.Squeezer ()
self.sq_viewswitcher.set_switch_threshold_policy (
Adw.FoldThresholdPolicy.NATURAL
)
self.sq_viewswitcher.set_transition_type (
Adw.SqueezerTransitionType.CROSSFADE
)
self.sq_viewswitcher.set_xalign (1)
self.sq_viewswitcher.set_homogeneous (True)
self.hb.set_title_widget (
self.sq_viewswitcher
)
# ViewSwitcher (wide)
self.viewswitcher_wide = Adw.ViewSwitcher ()
self.viewswitcher_wide.set_policy(
Adw.ViewSwitcherPolicy.WIDE
)
self.viewswitcher_wide.set_stack (
self.stack
)
self.sq_viewswitcher.add (
self.viewswitcher_wide
)
# ViewSwitcher (narrow)
self.viewswitcher_narrow = Adw.ViewSwitcher ()
self.viewswitcher_narrow.set_policy(
Adw.ViewSwitcherPolicy.NARROW
)
self.viewswitcher_narrow.set_stack (
self.stack
)
self.sq_viewswitcher.add (
self.viewswitcher_narrow
)
# ViewSwitcherBar (bottom viewswitcher)
self.viewswitcherbar = Adw.ViewSwitcherBar (
vexpand = True,
valign = Gtk.Align.END
)
self.viewswitcherbar.set_stack (
self.stack
)
self.viewswitcherbar.set_reveal (False)
self.box_main.append (
self.viewswitcherbar
)
# Window Title
self.wintitle = Adw.WindowTitle (
title = 'Adwaita ViewSwitcher'
)
self.sq_viewswitcher.add (self.wintitle)
# Connect signals
self.sq_viewswitcher.connect (
'notify::visible-child',
self.on_sq_get_visible_child
)
# Page 1
self.page1 = Adw.StatusPage (
title = 'Apps',
icon_name = 'view-grid-symbolic',
valign = Gtk.Align.CENTER,
vexpand = True
)
self.stack.add_titled (
self.page1,
'page0',
'Apps'
)
self.stack.get_page (self.page1).set_icon_name (
'view-grid-symbolic'
)
# Page 2
self.page2 = Adw.StatusPage (
title = 'Installed',
icon_name = 'system-software-install-symbolic',
valign = Gtk.Align.CENTER,
vexpand = True
)
self.stack.add_titled (
self.page2,
'page1',
'Installed'
)
self.stack.get_page (self.page2).set_icon_name (
'system-software-install-symbolic'
)
# Page 3
self.page3 = Adw.StatusPage (
title = 'Updates',
icon_name = 'view-refresh-symbolic',
valign = Gtk.Align.CENTER,
vexpand = True
)
self.stack.add_titled (
self.page3,
'page2',
'Updates'
)
self.stack.get_page (self.page3).set_icon_name (
'view-refresh-symbolic'
)
def on_sq_get_visible_child (self, widget, event):
if self.sq_viewswitcher.get_visible_child() == self.wintitle:
self.viewswitcherbar.set_reveal (True)
else:
self.viewswitcherbar.set_reveal (False)
class MyApp (Adw.Application):
def __init__ (self, **kwargs):
super ().__init__ (**kwargs)
self.connect (
'activate',
self.on_activate
)
def on_activate (self, app):
self.win = MainWindow (
application = app
)
self.win.present ()
app = MyApp (
application_id = 'io.github.afacanc38.adw-viewswitcher'
)
app.run (sys.argv)

252
libadwaita/7-carousel.py Normal file
View File

@ -0,0 +1,252 @@
import sys
import gi
gi.require_version (
'Gtk',
'4.0'
)
gi.require_version (
'Adw',
'1'
)
from gi.repository import Gtk, Adw, GLib
class MainWindow (Adw.Window):
def __init__ (self, *args, **kwargs):
super ().__init__ (
*args,
**kwargs
)
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
GLib.set_application_name (
'Adwaita Carousel'
)
self.set_default_size (650, 500)
self.set_size_request (400, 400)
self.box_main = Gtk.Box (
orientation = Gtk.Orientation.VERTICAL,
valign = Gtk.Align.FILL,
vexpand = True
)
self.set_content (
self.box_main
)
self.hb = Gtk.HeaderBar ()
self.box_main.append (
self.hb
)
# Carousel
self.carousel = Adw.Carousel (
hexpand = True,
vexpand = True,
allow_scroll_wheel = True,
allow_long_swipes = False
)
self.box_main.append (
self.carousel
)
# Indicator
self.stk_indicator = Gtk.Stack (
transition_type = Gtk.StackTransitionType.CROSSFADE
)
self.box_main.append (
self.stk_indicator
)
self.carousel_dots = Adw.CarouselIndicatorDots (
carousel = self.carousel
)
self.stk_indicator.add_titled (
self.carousel_dots,
'page0',
'page0'
)
self.carousel_lines = Adw.CarouselIndicatorLines (
carousel = self.carousel
)
self.stk_indicator.add_titled (
self.carousel_lines,
'page1',
'page1'
)
# Page 1
self.page1 = Adw.StatusPage (
title = 'Carousel',
description = 'A widget for paginated scrolling.',
icon_name = 'go-next-symbolic',
hexpand = True,
vexpand = True,
)
self.carousel.append (
self.page1
)
# Page 2
self.page2 = Gtk.Box (
hexpand = True,
vexpand = True,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
)
self.carousel.append (
self.page2
)
self.clamp = Adw.Clamp ()
self.page2.append (
self.clamp
)
self.listbox = Gtk.ListBox (
selection_mode = Gtk.SelectionMode.NONE
)
self.listbox.get_style_context ().add_class (
'boxed-list'
)
self.clamp.set_child (
self.listbox
)
self.setting1 = Adw.ComboRow (
title = 'Indicator Style'
)
self.strlist1 = Gtk.StringList ()
self.strlist1.append (
'Dots'
)
self.strlist1.append (
'Lines'
)
self.setting1.set_model (
self.strlist1
)
self.setting1.connect (
'notify::selected-item',
self.on_setting1_set
)
self.listbox.append (
self.setting1
)
self.setting2 = Adw.ActionRow (
title = 'Long swipes'
)
self.sw_long_swipe = Gtk.Switch (
valign = Gtk.Align.CENTER
)