def updateWidget(self): cells, wEventData = ui.cellCache.getWeekData(self.absWeekNumber) self.ls.clear() for item in wEventData: if not item["show"][1]: continue self.ls.append( pixbufFromFile(item["icon"]), core.getWeekDayAuto(item["weekDay"], self.abrivateWeekDays), item["time"], item["text"], )
def drawAll(self, widget=None, cr=None, cursor=True): #gevent = gtk.get_current_event() #?????? Must enhance (only draw few cells, not all cells) self.calcCoord() w = self.get_allocation().width h = self.get_allocation().height if not cr: cr = self.get_window().cairo_create() #cr.set_line_width(0)#?????????????? #cr.scale(0.5, 0.5) wx = ui.winX wy = ui.winY #if ui.bgUseDesk: # FIXME: should be re-implemented # from scal3.ui_gtk import desktop # from scal3.ui_gtk import wallpaper cr.rectangle(0, 0, w, h) fillColor(cr, ui.bgColor) status = getCurrentMonthStatus() #################################### Drawing Border if ui.mcalTopMargin > 0: ##### Drawing border top background ##menuBgColor == borderColor ##??????????????? cr.rectangle(0, 0, w, ui.mcalTopMargin) fillColor(cr, ui.borderColor) ######## Drawing weekDays names setColor(cr, ui.borderTextColor) dx = 0 wdayAb = (self.wdaysWidth > w) for i in range(7): wday = newTextLayout(self, core.getWeekDayAuto(i, wdayAb)) try: fontw, fonth = wday.get_pixel_size() except: myRaise(__file__) fontw, fonth = wday.get_pixel_size() cr.move_to( self.cx[i] - fontw / 2, (ui.mcalTopMargin - fonth) / 2 - 1, ) show_layout(cr, wday) ######## Drawing "Menu" label setColor(cr, ui.menuTextColor) text = newTextLayout(self, _("Menu")) fontw, fonth = text.get_pixel_size() if rtl: cr.move_to( w - (ui.mcalLeftMargin + fontw) / 2 - 3, (ui.mcalTopMargin - fonth) / 2 - 1, ) else: cr.move_to( (ui.mcalLeftMargin - fontw) / 2, (ui.mcalTopMargin - fonth) / 2 - 1, ) show_layout(cr, text) if ui.mcalLeftMargin > 0: ##### Drawing border left background if rtl: cr.rectangle( w - ui.mcalLeftMargin, ui.mcalTopMargin, ui.mcalLeftMargin, h - ui.mcalTopMargin, ) else: cr.rectangle( 0, ui.mcalTopMargin, ui.mcalLeftMargin, h - ui.mcalTopMargin, ) fillColor(cr, ui.borderColor) ##### Drawing week numbers setColor(cr, ui.borderTextColor) for i in range(6): lay = newTextLayout(self, _(status.weekNum[i])) fontw, fonth = lay.get_pixel_size() if rtl: cr.move_to( w - (ui.mcalLeftMargin + fontw) / 2, self.cy[i] - fonth / 2 + 2, ) else: cr.move_to( (ui.mcalLeftMargin - fontw) / 2, self.cy[i] - fonth / 2 + 2, ) show_layout(cr, lay) selectedCellPos = ui.cell.monthPos if ui.todayCell.inSameMonth(ui.cell): tx, ty = ui.todayCell.monthPos ## today x and y x0 = self.cx[tx] - self.dx / 2 y0 = self.cy[ty] - self.dy / 2 cr.rectangle(x0, y0, self.dx, self.dy) fillColor(cr, ui.todayCellColor) for yPos in range(6): for xPos in range(7): c = status[yPos][xPos] x0 = self.cx[xPos] y0 = self.cy[yPos] cellInactive = (c.month != ui.cell.month) cellHasCursor = (cursor and (xPos, yPos) == selectedCellPos) if cellHasCursor: ##### Drawing Cursor cx0 = x0 - self.dx / 2 + 1 cy0 = y0 - self.dy / 2 + 1 cw = self.dx - 1 ch = self.dy - 1 ######### Circular Rounded drawCursorBg(cr, cx0, cy0, cw, ch) fillColor(cr, ui.cursorBgColor) ######## end of Drawing Cursor if not cellInactive: iconList = c.getMonthEventIcons() if iconList: iconsN = len(iconList) scaleFact = 1 / sqrt(iconsN) fromRight = 0 for index, icon in enumerate(iconList): ## if len(iconList) > 1 ## FIXME try: pix = GdkPixbuf.Pixbuf.new_from_file(icon) except: myRaise(__file__) continue pix_w = pix.get_width() pix_h = pix.get_height() # right buttom corner ??? # right side: x1 = (x0 + self.dx / 2) / scaleFact - fromRight - pix_w # buttom side: y1 = (y0 + self.dy / 2) / scaleFact - pix_h cr.scale(scaleFact, scaleFact) gdk.cairo_set_source_pixbuf(cr, pix, x1, y1) cr.rectangle(x1, y1, pix_w, pix_h) cr.fill() cr.scale(1 / scaleFact, 1 / scaleFact) fromRight += pix_w #### Drawing numbers inside every cell #cr.rectangle( # x0-self.dx / 2+1, # y0-self.dy / 2+1, # self.dx-1, # self.dy-1, #) mode = calTypes.primary params = ui.mcalTypeParams[0] daynum = newTextLayout( self, _(c.dates[mode][2], mode), params["font"], ) fontw, fonth = daynum.get_pixel_size() if cellInactive: setColor(cr, ui.inactiveColor) elif c.holiday: setColor(cr, ui.holidayColor) else: setColor(cr, params["color"]) cr.move_to( x0 - fontw / 2 + params["pos"][0], y0 - fonth / 2 + params["pos"][1], ) show_layout(cr, daynum) if not cellInactive: for mode, params in ui.getActiveMonthCalParams()[1:]: daynum = newTextLayout( self, _(c.dates[mode][2], mode), params["font"], ) fontw, fonth = daynum.get_pixel_size() setColor(cr, params["color"]) cr.move_to( x0 - fontw / 2 + params["pos"][0], y0 - fonth / 2 + params["pos"][1], ) show_layout(cr, daynum) if cellHasCursor: ##### Drawing Cursor Outline cx0 = x0 - self.dx / 2 + 1 cy0 = y0 - self.dy / 2 + 1 cw = self.dx - 1 ch = self.dy - 1 ######### Circular Rounded drawCursorOutline(cr, cx0, cy0, cw, ch) fillColor(cr, ui.cursorOutColor) ##### end of Drawing Cursor Outline ################ end of drawing cells ##### drawGrid if ui.mcalGrid: setColor(cr, ui.mcalGridColor) for i in range(7): cr.rectangle( self.cx[i] + rtlSgn() * self.dx / 2, 0, 1, h, ) cr.fill() for i in range(6): cr.rectangle( 0, self.cy[i] - self.dy / 2, w, 1, ) cr.fill() return False
def drawAll(self, widget=None, cr=None, cursor=True): #gevent = gtk.get_current_event() #?????? Must enhance (only draw few cells, not all cells) self.calcCoord() w = self.get_allocation().width h = self.get_allocation().height if not cr: cr = self.get_window().cairo_create() #cr.set_line_width(0)#?????????????? #cr.scale(0.5, 0.5) wx = ui.winX wy = ui.winY if ui.bgUseDesk:## FIXME ### ????????????????? Need for mainWin !!!!! coord = self.translate_coordinates(self, wx, wy) if len(coord)==2: from scal3.ui_gtk import desktop x0, y0 = coord try: bg = desktop.get_wallpaper(x0, y0, w, h) except: print('Could not get wallpaper!') myRaise(__file__) #os.popen('gnome-settings-daemon') ui.bgUseDesk = False ##?????????????????? #if ui.prefDialog # ui.prefDialog.checkDeskBg.set_active(False)##?????????????????? else: gdk.cairo_set_source_pixbuf(cr, bg, 0, 0, 0) cr.paint() #else: # print(coord) cr.rectangle(0, 0, w, h) fillColor(cr, ui.bgColor) status = getCurrentMonthStatus() #################################### Drawing Border if ui.mcalTopMargin>0: ##### Drawing border top background ##menuBgColor == borderColor ##??????????????? cr.rectangle(0, 0, w, ui.mcalTopMargin) fillColor(cr, ui.borderColor) ######## Drawing weekDays names setColor(cr, ui.borderTextColor) dx = 0 wdayAb = (self.wdaysWidth > w) for i in range(7): wday = newTextLayout(self, core.getWeekDayAuto(i, wdayAb)) try: fontw, fonth = wday.get_pixel_size() except: myRaise(__file__) fontw, fonth = wday.get_pixel_size() cr.move_to( self.cx[i]-fontw/2.0, (ui.mcalTopMargin-fonth)/2.0-1, ) show_layout(cr, wday) ######## Drawing "Menu" label setColor(cr, ui.menuTextColor) text = newTextLayout(self, _('Menu')) fontw, fonth = text.get_pixel_size() if rtl: cr.move_to( w-(ui.mcalLeftMargin+fontw)/2.0 - 3, (ui.mcalTopMargin-fonth)/2.0 - 1, ) else: cr.move_to( (ui.mcalLeftMargin-fontw)/2.0, (ui.mcalTopMargin-fonth)/2.0 - 1, ) show_layout(cr, text) if ui.mcalLeftMargin>0: ##### Drawing border left background if rtl: cr.rectangle( w - ui.mcalLeftMargin, ui.mcalTopMargin, ui.mcalLeftMargin, h - ui.mcalTopMargin, ) else: cr.rectangle( 0, ui.mcalTopMargin, ui.mcalLeftMargin, h - ui.mcalTopMargin, ) fillColor(cr, ui.borderColor) ##### Drawing week numbers setColor(cr, ui.borderTextColor) for i in range(6): lay = newTextLayout(self, _(status.weekNum[i])) fontw, fonth = lay.get_pixel_size() if rtl: cr.move_to( w - (ui.mcalLeftMargin+fontw)/2.0, self.cy[i]-fonth/2.0 + 2, ) else: cr.move_to( (ui.mcalLeftMargin-fontw)/2.0, self.cy[i]-fonth/2.0 + 2, ) show_layout(cr, lay) selectedCellPos = ui.cell.monthPos if ui.todayCell.inSameMonth(ui.cell): tx, ty = ui.todayCell.monthPos ## today x and y x0 = self.cx[tx] - self.dx/2.0 y0 = self.cy[ty] - self.dy/2.0 cr.rectangle(x0, y0, self.dx, self.dy) fillColor(cr, ui.todayCellColor) for yPos in range(6): for xPos in range(7): c = status[yPos][xPos] x0 = self.cx[xPos] y0 = self.cy[yPos] cellInactive = (c.month != ui.cell.month) cellHasCursor = (cursor and (xPos, yPos) == selectedCellPos) if cellHasCursor: ##### Drawing Cursor cx0 = x0 - self.dx/2.0 + 1 cy0 = y0 - self.dy/2.0 + 1 cw = self.dx - 1 ch = self.dy - 1 ######### Circular Rounded drawCursorBg(cr, cx0, cy0, cw, ch) fillColor(cr, ui.cursorBgColor) ######## end of Drawing Cursor if not cellInactive: iconList = c.getMonthEventIcons() if iconList: iconsN = len(iconList) scaleFact = 1.0 / sqrt(iconsN) fromRight = 0 for index, icon in enumerate(iconList): ## if len(iconList) > 1 ## FIXME try: pix = GdkPixbuf.Pixbuf.new_from_file(icon) except: myRaise(__file__) continue pix_w = pix.get_width() pix_h = pix.get_height() ## right buttom corner ????????????????????? x1 = (x0 + self.dx/2.0)/scaleFact - fromRight - pix_w # right side y1 = (y0 + self.dy/2.0)/scaleFact - pix_h # buttom side cr.scale(scaleFact, scaleFact) gdk.cairo_set_source_pixbuf(cr, pix, x1, y1) cr.rectangle(x1, y1, pix_w, pix_h) cr.fill() cr.scale(1.0/scaleFact, 1.0/scaleFact) fromRight += pix_w #### Drawing numbers inside every cell #cr.rectangle( # x0-self.dx/2.0+1, # y0-self.dy/2.0+1, # self.dx-1, # self.dy-1, #) mode = calTypes.primary params = ui.mcalTypeParams[0] daynum = newTextLayout(self, _(c.dates[mode][2], mode), params['font']) fontw, fonth = daynum.get_pixel_size() if cellInactive: setColor(cr, ui.inactiveColor) elif c.holiday: setColor(cr, ui.holidayColor) else: setColor(cr, params['color']) cr.move_to( x0 - fontw/2.0 + params['pos'][0], y0 - fonth/2.0 + params['pos'][1], ) show_layout(cr, daynum) if not cellInactive: for mode, params in ui.getActiveMonthCalParams()[1:]: daynum = newTextLayout(self, _(c.dates[mode][2], mode), params['font']) fontw, fonth = daynum.get_pixel_size() setColor(cr, params['color']) cr.move_to( x0 - fontw/2.0 + params['pos'][0], y0 - fonth/2.0 + params['pos'][1], ) show_layout(cr, daynum) if cellHasCursor: ##### Drawing Cursor Outline cx0 = x0-self.dx/2.0+1 cy0 = y0-self.dy/2.0+1 cw = self.dx-1 ch = self.dy-1 ######### Circular Rounded drawCursorOutline(cr, cx0, cy0, cw, ch) fillColor(cr, ui.cursorOutColor) ##### end of Drawing Cursor Outline ################ end of drawing cells ##### drawGrid if ui.mcalGrid: setColor(cr, ui.mcalGridColor) for i in range(7): cr.rectangle(self.cx[i]+rtlSgn()*self.dx/2.0, 0, 1, h) cr.fill() for i in range(6): cr.rectangle(0, self.cy[i]-self.dy/2.0, w, 1) cr.fill() return False