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.15 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
self.hide()
36
37
def drag_cancel(self, source: Gtk.DragSource, drag: Gdk.Drag, reason: Gdk.DragCancelReason):
38
self.show()
39
return False
40
41
def get_config(self):
42
return {}
43
44
def set_panel_position(self, position: Gtk.PositionType):
45
return
46
47
def make_draggable(self):
48
self.add_controller(self.drag_source)
49
50
def restore_drag(self):
51
self.remove_controller(self.drag_source)
52
53
54
def get_panel_position(applet: Applet) -> Gtk.PositionType:
55
return applet.get_root().position
56
57
58
OPPOSITE_POSITION = {
59
Gtk.PositionType.TOP: Gtk.PositionType.BOTTOM,
60
Gtk.PositionType.BOTTOM: Gtk.PositionType.TOP,
61
Gtk.PositionType.LEFT: Gtk.PositionType.RIGHT,
62
Gtk.PositionType.RIGHT: Gtk.PositionType.LEFT,
63
}
64
65
POSITION_TO_ARROW = {
66
Gtk.PositionType.TOP: Gtk.ArrowType.UP,
67
Gtk.PositionType.BOTTOM: Gtk.ArrowType.DOWN,
68
Gtk.PositionType.LEFT: Gtk.ArrowType.LEFT,
69
Gtk.PositionType.RIGHT: Gtk.ArrowType.RIGHT,
70
}
71