update
parent
b9bb98966c
commit
360cd9a5a8
106
draft/test.py
106
draft/test.py
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from Xlib import display
|
||||
from pprint import pprint as print
|
||||
# from pprint import pprint as print
|
||||
import gi, cairo
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gdk
|
||||
|
@ -31,33 +31,101 @@ def on_draw(widget, cr):
|
|||
|
||||
def on_mouse_move(widget, event):
|
||||
|
||||
pointer = root.query_pointer()
|
||||
print(event.x_root, event.y_root)
|
||||
# pointer = root.query_pointer()
|
||||
# print("Mouse at (%d, %d)" % (pointer.root_x, pointer.root_y))
|
||||
win_at_pointer = pointer.child
|
||||
print(win_at_pointer.get_wm_class())
|
||||
# win_at_pointer = pointer.child
|
||||
# print(win_at_pointer.get_wm_class())
|
||||
|
||||
# print(dir(Gtk.WindowType))
|
||||
|
||||
# 创建遮罩窗口
|
||||
# window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
|
||||
window = Gtk.Window(type=Gtk.WindowType.POPUP)
|
||||
window.set_default_size(total_width, total_height)
|
||||
window.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
|
||||
|
||||
# 设置透明背景
|
||||
screen = window.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
if visual and screen.is_composited():
|
||||
window.set_visual(visual)
|
||||
class App(Gtk.Window):
|
||||
|
||||
window.set_app_paintable(True)
|
||||
def __init__(self):
|
||||
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP)
|
||||
self.set_default_size(total_width, total_height)
|
||||
self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
|
||||
|
||||
window.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
|
||||
window.connect("motion-notify-event", on_mouse_move)
|
||||
# 设置透明背景
|
||||
screen = self.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
if visual and screen.is_composited():
|
||||
self.set_visual(visual)
|
||||
|
||||
self.set_app_paintable(True)
|
||||
|
||||
|
||||
|
||||
window.connect("draw", on_draw)
|
||||
self.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
|
||||
# window.connect("button-press-event", on_mouse_move)
|
||||
# window.connect("button-release-event", on_mouse_move)
|
||||
# window.connect("motion-notify-event", on_mouse_move)
|
||||
# window.connect("motion-notify-event", on_mouse_move)
|
||||
|
||||
window.show_all()
|
||||
Gtk.main()
|
||||
|
||||
# layout = Gtk.Fixed()
|
||||
# btn = Gtk.Button(label = 'hello world')
|
||||
# btn.set_size_request(200, 32)
|
||||
# layout.put(btn, 0, 0)
|
||||
# self.add(layout)
|
||||
|
||||
|
||||
self.drawing_area = Gtk.DrawingArea()
|
||||
self.drawing_area.add_events(
|
||||
Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK)
|
||||
self.drawing_area.connect("draw", self.on_draw)
|
||||
self.drawing_area.connect("button-press-event", self.on_button_press)
|
||||
self.drawing_area.connect("button-release-event", self.on_button_release)
|
||||
self.drawing_area.connect("motion-notify-event", self.on_motion_notify)
|
||||
self.add(self.drawing_area)
|
||||
# Initialize rectangle and control point size
|
||||
self.start_x = None
|
||||
self.start_y = None
|
||||
self.current_x = None
|
||||
self.current_y = None
|
||||
|
||||
self.dragging = False
|
||||
self.resize_dragging = False
|
||||
|
||||
self.connect("draw", on_draw)
|
||||
|
||||
def on_draw(self, widget, cr):
|
||||
if self.start_x is not None and self.start_y is not None:
|
||||
width = self.current_x - self.start_x
|
||||
height = self.current_y - self.start_y
|
||||
cr.set_dash([6.0, 4.0])
|
||||
cr.rectangle(self.start_x, self.start_y, width, height)
|
||||
cr.stroke()
|
||||
# draw resizing dots
|
||||
for x in [self.start_x, self.start_x + width / 2, self.current_x]:
|
||||
for y in [self.start_y, self.start_y + height / 2, self.current_y]:
|
||||
cr.arc(x, y, 5, 0, 2 * 3.14)
|
||||
cr.fill()
|
||||
def on_button_press(self, widget, event):
|
||||
if event.button == 1: # left mouse button
|
||||
self.start_x = event.x
|
||||
self.start_y = event.y
|
||||
self.current_x = event.x
|
||||
self.current_y = event.y
|
||||
self.dragging = True
|
||||
def on_button_release(self, widget, event):
|
||||
if event.button == 1: # left mouse button
|
||||
self.dragging = False
|
||||
self.queue_draw()
|
||||
def on_motion_notify(self, widget, event):
|
||||
if self.dragging:
|
||||
self.current_x = event.x
|
||||
self.current_y = event.y
|
||||
self.queue_draw()
|
||||
|
||||
|
||||
|
||||
def run(self):
|
||||
self.show_all()
|
||||
Gtk.main()
|
||||
|
||||
|
||||
|
||||
App().run()
|
Loading…
Reference in New Issue