willsonlincake 发表于 2022-4-4 11:21:38

Scribus月历脚本源代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

import sys

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

import calendar
import time

def main():
    Month = time.localtime()
    Year = time.localtime()
    Objects = []
    MonthList = ["January","February","March","April","May","June","July","August","September","October","November","December"]
    DaysList = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
    Xcoor = 10
    Ycoor = 30
    DayC = 0
    Calend = calendar.monthcalendar(Year, Month)
    ob = createText(10, 10, 245, 20)
    Title = MonthList + " " + str(Year)
    setText(Title, ob)
    Objects.append(ob)
    for lx in range(45, 245, 35):
      ob = createLine(lx, 30, lx, 20*len(Calend)+50)
      Objects.append(ob)
    for ly in range(50, 20*len(Calend)+50, 20):
      ob = createLine(10, ly, 255, ly)
      Objects.append(ob)
    ob = createRect(10, 30, 245, 20*len(Calend)+20)
    setFillColor("None", ob)
    Objects.append(ob)
    for day in range(7):
      ob = createText(Xcoor, Ycoor, 35, 20)
      setTextAlignment(ALIGN_CENTERED, ob)
      setFontSize(12, ob)
      if day == 6:
            setTextColor("Red", ob)
      setText(DaysList, ob)
      Objects.append(ob)
      Xcoor = Xcoor + 35
    Ycoor = Ycoor + 20
    for lines in Calend:
      Xcoor = 10
      DayC = 0
      for rows in lines:
            if rows != 0:
                ob = createText(Xcoor, Ycoor, 35, 20)
                setTextAlignment(ALIGN_CENTERED, ob)
                if DayC == 6:
                  setTextColor("Red", ob)
                setText(str(rows), ob)
                Objects.append(ob)
            Xcoor = Xcoor + 35
            DayC = DayC + 1
      Ycoor = Ycoor + 20
    groupObjects(Objects)

if __name__ == '__main__':
    if haveDoc():
      try:
            setRedraw(False)
            main()
      finally:
            setRedraw(True)
            redrawAll()
    else:
      messageBox("Calendar Script", "Please run this script with a document open.", ICON_INFORMATION);

willsonlincake 发表于 2022-4-4 11:22:14

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

willsonlincake 发表于 2022-4-4 11:27:09

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

willsonlincake 发表于 2022-4-4 11:30:51

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

蓝莓糖 发表于 2022-4-4 13:36:54

非常给力
页: [1]
查看完整版本: Scribus月历脚本源代码