Aug-01-2022, 02:20 PM
Hi,
I am trying to create an application in PyGTK that will feature 4 video screens in a single GTK window. I am using GTKs UI sockets to embed the video and this works fine. I can embed a number of these in a grid and present it in the window.
However, I wanted to be able to create a hotspot on the corner of each embedded video so that when I hover my mouse there I get the option of invoking a menu or or button that presents a menu. I was wondering which GTK facility I could use. I tried overlays, eventboxes and transparent layouts and drawing widgets but none of them appear to work in a predictable way with the UI socket. Should I be looking at a more basic feature that allows me know where the mouse is? The difficult is that when the video plays the application that renders the video consumes the mouse events so I cannot trap them in the window that embeds the UI sockets.
The code below shows just a few of my unsuccessful attempts:
D
I am trying to create an application in PyGTK that will feature 4 video screens in a single GTK window. I am using GTKs UI sockets to embed the video and this works fine. I can embed a number of these in a grid and present it in the window.
However, I wanted to be able to create a hotspot on the corner of each embedded video so that when I hover my mouse there I get the option of invoking a menu or or button that presents a menu. I was wondering which GTK facility I could use. I tried overlays, eventboxes and transparent layouts and drawing widgets but none of them appear to work in a predictable way with the UI socket. Should I be looking at a more basic feature that allows me know where the mouse is? The difficult is that when the video plays the application that renders the video consumes the mouse events so I cannot trap them in the window that embeds the UI sockets.
The code below shows just a few of my unsuccessful attempts:
from gi.repository import GLib, Gio, Gtk, Gdk
import sys
import cairo
import gi
from subprocess import Popen, PIPE
gi.require_version("Gtk", "3.0")
# works
class PyApp(Gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_title("Socket Demo")
self.set_default_size(1020, 1000)
self.set_resizable(False)
self.socket1 = Gtk.Socket()
self.socket2 = Gtk.Socket()
self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self.connect('enter-notify-event', self.HandleMouse)
self.connect('button-press-event', self.HandleButtonPress)
self.grid = Gtk.Grid()
self.grid2 = Gtk.Grid()
self.overlay = Gtk.Overlay()
self.add(self.overlay)
self.overlay.add(self.grid)
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
#button1 = Gtk.Button(label="Overlayed Button 1")
button1 = Gtk.Button.new()
button1.set_valign(Gtk.Align.START)
button1.set_halign(Gtk.Align.START)
button1.connect("clicked", self.on_button1_clicked)
#button1.margin = 100
button1.set_property("width-request", 185)
button1.set_property("height-request", 115)
button2 = Gtk.Button(label="...")
button2.set_valign(Gtk.Align.START)
button2.set_halign(Gtk.Align.END)
button2.connect("clicked", self.on_button2_clicked)
button2.opacity = 0.1
#self.grid2.attach(button1, 1, 0, 1, 1)
#self.grid2.attach(button2, 0, 1, 10, 10)
eventbox = Gtk.EventBox()
eventbox.set_above_child(True)
eventbox.connect("button_press_event",
self.on_button_pressed, self.socket1)
eventbox.add(self.socket1)
# self.add(eventbox)
eventbox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
# drawingarea = Gtk.DrawingArea()
# drawingarea.connect("draw", self.on_draw)
# layout = Gtk.Layout()
# layout.connect("draw", self.on_draw)
# layout.set_size(1020, 1000)
# self.add(drawingarea)
# label = Gtk.Label.new_with_mnemonic("..")
# hbox.add(label)
# label2 = Gtk.Label.new_with_mnemonic(".")
# hbox.add(label2)
# hbox.set_homogeneous(True)
# button1.add(hbox)
# button1.add(button2)
# self.overlay.add_overlay(button1)
# button1.add(drawingarea)
# self.overlay.add_overlay(button2)
# self.overlay.add_overlay(layout)
self.grid.attach(eventbox, 1, 0, 1, 1)
self.grid.attach(self.socket2, 0, 1, 10, 10)
self.connect("destroy", Gtk.main_quit)
eventbox.realize()
self.show_all()
print("Socket1 = " + hex(self.socket1.get_id()))
print("Socket2 = " + hex(self.socket2.get_id()))
def on_draw(self, wid, cr):
cr.set_operator(cairo.OPERATOR_CLEAR)
cr.paint()
# cr.set_operator(cairo.OPERATOR_OVER)
def HandleMouse(self, event, data):
print("Handling the mouse")
def HandleButtonPress(self, event, data):
print("Handling the mouse button press for window")
def on_button_pressed(self, event):
print("Handling the EventBoxes's #1 mouse button press")
def on_button1_clicked(self, event):
print("Handling the button's #1 mouse button press")
def on_button2_clicked(self, event):
print("Handling the button's #2 mouse button press")
if __name__ == '__main__':
PyApp()
Gtk.main()regardsD
