Exemplo n.º 1
0
 def save(self, widget=None):
     self.get_window().set_cursor(gdk.Cursor.new(gdk.CursorType.WATCH))
     while gtk.events_pending():
         gtk.main_iteration_do(False)
     path = self.fcw.get_filename()
     if path in (None, ''):
         return
     print('Exporting to html file "%s"'%path)
     i = self.combo.get_active()
     months = []
     module = calTypes.primaryModule()
     if i==0:
         s = getCurrentMonthStatus()
         months = [s]
         title = '%s %s'%(locale_man.getMonthName(calTypes.primary, s.month, s.year), _(s.year))
     elif i==1:
         for i in range(1, 13):
             months.append(getMonthStatus(ui.cell.year, i))
         title = '%s %s'%(_('Calendar'), _(ui.cell.year))
     elif i==2:
         y0, m0 = self.ymBox0.get_value()
         y1, m1 = self.ymBox1.get_value()
         for ym in range(y0*12+m0-1, y1*12+m1):
             y, m = divmod(ym, 12)
             m += 1
             months.append(getMonthStatus(y, m))
         title = _('Calendar')
     exportToHtml(path, months, title)
     self.get_window().set_cursor(gdk.Cursor.new(gdk.CursorType.LEFT_PTR))
     self.hide()
Exemplo n.º 2
0
	def _save(self, path):
		comboItem = self.combo.get_active()
		months = []
		module = calTypes.primaryModule()
		if comboItem == 0:
			s = getCurrentMonthStatus()
			months = [s]
			title = "%s %s" % (
				locale_man.getMonthName(
					calTypes.primary,
					s.month,
					s.year,
				),
				_(s.year),
			)
		elif comboItem == 1:
			for i in range(1, 13):
				months.append(getMonthStatus(ui.cell.year, i))
			title = "%s %s" % (_("Calendar"), _(ui.cell.year))
		elif comboItem == 2:
			y0, m0 = self.ymBox0.get_value()
			y1, m1 = self.ymBox1.get_value()
			for ym in range(y0 * 12 + m0 - 1, y1 * 12 + m1):
				y, m = divmod(ym, 12)
				m += 1
				months.append(getMonthStatus(y, m))
			title = _("Calendar")
		exportToHtml(path, months, title)
		self.hide()
Exemplo n.º 3
0
 def buttonPress(self, obj, gevent):
     ## self.winActivate() #?????????
     b = gevent.button
     x, y, = self.get_pointer()
     # foo, x, y, flags = self.get_window().get_pointer()
     self.pointer = (x, y)
     if b == 2:
         return False
     xPos = -1
     yPos = -1
     for i in range(7):
         if abs(x - self.cx[i]) <= self.dx / 2:
             xPos = i
             break
     for i in range(6):
         if abs(y - self.cy[i]) <= self.dy / 2:
             yPos = i
             break
     status = getCurrentMonthStatus()
     if yPos == -1 or xPos == -1:
         self.emit("popup-main-menu", gevent.time, gevent.x, gevent.y)
     elif yPos >= 0 and xPos >= 0:
         cell = status[yPos][xPos]
         self.changeDate(*cell.dates[calTypes.primary])
         if gevent.type == TWO_BUTTON_PRESS:
             self.emit("double-button-press")
         if b == 3 and cell.month == ui.cell.month:  ## right click on a normal cell
             #self.emit("popup-cell-menu", gevent.time, *self.getCellPos())
             self.emit("popup-cell-menu", gevent.time, gevent.x, gevent.y)
     return True
Exemplo n.º 4
0
 def buttonPress(self, obj, gevent):
     ## self.winActivate() #?????????
     b = gevent.button
     x, y, = self.get_pointer()
     # foo, x, y, flags = self.get_window().get_pointer()
     self.pointer = (x, y)
     if b==2:
         return False
     xPos = -1
     yPos = -1
     for i in range(7):
         if abs(x-self.cx[i]) <= self.dx/2.0:
             xPos = i
             break
     for i in range(6):
         if abs(y-self.cy[i]) <= self.dy/2.0:
             yPos = i
             break
     status = getCurrentMonthStatus()
     if yPos == -1 or xPos == -1:
         self.emit('popup-main-menu', gevent.time, gevent.x, gevent.y)
     elif yPos >= 0 and xPos >= 0:
         cell = status[yPos][xPos]
         self.changeDate(*cell.dates[calTypes.primary])
         if gevent.type==TWO_BUTTON_PRESS:
             self.emit('2button-press')
         if b == 3 and cell.month == ui.cell.month:## right click on a normal cell
             #self.emit('popup-cell-menu', gevent.time, *self.getCellPos())
             self.emit('popup-cell-menu', gevent.time, gevent.x, gevent.y)
     return True
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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