22
22
from math import pi as PI
23
from gi.repository import Gtk, Gdk, GObject
23
from gi.repository import Gtk, Gdk, GObject, PangoCairo
25
25
import softwarecenter.paths
26
from softwarecenter.ui.gtk3.em import em
26
27
from softwarecenter.ui.gtk3.drawing import rounded_rect
156
158
if not self.is_animating() or not self.transaction_count: return
157
160
# paint transactions bubble
158
162
# get the layout extents and calc the bubble size
159
163
ex = self.layout.get_pixel_extents()[1]
160
164
x = (a.width - self.icon.get_width()) / 2 + self.icon.get_width() - ex.width + 2
161
165
y = (a.height - self.icon.get_height()) / 2 + self.icon.get_height() - ex.height + 2
162
166
w = ex.width + 2*self.BUBBLE_XPADDING
163
167
h = ex.height + 2*self.BUBBLE_YPADDING
170
if border_radius > self.BUBBLE_MAX_BORDER_RADIUS:
171
border_radius = self.BUBBLE_MAX_BORDER_RADIUS
164
173
# paint background
165
rounded_rect(cr, x+1, y+1, w-2, h-2, self.BUBBLE_BORDER_RADIUS)
166
cr.set_source_rgba(0,0,0,0.75)
174
context = widget.get_style_context()
176
color = context.get_background_color(Gtk.StateFlags.SELECTED)
177
rounded_rect(cr, x+1, y+1, w-2, h-2, border_radius)
178
Gdk.cairo_set_source_rgba(cr, color)
169
#~ rounded_rect(cr, x+0.5, y+0.5, w-1, h-1, self.BUBBLE_BORDER_RADIUS)
170
#~ cr.set_source_rgba(1,1,1, 0.85)
171
#~ cr.set_line_width(1)
183
rounded_rect(cr, x+1.5, y+1.5, w-3, h-3, border_radius-1)
184
cr.set_source_rgb(1,1,1)
174
Gtk.render_layout(widget.get_style_context(), cr,
175
x + self.BUBBLE_XPADDING,
176
y + self.BUBBLE_YPADDING,
190
cr.translate(x+(w-ex.width)*0.5, y+(h-ex.height)*0.5)
192
PangoCairo.layout_path(cr, self.layout)
193
cr.set_source_rgba(0,0,0,0.6)
195
Gtk.render_layout(context, cr, 0, 0, self.layout)
180
199
def set_transaction_count(self, count):
181
200
if count == self.transaction_count: return
182
201
self.transaction_count = count
183
m = '<span font_desc="%s">%i</span>' % (self.BUBBLE_FONT_DESC,
202
m = '<span font_desc="%s" color="%s">%i</span>' % (self.BUBBLE_FONT_DESC,
185
205
self.layout.set_markup(m, -1)
186
206
self.queue_draw()
190
210
if __name__ == "__main__":
211
softwarecenter.paths.datadir = os.path.join(os.getcwd(), 'data')
191
213
win = Gtk.Window()
214
win.set_border_width(20)
192
215
hb = Gtk.HBox(spacing=12)
194
217
ico = SymbolicIcon("available")