This commit is contained in:
Page Asgardius 2024-10-07 17:29:15 -07:00
parent 2ee405f245
commit 4442c152a2
3 changed files with 143 additions and 143 deletions

View file

@ -1,95 +0,0 @@
'''
Example of a list with two lines per row.
'''
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gio, GObject, GLib
# content list to add to the listview
content = (
('Into the New', 'Angus Guild'),
('Now to the Sea', 'Anne Toner'),
('Sleeping Gypsy', 'Ralph Bennett-Eades'),
('Angels in Silence', 'The Wastrels'),
('Deeply in Love', 'Duo Montagne'),
('No Bridges', 'Martin Way')
)
class DataObject(GObject.GObject):
'''
object to hold the data for each row
'''
def __init__(self, text: str):
super().__init__()
self.text = text
class AppWindow(Gtk.ApplicationWindow):
def __init__(self, app):
super(AppWindow, self).__init__(application=app)
self.init_ui()
def init_ui(self):
self.title="Double List"
GLib.set_prgname (
'Adwaita Examples by Afacanc38'
)
GLib.set_application_name (
'Adwaita ListBox'
)
self.set_default_size (650, 500)
self.default_height=400
self.default_width=400
self.scroll = Gtk.ScrolledWindow ()
self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
listview = Gtk.ListView()
factory = Gtk.SignalListItemFactory()
factory.connect("setup", self.setup)
factory.connect("bind", self.bind)
listview.set_factory(factory)
self.scroll.set_child (
listview
)
selection = Gtk.SingleSelection()
store = Gio.ListStore.new(DataObject)
selection.set_model(store)
listview.set_model(selection)
#add rows to the listview from the content list
for row in content:
line1, line2 = row
item = line1 + '\n' + line2
store.append(DataObject(item))
self.set_child(self.scroll)
def setup(self, widget, item):
"""Setup the widget (Gtk.ListItem) to show in the Gtk.ListView"""
label = Gtk.Label(
margin_top = 2,
margin_start = 8,
margin_end = 8,
halign = Gtk.Align.START
)
item.set_child(label)
def bind(self, widget, item):
"""bind data (Gtk.ListItem) from the store object to the widget"""
label = item.get_child()
obj = item.get_item()
label.set_label(obj.text)
def on_activate(app):
win = AppWindow(app)
win.present()
app = Gtk.Application(application_id='com.example.doublelist')
app.connect('activate', on_activate)
app.run(None)

53
objectlist-old.py Normal file
View file

@ -0,0 +1,53 @@
import sys
import time
import threading
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QWidget, QPushButton, QSlider, QListWidget
from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
from PyQt6.QtMultimediaWidgets import QVideoWidget
from PyQt6.QtCore import QUrl, Qt, QEvent
class VideoPlayer(QMainWindow):
def __init__(self):
super().__init__()
self.fswindow = 0
self.dclick = False
self.setWindowTitle("Objects")
self.setGeometry(100, 100, 640, 480)
#self.showFullScreen()
self.returnbutton = QPushButton("return")
self.returnbutton.setFixedSize(60, 33)
self.openbutton = QPushButton("open")
self.openbutton.setFixedSize(60, 33)
self.list_widget = QListWidget(self)
self.list_widget.addItems(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'])
layout = QVBoxLayout()
controls = QHBoxLayout()
controls.addWidget(self.returnbutton)
controls.addWidget(self.openbutton)
layout.addLayout(controls)
layout.addWidget(self.list_widget)
#layout.addWidget(self.slider)
container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)
#self.set_layout()
def eventFilter(self, obj, event):
pass
return True
if __name__ == "__main__":
app = QApplication(sys.argv)
video_player = VideoPlayer()
video_player.show()
sys.exit(app.exec())

View file

@ -1,53 +1,95 @@
import sys
import time
import threading
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QWidget, QPushButton, QSlider, QListWidget
from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
from PyQt6.QtMultimediaWidgets import QVideoWidget
from PyQt6.QtCore import QUrl, Qt, QEvent
class VideoPlayer(QMainWindow): '''
def __init__(self): Example of a list with two lines per row.
'''
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gio, GObject, GLib
# content list to add to the listview
content = (
('Into the New', 'Angus Guild'),
('Now to the Sea', 'Anne Toner'),
('Sleeping Gypsy', 'Ralph Bennett-Eades'),
('Angels in Silence', 'The Wastrels'),
('Deeply in Love', 'Duo Montagne'),
('No Bridges', 'Martin Way')
)
class DataObject(GObject.GObject):
'''
object to hold the data for each row
'''
def __init__(self, text: str):
super().__init__() super().__init__()
self.fswindow = 0 self.text = text
self.dclick = False
self.setWindowTitle("Objects")
self.setGeometry(100, 100, 640, 480)
#self.showFullScreen()
self.returnbutton = QPushButton("return")
self.returnbutton.setFixedSize(60, 33)
self.openbutton = QPushButton("open")
self.openbutton.setFixedSize(60, 33)
self.list_widget = QListWidget(self)
self.list_widget.addItems(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'])
layout = QVBoxLayout()
controls = QHBoxLayout()
controls.addWidget(self.returnbutton)
controls.addWidget(self.openbutton)
layout.addLayout(controls)
layout.addWidget(self.list_widget)
#layout.addWidget(self.slider)
container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)
#self.set_layout()
def eventFilter(self, obj, event):
pass
return True
class AppWindow(Gtk.ApplicationWindow):
def __init__(self, app):
super(AppWindow, self).__init__(application=app)
self.init_ui()
if __name__ == "__main__": def init_ui(self):
app = QApplication(sys.argv) self.title="Double List"
video_player = VideoPlayer() GLib.set_prgname (
video_player.show() 'Adwaita Examples by Afacanc38'
sys.exit(app.exec()) )
GLib.set_application_name (
'Adwaita ListBox'
)
self.set_default_size (650, 500)
self.default_height=400
self.default_width=400
self.scroll = Gtk.ScrolledWindow ()
self.scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
listview = Gtk.ListView()
factory = Gtk.SignalListItemFactory()
factory.connect("setup", self.setup)
factory.connect("bind", self.bind)
listview.set_factory(factory)
self.scroll.set_child (
listview
)
selection = Gtk.SingleSelection()
store = Gio.ListStore.new(DataObject)
selection.set_model(store)
listview.set_model(selection)
#add rows to the listview from the content list
for row in content:
line1, line2 = row
item = line1 + '\n' + line2
store.append(DataObject(item))
self.set_child(self.scroll)
def setup(self, widget, item):
"""Setup the widget (Gtk.ListItem) to show in the Gtk.ListView"""
label = Gtk.Label(
margin_top = 2,
margin_start = 8,
margin_end = 8,
halign = Gtk.Align.START
)
item.set_child(label)
def bind(self, widget, item):
"""bind data (Gtk.ListItem) from the store object to the widget"""
label = item.get_child()
obj = item.get_item()
label.set_label(obj.text)
def on_activate(app):
win = AppWindow(app)
win.present()
app = Gtk.Application(application_id='com.example.doublelist')
app.connect('activate', on_activate)
app.run(None)