mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-19 20:38:03 +01:00
1724798: labels are not aligned
implemented the 'align' parameter to the Application.addLabel method. the pywmhelpers.addString function now returns the x-size of the string. moved all labels in pywmdatetime one pixel to the left.
This commit is contained in:
@@ -114,17 +114,18 @@ class Application(wmoo.Application):
|
|||||||
bg=0, fg=2, palette=palette,
|
bg=0, fg=2, palette=palette,
|
||||||
background=background,
|
background=background,
|
||||||
debug=options.debug)
|
debug=options.debug)
|
||||||
|
|
||||||
|
|
||||||
if options.antialiased:
|
if options.antialiased:
|
||||||
self.addLabel('date', orig=(5,24), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('date', orig=(4,24), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('day', orig=(5,36), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('day', orig=(4,36), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('week', orig=(5,48), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('week', orig=(4,48), size=(54,10), align=wmoo.CENTRE)
|
||||||
else:
|
else:
|
||||||
self.addLabel('time', orig=(5, 5), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('time', orig=(4, 5), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('time2', orig=(5,16), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('time2', orig=(4,16), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('date', orig=(5,27), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('date', orig=(4,27), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('day', orig=(5,38), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('day', orig=(4,38), size=(54,10), align=wmoo.CENTRE)
|
||||||
self.addLabel('week', orig=(5,49), size=(54,10), align=wmoo.CENTRE)
|
self.addLabel('week', orig=(4,49), size=(54,10), align=wmoo.CENTRE)
|
||||||
|
|
||||||
self.timeFmt = options.timeformat
|
self.timeFmt = options.timeformat
|
||||||
self.dateFmt = options.dateformat
|
self.dateFmt = options.dateformat
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ def addString(s, x, y, xOffset=0, yOffset=0, width=None, height=None, drawable=N
|
|||||||
xOffset, yOffset, width, height,
|
xOffset, yOffset, width, height,
|
||||||
drawable)
|
drawable)
|
||||||
lastW += w
|
lastW += w
|
||||||
|
return lastW
|
||||||
|
|
||||||
def getVertSpacing(numLines, margin, height, yOffset):
|
def getVertSpacing(numLines, margin, height, yOffset):
|
||||||
"""Return the optimal spacing between a number of lines.
|
"""Return the optimal spacing between a number of lines.
|
||||||
|
|||||||
@@ -52,23 +52,41 @@ class Application:
|
|||||||
pixmapwidth = max(self._char_width * len(text), size[0])
|
pixmapwidth = max(self._char_width * len(text), size[0])
|
||||||
import pywmgeneral
|
import pywmgeneral
|
||||||
labelPixmap = pywmgeneral.Drawable(pixmapwidth, self._char_height)
|
labelPixmap = pywmgeneral.Drawable(pixmapwidth, self._char_height)
|
||||||
self._elements[labelId] = [orig, size, pixmapwidth, 0, labelPixmap]
|
self._elements[labelId] = {
|
||||||
|
'orig': orig,
|
||||||
|
'size': size,
|
||||||
|
'pixw': pixmapwidth,
|
||||||
|
'offset': 0,
|
||||||
|
'pixmap': labelPixmap,
|
||||||
|
'align': align}
|
||||||
self.setLabelText(labelId, text)
|
self.setLabelText(labelId, text)
|
||||||
|
|
||||||
def setLabelText(self, labelId, text):
|
def setLabelText(self, labelId, text):
|
||||||
"""updates the drawable associated with labelId
|
"""updates the drawable associated with labelId
|
||||||
"""
|
"""
|
||||||
(orig_x,orig_y), (size_x, size_y), width, offset, pixmap = self._elements[labelId]
|
lbl = self._elements[labelId]
|
||||||
|
(orig_x,orig_y) = lbl['orig']
|
||||||
|
(size_x, size_y) = lbl['size']
|
||||||
newwidth = self._char_width * len(text)
|
newwidth = self._char_width * len(text)
|
||||||
if newwidth > width:
|
if newwidth > lbl['pixw']:
|
||||||
import pywmgeneral
|
import pywmgeneral
|
||||||
pixmap = pywmgeneral.Drawable(newwidth, self._char_height)
|
lbl['pixmap'] = pywmgeneral.Drawable(newwidth, self._char_height)
|
||||||
self._elements[labelId][4] = pixmap
|
lbl['pixw'] = newwidth
|
||||||
self._elements[labelId][2] = newwidth
|
lbl['offset'] = 0
|
||||||
self._elements[labelId][3] = 0
|
lbl['pixmap'].xClear()
|
||||||
pixmap.xClear()
|
lbl['pixmap'].xCopyAreaToWindow(0, 0, size_x, size_y, orig_x, orig_y)
|
||||||
pywmhelpers.addString(text, 0, 0, drawable=pixmap)
|
w = pywmhelpers.addString(text, 0, 0, drawable=lbl['pixmap'])
|
||||||
pixmap.xCopyAreaToWindow(0, 0, size_x, size_y, orig_x, orig_y)
|
dx = 0
|
||||||
|
if w < size_x:
|
||||||
|
spare = size_x - w
|
||||||
|
if lbl['align'] == RIGHT:
|
||||||
|
dx = spare
|
||||||
|
elif lbl['align'] == CENTRE:
|
||||||
|
dx = int(spare/2)
|
||||||
|
else:
|
||||||
|
w = size_x
|
||||||
|
|
||||||
|
lbl['pixmap'].xCopyAreaToWindow(0, 0, w, size_y, orig_x+dx, orig_y)
|
||||||
|
|
||||||
def addButton(self, buttonId, orig, size,
|
def addButton(self, buttonId, orig, size,
|
||||||
callback1, callback2=None, callback3=None,
|
callback1, callback2=None, callback3=None,
|
||||||
@@ -103,15 +121,15 @@ class Application:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def redraw(self):
|
def redraw(self):
|
||||||
for labelId in self._elements:
|
for lbl in self._elements.values():
|
||||||
(orig_x,orig_y), (size_x, size_y), width, offset, pixmap = self._elements[labelId]
|
(orig_x,orig_y) = lbl['orig']
|
||||||
if size_x < width:
|
(size_x, size_y) = lbl['size']
|
||||||
pixmap.xCopyAreaToWindow(offset, 0, size_x, size_y, orig_x, orig_y)
|
if lbl['size'][0] < lbl['pixw']:
|
||||||
if offset == width:
|
lbl['pixmap'].xCopyAreaToWindow(lbl['offset'], 0, size_x, size_y, orig_x, orig_y)
|
||||||
offset = -size_x
|
if lbl['offset'] == lbl['pixw']:
|
||||||
|
lbl['offset'] = -size_x
|
||||||
else:
|
else:
|
||||||
offset += 1
|
lbl['offset'] += 1
|
||||||
self._elements[labelId][3] = offset
|
|
||||||
self.update()
|
self.update()
|
||||||
pywmhelpers.redraw()
|
pywmhelpers.redraw()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user