By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 panorama_panel.py

View raw Download
text/x-script.python • 2.26 kiB
Python script, ASCII text executable
        
            
1
import gi
2
gi.require_version("Gtk", "4.0")
3
4
from gi.repository import Gtk, Gdk, GObject
5
6
7
class Applet(Gtk.Box):
8
name = "Generic applet"
9
description = ""
10
11
def __init__(self, orientation=Gtk.Orientation.HORIZONTAL, config=None):
12
super().__init__(orientation=orientation)
13
if orientation == Gtk.Orientation.VERTICAL:
14
self.set_hexpand(True)
15
self.set_vexpand(False)
16
elif orientation == Gtk.Orientation.HORIZONTAL:
17
self.set_vexpand(True)
18
self.set_hexpand(False)
19
20
self.drag_source = Gtk.DragSource(actions=Gdk.DragAction.MOVE)
21
self.drag_source.connect("prepare", self.provide_drag_data)
22
self.drag_source.connect("drag-begin", self.drag_begin)
23
self.drag_source.connect("drag-cancel", self.drag_cancel)
24
25
def provide_drag_data(self, source: Gtk.DragSource, x: float, y: float):
26
app = self.get_root().get_application()
27
app.drags[id(self)] = self
28
value = GObject.Value()
29
value.init(GObject.TYPE_UINT64)
30
value.set_uint64(id(self))
31
print(value)
32
return Gdk.ContentProvider.new_for_value(value)
33
34
def drag_begin(self, source: Gtk.DragSource, drag: Gdk.Drag):
35
paintable = Gtk.WidgetPaintable.new(self).get_current_image()
36
source.set_icon(paintable, 0, 0)
37
self.hide()
38
39
def drag_cancel(self, source: Gtk.DragSource, drag: Gdk.Drag, reason: Gdk.DragCancelReason):
40
self.show()
41
return False
42
43
def get_config(self):
44
return {}
45
46
def set_panel_position(self, position: Gtk.PositionType):
47
return
48
49
def make_draggable(self):
50
self.add_controller(self.drag_source)
51
52
def restore_drag(self):
53
self.remove_controller(self.drag_source)
54
55
56
def get_panel_position(applet: Applet) -> Gtk.PositionType:
57
return applet.get_root().position
58
59
60
OPPOSITE_POSITION = {
61
Gtk.PositionType.TOP: Gtk.PositionType.BOTTOM,
62
Gtk.PositionType.BOTTOM: Gtk.PositionType.TOP,
63
Gtk.PositionType.LEFT: Gtk.PositionType.RIGHT,
64
Gtk.PositionType.RIGHT: Gtk.PositionType.LEFT,
65
}
66
67
POSITION_TO_ARROW = {
68
Gtk.PositionType.TOP: Gtk.ArrowType.UP,
69
Gtk.PositionType.BOTTOM: Gtk.ArrowType.DOWN,
70
Gtk.PositionType.LEFT: Gtk.ArrowType.LEFT,
71
Gtk.PositionType.RIGHT: Gtk.ArrowType.RIGHT,
72
}
73