-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockbarx_mate_applet.in
140 lines (125 loc) · 5.62 KB
/
dockbarx_mate_applet.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python3
# dockbarx_mate_applet
#
# Copyright 2008, 2009, 2010 Aleksey Shaferov and Matias Sars
# Copyright 2017 Alexey Hohlov
#
# DockbarX is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DockbarX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with dockbar. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version("Gtk", "3.0")
gi.require_version('MatePanelApplet', '4.0')
from gi.repository import Gtk, GLib
from gi.repository import MatePanelApplet
try:
import sys
import dockbarx.dockbar
from dockbarx.log import *
except Exception as e:
print(e)
sys.exit(1)
class DockbarMateApplet(object):
def __init__(self, applet, iid):
self.applet = applet
self.size = None
self.dockbar = dockbarx.dockbar.DockBar(self)
applet.set_flags(MatePanelApplet.AppletFlags.HAS_HANDLE | \
MatePanelApplet.AppletFlags.EXPAND_MINOR | \
MatePanelApplet.AppletFlags.EXPAND_MAJOR)
orients = {MatePanelApplet.AppletOrient.DOWN: "down",
MatePanelApplet.AppletOrient.UP: "up",
MatePanelApplet.AppletOrient.LEFT: "left",
MatePanelApplet.AppletOrient.RIGHT: "right"}
self.dockbar.set_orient(orients[applet.get_orient()])
menu_actions = [("About", Gtk.STOCK_ABOUT, _("About"), None, None, self.dockbar.on_ppm_about),
("Pref", Gtk.STOCK_PREFERENCES, _("Preferences"), None, None, self.dockbar.on_ppm_pref),
("Reload", Gtk.STOCK_REFRESH, _("Refresh"), None, None, self.dockbar.reload)]
actiongroup = Gtk.ActionGroup.new("DockBarXAppletActions")
#actiongroup.set_translation_domain(dockbarx.defs.GETTEXT_PACKAGE)
actiongroup.add_actions(menu_actions, None)
applet.setup_menu_from_file("%PREFIX%/share/mate-panel/ui/dockbarx-applet-menu.xml", actiongroup)
# Set the applet coordinates to be way ofscreen until they've
# been set correctly by a size allocate call.
self.applet_origin_x = -1000
self.applet_origin_y = -1000
applet.connect("delete-event", self.__cleanup)
applet.show_all()
# Most of initializion must happen after dockbarx is
# realized since python mateapplets crash if it
# takes too long to realize.
GLib.idle_add(self.__load_on_realized)
def __load_on_realized(self):
# Wait while gtk events are pending.
while Gtk.events_pending():
Gtk.main_iteration()
# Load DockbarX.
self.dockbar.load()
# Add it to the applet.
self.applet.add(self.dockbar.get_container())
self.applet.show_all()
# Connect events.
self.applet.connect("size-allocate", self.__on_applet_size_alloc)
#self.applet.connect("change_background", self.__on_change_background)
self.applet.connect("change-orient", self.__on_change_orient)
def __on_applet_size_alloc(self, widget, allocation):
if self.applet.get_orient() in (MatePanelApplet.AppletOrient.DOWN,
MatePanelApplet.AppletOrient.UP):
size = allocation.height
else:
size = allocation.width
if self.size != size:
self.dockbar.set_size(size)
self.size = size
if not widget.get_window():
return
#x,y = widget.get_window().get_origin()
x,y = widget.get_window().get_root_coords(0, 0)
if x == self.applet_origin_x or y == self.applet_origin_y:
# Nothing moved.
return
# Applet and/or panel moved,
# icon_geo needs to be updated.
self.applet_origin_x = x
self.applet_origin_y = y
self.dockbar.dockbar_moved()
def __on_change_orient(self, arg1, data):
orients = {MatePanelApplet.AppletOrient.DOWN: "down",
MatePanelApplet.AppletOrient.UP: "up",
MatePanelApplet.AppletOrient.LEFT: "left",
MatePanelApplet.AppletOrient.RIGHT: "right"}
self.applet.remove(self.dockbar.get_container())
self.dockbar.set_orient(orients[self.applet.get_orient()])
self.applet.add(self.dockbar.get_container())
def __on_change_background(self, applet, type, color, pixmap):
applet.set_style(None)
rc_style = Gtk.RcStyle()
applet.modify_style(rc_style)
if type == MatePanelApplet.AppletBackgroundType.COLOR_BACKGROUND:
applet.modify_bg(Gtk.StateType.NORMAL, color)
elif type == MatePanelApplet.AppletBackgroundType.PIXMAP_BACKGROUND:
style = applet.style
style.bg_pixmap[Gtk.StateType.NORMAL] = pixmap
applet.set_style(style)
return
def readd_container (self, container):
self.applet.add(container)
container.show_all()
def __cleanup(self,event):
if hasattr(self.dockbar, "destroy"):
self.dockbar.destroy()
def applet_factory(applet, iid, data):
DockbarMateApplet(applet, iid)
return True
MatePanelApplet.Applet.factory_main("DockbarXAppletFactory", True,
MatePanelApplet.Applet.__gtype__,
applet_factory, None)