def onExposeEvent(self, widget=None, event=None): cr = self.window.cairo_create() self.drawBg(cr) self.drawTextList( cr, [core.getWeekDayN(i) for i in range(7)], ) self.drawCursorFg(cr)
def trayUpdate(self, gdate=None, checkDate=True):## FIXME if gdate==None: gdate = localtime()[:3] if self.lastGDate!=gdate or not checkDate: jd = core.modules[core.DATE_GREG].to_jd(*gdate) if core.primaryMode==core.DATE_GREG: ddate = gdate else: ddate = core.modules[core.primaryMode].jd_to(jd) self.lastGDate = gdate ui.todayCell = ui.cellCache.getTodayCell() imPath = ui.trayImageHoli if ui.todayCell.holiday else ui.trayImage self.pmap.load(imPath) try: self.painter.end() except: pass self.painter.begin(self.pmap) w = self.pmap.width() h = self.pmap.height() self.painter.drawText(qc.QPoint(0, h-2), _(ddate[2])) self.iconT.setPixmap(self.pmap) self.icon.setWidget(self.iconT) #self.icon.setGeometry(qc.QRectF(0, 0, w, h)) #self.iconT.setGeometry(qc.QRect(0, 0, w, h)) self.iconT.setFixedWidth(w) #self.iconT.setFixedHeight(h) ## position of left lower corner of text ^^ ## trayTextColor, ui.trayFont, ui.fontUseDefault ?????? #################### wd = core.getWeekDay(*ddate) tt = core.getWeekDayN(wd) #if ui.pluginsTextTray:##????????? # sep = _(',')+' ' #else: sep = u'<br>' for item in ui.shownCals: if item['enable']: mode = item['mode'] (y, m, d) = ui.todayCell.dates[mode] tt += u'%s%s %s %s'%(sep, _(d), core.getMonthName(mode, m), _(y)) if ui.pluginsTextTray: text = ui.todayCell.pluginsText if text!='': tt += u'%s%s'%(sep, text.replace(u'\t', sep)) #???????????? if rtl:## tags: div, p, body tt = u'<p dir="rtl">%s</p>'%tt #else: # tt = '<p dir="ltr">%s</p>'%tt self.tooltipContent.setMainText('') ## self.name self.tooltipContent.setSubText(tt) self.tooltipMgr.setContent(self.papplet.applet, self.tooltipContent) return True
def onExposeEvent(self, widget=None, event=None): cr = self.getContext() self.drawBg(cr) self.drawTextList( cr, [ [ (core.getWeekDayN(i), ''), ] for i in range(7) ], ) self.drawCursorFg(cr)
def drawCairo(self, cr): if not self.data: return t0 = now() w = self.get_allocation().width h = self.get_allocation().height cr.rectangle(0, 0, w, h) fillColor(cr, ui.bgColor) textColor = ui.textColor gridColor = ui.mcalGridColor ## FIXME ### #classBounds = self.term.classTimeBounds titles, tmfactors = self.term.getClassBoundsFormatted() ### weekDayLayouts = [] weekDayLayoutsWidth = [] for j in range(7): layout = newTextLayout(self, core.getWeekDayN(j)) layoutW, layoutH = layout.get_pixel_size() weekDayLayouts.append(layout) weekDayLayoutsWidth.append(layoutW) leftMargin = max(weekDayLayoutsWidth) + 6 ### topMargin = 20 ## FIXME ### Calc Coordinates: ycenters(list), dy(float) ycenters = [ topMargin + (h - topMargin) * (1.0 + 2 * i) / 14.0 for i in range(7) ] ## centers y dy = (h - topMargin) / 7.0 ## delta y ### Draw grid ## tmfactors includes 0 at the first, and 1 at the end setColor(cr, gridColor) ## for i in range(7): cr.rectangle(0, ycenters[i] - dy / 2.0, w, 1) cr.fill() ## for factor in tmfactors[:-1]: x = leftMargin + factor * (w - leftMargin) if rtl: x = w - x cr.rectangle(x, 0, 1, h) cr.fill() ### setColor(cr, textColor) for i, title in enumerate(titles): layout = newTextLayout(self, title) layoutW, layoutH = layout.get_pixel_size() ## dx = (w - leftMargin) * (tmfactors[i + 1] - tmfactors[i]) if dx < layoutW: continue ## factor = (tmfactors[i] + tmfactors[i + 1]) / 2.0 x = factor * (w - leftMargin) + leftMargin if rtl: x = w - x x -= layoutW / 2.0 ## y = (topMargin - layoutH) / 2.0 - 1 ## cr.move_to(x, y) cr.show_layout(layout) ### for j in range(7): layout = weekDayLayouts[j] layoutW, layoutH = layout.get_pixel_size() x = leftMargin / 2.0 if rtl: x = w - x x -= layoutW / 2.0 ## y = topMargin + (h - topMargin) * (j + 0.5) / 7.0 - layoutH / 2.0 ## cr.move_to(x, y) cr.show_layout(layout) for j in range(7): wd = (j + core.firstWeekDay) % 7 for i, dayData in enumerate(self.data[wd]): textList = [] for classData in dayData: text = classData['name'] if classData['weekNumMode']: text += '(<span color="#f00">' + _( classData['weekNumMode'].capitalize()) + '</span>)' textList.append(text) dx = (w - leftMargin) * (tmfactors[i + 1] - tmfactors[i]) layout = newTextLayout(self, '\n'.join(textList), maxSize=(dx, dy)) layoutW, layoutH = layout.get_pixel_size() ## factor = (tmfactors[i] + tmfactors[i + 1]) / 2.0 x = factor * (w - leftMargin) + leftMargin if rtl: x = w - x x -= layoutW / 2.0 ## y = topMargin + (h - topMargin) * (j + 0.5) / 7.0 - layoutH / 2.0 ## cr.move_to(x, y) cr.show_layout(layout)
def drawCairo(self, cr): if not self.data: return t0 = time.time() w = self.allocation.width h = self.allocation.height cr.rectangle(0, 0, w, h) fillColor(cr, ui.bgColor) textColor = ui.shownCals[0]['color'] gridColor = ui.gridColor ### #classBounds = self.term.classTimeBounds (titles, tmfactors) = self.term.getClassBoundsFormatted() ### weekDayLayouts = [] weekDayLayoutsWidth = [] for j in range(7): layout = newTextLayout(self, core.getWeekDayN(j)) layoutW, layoutH = layout.get_pixel_size() weekDayLayouts.append(layout) weekDayLayoutsWidth.append(layoutW) leftMargin = max(weekDayLayoutsWidth) + 6 ### topMargin = 20 ## FIXME ### Calc Coordinates: ycenters(list), dy(float) ycenters = [ topMargin + (h-topMargin)*(1.0+2*i)/14.0 for i in xrange(7) ] ## centers y dy = (h-topMargin)/7.0 ## delta y ### Draw grid ## tmfactors includes 0 at the first, and 1 at the end setColor(cr, ui.gridColor) ## for i in xrange(7): cr.rectangle(0, ycenters[i]-dy/2.0, w, 1) cr.fill() ## for factor in tmfactors[:-1]: x = leftMargin + factor*(w-leftMargin) if rtl: x = w - x cr.rectangle(x, 0, 1, h) cr.fill() ### setColor(cr, textColor) for i,title in enumerate(titles): layout = newTextLayout(self, title) (layoutW, layoutH) = layout.get_pixel_size() ## dx = (w - leftMargin) * (tmfactors[i+1] - tmfactors[i]) if dx < layoutW: continue ## factor = (tmfactors[i] + tmfactors[i+1])/2.0 x = factor*(w-leftMargin) + leftMargin if rtl: x = w - x x -= layoutW/2.0 ## y = (topMargin-layoutH)/2.0 - 1 ## cr.move_to(x, y) cr.show_layout(layout) ### for j in range(7): layout = weekDayLayouts[j] (layoutW, layoutH) = layout.get_pixel_size() x = leftMargin/2.0 if rtl: x = w - x x -= layoutW/2.0 ## y = topMargin + (h-topMargin)*(j+0.5)/7.0 - layoutH/2.0 ## cr.move_to(x, y) cr.show_layout(layout) for j in range(7): wd = (j+core.firstWeekDay)%7 for i,dayData in enumerate(self.data[wd]): textList = [] for classData in dayData: text = classData['name'] if classData['weekNumMode']: text += '(<span color="#f00">' + _(classData['weekNumMode'].capitalize()) + '</span>)' textList.append(text) dx = (w - leftMargin) * (tmfactors[i+1] - tmfactors[i]) layout = newTextLayout(self, '\n'.join(textList), maxSize=(dx, dy)) (layoutW, layoutH) = layout.get_pixel_size() ## factor = (tmfactors[i] + tmfactors[i+1])/2.0 x = factor*(w-leftMargin) + leftMargin if rtl: x = w - x x -= layoutW/2.0 ## y = topMargin + (h-topMargin)*(j+0.5)/7.0 - layoutH/2.0 ## cr.move_to(x, y) cr.show_layout(layout)
def exportToHtml(fpath, monthsStatus, title=''): ##################### Options: format = ((2, 'SUB'), (0, None), (1, 'SUB')) ## (dateMode, htmlTag) sizeMap = lambda size: size*0.25 - 0.5 ## ??????????????? sep = ' ' pluginsTextSep = ' <B>ـ</B> ' pluginsTextPerLine = True ## description of each day in one line ##################### dates = ui.shownCals ##################### bgColor = rgbToHtml(*ui.bgColor) inactiveColor = rgbToHtml(*colorComposite(ui.inactiveColor, ui.bgColor)) borderColor= rgbToHtml(*colorComposite(ui.borderColor, ui.bgColor)) borderTextColor = rgbToHtml(*ui.borderTextColor) holidayColor = rgbToHtml(*ui.holidayColor) colors = [rgbToHtml(*x['color']) for x in dates] if rtl: DIR = 'RTL' else: DIR = 'LRT' text = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE>%s</TITLE> </HEAD> <BODY LANG="%s" DIR="%s" BGCOLOR="%s">\n'''%(title, core.langSh, DIR, bgColor) for status in monthsStatus: mDesc = getMonthDesc(status).split('\n') text += ' <P>\n' for i in xrange(len(dates)): if dates[i]['enable']: text += ' <FONT COLOR="%s">%s</FONT>\n <BR>\n'%(colors[i], mDesc[i]) text += ' </P>\n' text += ''' <TABLE WIDTH=100%% BGCOLOR="%s" BORDER=%s BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0> <TR VALIGN=TOP>\n'''\ %(bgColor, int(ui.mcalGrid)) text += ''' <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER></P> </TD>\n'''%borderColor## what text???????? for j in xrange(7): text += ''' <TD WIDTH=13%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n'''%(borderColor, borderTextColor, core.getWeekDayN(j)) pluginsText = '<P><FONT COLOR="%s">\n'%colors[0] text += ' </TR>\n' for i in xrange(6): text += ''' <TR VALIGN=TOP> <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n'''%(borderColor, borderTextColor, _(status.weekNum[i])) for j in xrange(7): cell = status[i][j] text += ' <TD WIDTH=13%>\n <P DIR="LTR" ALIGN=CENTER>\n' for (ind, tag) in format: if not dates[ind]['enable']: continue mode = dates[ind]['mode'] day = _(cell.dates[mode][2], mode)## , 2 font = dates[ind]['font'] face = font[0] if font[1]: face += ' Bold' if font[2]: face += ' Underline' size = str(sizeMap(font[3])) if cell.month != status.month: if ind==0: text += ' ' if tag: text += '<%s>'%tag text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>'%( inactiveColor, face, size, day, ) if tag: text += '</%s>'%tag text += '\n' break else: continue text += ' ' if tag: text += '<%s>'%tag if ind==0 and cell.holiday: color = holidayColor else: color = colors[ind] text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>'%(color, face, size, day) if tag: text += '</%s>'%tag text += '\n' #text += sep##??????????? text += ' </P>\n </TD>\n' if cell.month == status.month: if cell.holiday: color = holidayColor else: color = colors[0] t = cell.pluginsText.replace('\n', pluginsTextSep) if t: pluginsText += '<B><FONT COLOR="%s">%s</FONT>:</B> <SMALL>%s</SMALL>'%( color, _(cell.dates[core.primaryMode][2]), t, ) if pluginsTextPerLine: pluginsText += '<BR>\n' else: pluginsText += ' \n' text += ' </TR>\n' pluginsText += ' </FONT></P>\n' text += ' </TABLE>\n' text = toStr(text) ## needed for windows text += pluginsText text += '\n<P STYLE="border-bottom: 5pt double %s"></P>\n'%colors[0] text += ''' <P> <FONT COLOR="%s">%s <A HREF="%s">%s</A> %s %s</FONT> </P> </BODY> </HTML>'''%( colors[0], toStr(_('Generated by')), core.homePage, core.APP_DESC, toStr(_('version')), core.VERSION, ) open(fpath, 'w').write(text)
def exportToHtml(fpath, monthsStatus, title=''): ##################### Options: format = ((2, 'SUB'), (0, None), (1, 'SUB')) ## (dateMode, htmlTag) sizeMap = lambda size: size * 0.25 - 0.5 ## ??????????????? sep = ' ' pluginsTextSep = ' <B>ـ</B> ' pluginsTextPerLine = True ## description of each day in one line ##################### bgColor = rgbToHtml(*ui.bgColor) inactiveColor = rgbToHtml(*colorComposite(ui.inactiveColor, ui.bgColor)) borderColor = rgbToHtml(*colorComposite(ui.borderColor, ui.bgColor)) borderTextColor = rgbToHtml(*ui.borderTextColor) textColor = rgbToHtml(*ui.textColor) holidayColor = rgbToHtml(*ui.holidayColor) colors = [rgbToHtml(*x['color']) for x in ui.mcalTypeParams] if locale_man.rtl: DIR = 'RTL' else: DIR = 'LRT' text = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE>%s</TITLE> </HEAD> <BODY LANG="%s" DIR="%s" BGCOLOR="%s">\n''' % (title, locale_man.langSh, DIR, bgColor) for status in monthsStatus: text += ' <P>\n' for i, line in enumerate(getMonthDesc(status).split('\n')): try: color = colors[i] except IndexError: color = textColor text += ' <FONT COLOR="%s">%s</FONT>\n <BR>\n' % ( color, line) text += ' </P>\n' text += ''' <TABLE WIDTH=100%% BGCOLOR="%s" BORDER=%s BORDERCOLOR="#000000" CELLPADDING=4 CELLSPACING=0> <TR VALIGN=TOP>\n'''\ %(bgColor, int(ui.mcalGrid)) text += ''' <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER></P> </TD>\n''' % borderColor ## what text???????? for j in range(7): text += ''' <TD WIDTH=13%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n''' % (borderColor, borderTextColor, core.getWeekDayN(j)) pluginsText = '<P><FONT COLOR="%s">\n' % colors[0] text += ' </TR>\n' for i in range(6): text += ''' <TR VALIGN=TOP> <TD WIDTH=9%% BGCOLOR="%s"> <P ALIGN=CENTER> <FONT COLOR="%s"><B>%s</B></FONT> </P> </TD>\n''' % (borderColor, borderTextColor, _(status.weekNum[i])) for j in range(7): cell = status[i][j] text += ' <TD WIDTH=13%>\n <P DIR="LTR" ALIGN=CENTER>\n' for (ind, tag) in format: try: mode = calTypes.active[ind] except IndexError: continue try: params = ui.mcalTypeParams[ind] except IndexError: continue day = _(cell.dates[mode][2], mode) ## , 2 font = params['font'] face = font[0] if font[1]: face += ' Bold' if font[2]: face += ' Underline' size = str(sizeMap(font[3])) if cell.month != status.month: if ind == 0: text += ' ' if tag: text += '<%s>' % tag text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>' % ( inactiveColor, face, size, day, ) if tag: text += '</%s>' % tag text += '\n' break else: continue text += ' ' if tag: text += '<%s>' % tag if ind == 0 and cell.holiday: color = holidayColor else: color = colors[ind] text += '<FONT COLOR="%s" FACE="%s" SIZE="%s">%s</FONT>' % ( color, face, size, day) if tag: text += '</%s>' % tag text += '\n' #text += sep##??????????? text += ' </P>\n </TD>\n' if cell.month == status.month: if cell.holiday: color = holidayColor else: color = colors[0] t = cell.pluginsText.replace('\n', pluginsTextSep) if t: pluginsText += '<B><FONT COLOR="%s">%s</FONT>:</B> <SMALL>%s</SMALL>' % ( color, _(cell.dates[calTypes.primary][2]), t, ) if pluginsTextPerLine: pluginsText += '<BR>\n' else: pluginsText += ' \n' text += ' </TR>\n' pluginsText += ' </FONT></P>\n' text += ' </TABLE>\n' text = toStr(text) ## needed for windows text += pluginsText text += '\n<P STYLE="border-bottom: 5pt double %s"></P>\n' % colors[0] text += ''' <P> <FONT COLOR="%s">%s <A HREF="%s">%s</A> %s %s</FONT> </P> </BODY> </HTML>''' % ( colors[0], toStr(_('Generated by')), core.homePage, core.APP_DESC, toStr(_('version')), core.VERSION, ) open(fpath, 'w').write(text)