Scribus月历脚本源代码

willsonlincake之家 willsonlincake之家 784 人阅读 | 4 人回复 | 2022-04-04

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-

  3. """ This Script creates a Calendar Sheet for the Current Month """

  4. import sys

  5. try:
  6.     from scribus import *
  7. except ImportError:
  8.     print ("This script only runs from within Scribus.")
  9.     sys.exit(1)

  10. import calendar
  11. import time

  12. def main():
  13.     Month = time.localtime()[1]
  14.     Year = time.localtime()[0]
  15.     Objects = []
  16.     MonthList = ["January","February","March","April","May","June","July","August","September","October","November","December"]
  17.     DaysList = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
  18.     Xcoor = 10
  19.     Ycoor = 30
  20.     DayC = 0
  21.     Calend = calendar.monthcalendar(Year, Month)
  22.     ob = createText(10, 10, 245, 20)
  23.     Title = MonthList[Month-1] + " " + str(Year)
  24.     setText(Title, ob)
  25.     Objects.append(ob)
  26.     for lx in range(45, 245, 35):
  27.         ob = createLine(lx, 30, lx, 20*len(Calend)+50)
  28.         Objects.append(ob)
  29.     for ly in range(50, 20*len(Calend)+50, 20):
  30.         ob = createLine(10, ly, 255, ly)
  31.         Objects.append(ob)
  32.     ob = createRect(10, 30, 245, 20*len(Calend)+20)
  33.     setFillColor("None", ob)
  34.     Objects.append(ob)
  35.     for day in range(7):
  36.         ob = createText(Xcoor, Ycoor, 35, 20)
  37.         setTextAlignment(ALIGN_CENTERED, ob)
  38.         setFontSize(12, ob)
  39.         if day == 6:
  40.             setTextColor("Red", ob)
  41.         setText(DaysList[day], ob)
  42.         Objects.append(ob)
  43.         Xcoor = Xcoor + 35
  44.     Ycoor = Ycoor + 20
  45.     for lines in Calend:
  46.         Xcoor = 10
  47.         DayC = 0
  48.         for rows in lines:
  49.             if rows != 0:
  50.                 ob = createText(Xcoor, Ycoor, 35, 20)
  51.                 setTextAlignment(ALIGN_CENTERED, ob)
  52.                 if DayC == 6:
  53.                     setTextColor("Red", ob)
  54.                 setText(str(rows), ob)
  55.                 Objects.append(ob)
  56.             Xcoor = Xcoor + 35
  57.             DayC = DayC + 1
  58.         Ycoor = Ycoor + 20
  59.     groupObjects(Objects)

  60. if __name__ == '__main__':
  61.     if haveDoc():
  62.         try:
  63.             setRedraw(False)
  64.             main()
  65.         finally:
  66.             setRedraw(True)
  67.             redrawAll()
  68.     else:
  69.         messageBox("Calendar Script", "Please run this script with a document open.", ICON_INFORMATION);
复制代码


回答|共 4 个

willsonlincake 发表于 2022-4-4 11:22:14| 字数 25 来自手机 | 显示全部楼层

来自Scribus官方的示例脚本库,很值得研究学习

willsonlincake 发表于 2022-4-4 11:27:09| 字数 522 来自手机 | 显示全部楼层

time.localtime()方法返回一个数组
time.struct_time(tm_year=2016, tm_mon=11, tm_mday=27, tm_hour=10, tm_min=26, tm_sec=5, tm_wday=6, tm_yday=332, tm_isdst=0)

int tm_sec; /* 秒 – 取值区间为[0,59] */
int tm_min; /* 分 - 取值区间为[0,59] */
int tm_hour; /* 时 - 取值区间为[0,23] */
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
int tm_year; /* 年份,其值等于实际年份减去1900 */
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期一,1代表星期二,以此类推 */
int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的时候,tm_isdst为0;不了解情况时,tm_isdst()为负。

willsonlincake 发表于 2022-4-4 11:30:51| 字数 31 来自手机 | 显示全部楼层

calendar.monthcalendar
按星期输出月份数组

蓝莓糖 发表于 2022-4-4 13:36:54| 字数 4 | 显示全部楼层

非常给力
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐