This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dockitem.py
164 lines (134 loc) · 5.67 KB
/
dockitem.py
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
159
160
161
162
163
164
# -*- coding: utf-8 -*-
#
# Copyright © 2010 etk.docking Contributors
#
# This file is part of etk.docking.
#
# etk.docking is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# etk.docking 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with etk.docking. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import, division
from logging import getLogger
import gobject
import gtk
import gtk.gdk as gdk
class DockItem(gtk.Bin):
__gtype_name__ = 'EtkDockItem'
__gproperties__ = {'icon-name': (gobject.TYPE_STRING,
'icon name',
'icon name',
'',
gobject.PARAM_READWRITE),
'title': (gobject.TYPE_STRING,
'icon name',
'icon name',
'',
gobject.PARAM_READWRITE),
'title-tooltip-text': (gobject.TYPE_STRING,
'title tooltip text',
'title tooltip text',
'',
gobject.PARAM_READWRITE)}
def __init__(self, icon_name='', title='', title_tooltip_text=''):
gtk.Bin.__init__(self)
self.set_flags(self.flags() | gtk.NO_WINDOW)
# Initialize logging
self.log = getLogger('<%s object at %s>' % (self.__gtype_name__, hex(id(self))))
# Internal housekeeping
self._icon_name = icon_name
self._title = title
self._title_tooltip_text = title_tooltip_text
############################################################################
# GObject
############################################################################
def do_get_property(self, pspec):
if pspec.name == 'icon-name':
return self.get_icon_name()
elif pspec.name == 'title':
return self.get_title()
elif pspec.name == 'title-tooltip-text':
return self.get_title_tooltip_text()
def do_set_property(self, pspec, value):
if pspec.name == 'icon-name':
self.set_icon_name(value)
elif pspec.name == 'title':
self.set_title(value)
elif pspec.name == 'title-tooltip-text':
self.set_title_tooltip_text(value)
def get_icon_name(self):
return self._icon_name
def set_icon_name(self, value):
self._icon_name = value
self.notify('icon-name')
def get_title(self):
return self._title
def set_title(self, value):
self._title = value
self.notify('title')
def get_title_tooltip_text(self):
return self._title_tooltip_text
def set_title_tooltip_text(self, value):
self._title_tooltip_text = value
self.notify('title-tooltip-text')
############################################################################
# GtkWidget
############################################################################
def do_realize(self):
self.set_flags(self.flags() | gtk.REALIZED)
self.window = gdk.Window(self.get_parent_window(),
x = self.allocation.x,
y = self.allocation.y,
width = self.allocation.width,
height = self.allocation.height,
window_type = gdk.WINDOW_CHILD,
wclass = gdk.INPUT_OUTPUT,
event_mask = (gdk.EXPOSURE_MASK))
self.window.set_user_data(self)
self.style.attach(self.window)
self.style.set_background(self.window, gtk.STATE_NORMAL)
if self.child:
self.child.set_parent_window(self.window)
def do_unrealize(self):
self.window.set_user_data(None)
self.window.destroy()
gtk.Bin.do_unrealize(self)
def do_map(self):
gtk.Bin.do_map(self)
if self.window:
self.window.show()
def do_unmap(self):
gtk.Bin.do_unmap(self)
self.window.hide()
def do_show(self):
gtk.Bin.do_show(self)
self.child.show()
def do_hide(self):
gtk.Bin.do_hide(self)
self.child.hide()
def do_size_request(self, requisition):
requisition.width = self.border_width * 2
requisition.height = self.border_width * 2
if self.child:
(w, h) = self.child.size_request()
requisition.width += w
requisition.height += h
def do_size_allocate(self, allocation):
self.allocation = allocation
if self.child:
child_allocation = gdk.Rectangle()
child_allocation.x = self.border_width
child_allocation.y = self.border_width
child_allocation.width = max(self.allocation.width - self.border_width, 0)
child_allocation.height = max(self.allocation.height - self.border_width, 0)
self.child.size_allocate(child_allocation)
if self.flags() & gtk.REALIZED:
self.window.move_resize(*self.allocation)