-
Notifications
You must be signed in to change notification settings - Fork 40
/
dockbarx_factory
executable file
·158 lines (137 loc) · 5.7 KB
/
dockbarx_factory
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/python2
# dockbarx_factory
#
# Copyright 2008, 2009, 2010 Aleksey Shaferov and Matias Sars
#
# 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/>.
from dockbarx.log import *
import sys
if not (len(sys.argv) == 2 and sys.argv[1] == "run-in-window"):
log_to_file()
sys.stderr = StdErrWrapper()
sys.stdout = StdOutWrapper()
import pygtk
pygtk.require("2.0")
import gtk
import gnomeapplet
import dockbarx.dockbar
import gobject
class DockBarWindow():
"""DockBarWindow sets up the window if run-in-window is used."""
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_default_size(200,40)
self.window.show()
self.window.set_property("skip-taskbar-hint",True)
self.window.set_keep_above(True)
self.window.connect ("destroy",self.__destroy)
applet = gnomeapplet.Applet()
applet.reparent(self.window)
self.dockbar = dockbarx.dockbar.DockBar(self)
def __on_pref_clicked(self, *args):
self.dockbar.open_preference()
def __destroy (self,widget,data=None):
gtk.main_quit()
def main(self):
gtk.main()
class DockbarGnomeapplet():
def __init__(self, applet):
self.applet = applet
self.dockbar = dockbarx.dockbar.DockBar(applet)
applet.set_applet_flags(gnomeapplet.HAS_HANDLE | \
gnomeapplet.EXPAND_MINOR | \
gnomeapplet.EXPAND_MAJOR)
orients = {gnomeapplet.ORIENT_DOWN: "down",
gnomeapplet.ORIENT_UP: "up",
gnomeapplet.ORIENT_LEFT: "left",
gnomeapplet.ORIENT_RIGHT: "right"}
self.dockbar.set_orient(orients[applet.get_orient()])
self.pp_menu_xml = """
<popup name="button3">
<menuitem name="About Item" verb="About" stockid="gtk-about" />
<menuitem name="Preferences" verb="Pref" stockid="gtk-properties" />
<menuitem name="Reload" verb="Reload" stockid="gtk-refresh" />
</popup>
"""
self.pp_menu_verbs = [("About", self.dockbar.on_ppm_about),
("Pref", self.dockbar.on_ppm_pref),
("Reload", self.dockbar.reload)]
applet.setup_menu(self.pp_menu_xml, self.pp_menu_verbs,None)
# 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)
# Background bug workaround
applet.set_background_widget(applet)
applet.show_all()
# Most of initializion must happen after dockbarx is
# realized since python gnomeapplets crash if it
# takes too long to realize.
gobject.idle_add(self.__load_on_realized)
def __load_on_realized(self):
# Wait while gtk events are pending.
while gtk.events_pending():
gtk.main_iteration(False)
# Load DockbarX.
self.dockbar.load()
# Add it to the applet.
self.applet.add(self.dockbar.get_container())
# 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 not widget.window:
return
x,y = widget.window.get_origin()
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 = {gnomeapplet.ORIENT_DOWN: "down",
gnomeapplet.ORIENT_UP: "up",
gnomeapplet.ORIENT_LEFT: "left",
gnomeapplet.ORIENT_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 == gnomeapplet.COLOR_BACKGROUND:
applet.modify_bg(gtk.STATE_NORMAL, color)
elif type == gnomeapplet.PIXMAP_BACKGROUND:
style = applet.style
style.bg_pixmap[gtk.STATE_NORMAL] = pixmap
applet.set_style(style)
return
def __cleanup(self,event):
pass
def dockbar_factory(applet, iid):
DockbarGnomeapplet(applet)
return True
if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
dockbarwin = DockBarWindow()
dockbarwin.main()
else:
gnomeapplet.bonobo_factory("OAFIID:GNOME_DockBarXApplet_Factory",
gnomeapplet.Applet.__gtype__,
"dockbar applet", "0", dockbar_factory)