Simple Calendar Image Generator Script

Posted on
Mon Jul 11, 2016 11:34 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Simple Calendar Image Generator Script

here is a quick and dirty script to generate a calendar plot. The script will place an image into the Indigo Static Images Folder called 'calendar.png' which should make it easy to add to a control page. You can adjust the font and the color by changing the first two variables.

Cautions:
- the font needs to be a monospace font in order for things to line up properly.
- the background is transparent, so choose a color that will work well with your control page background (you can use the OS X color picker to find the HTML color value).
- if you change the font size, it won't be centered in the box any longer (and may not fit if you go much larger); if necessary, uncomment the 'ax.axis('off')' to hide the box.

Note: this script requires matplotlib be installed on the Indigo server machine. If your machine does not have matplotlib installed, this is probably not a solution for you (later Macs ship with it preinstalled.)

Code: Select all
import calendar
from datetime import datetime, time
import matplotlib.pyplot as plt

font_name = 'Andale Mono'
font_color = '#000000'

year = int(datetime.today().strftime('%Y'))
month = int(datetime.today().strftime('%m'))
cal = calendar.month(year, month)
output_file_path = f"{indigo.server.getInstallFolderPath()}/Web Assets/images/controls/static/calendar.png"

fig = plt.figure(figsize=(5, 3))
ax = fig.add_subplot(111)
ax.text(0.07, 0.95, cal, transform=ax.transAxes, color=font_color, fontname=font_name, fontsize=20, verticalalignment='top')
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
# ax.axis('off')  # uncomment this line to hide the box

plt.savefig(output_file_path, transparent=True)

calendar.png
calendar.png (21.75 KiB) Viewed 4115 times


[EDIT] Moved to the Dave's Scripts forum.

[EDIT2] To see a listing of fonts on your system that matplotlib can see, run the following script in an Indigo scripting shell:
Code: Select all
import matplotlib.font_manager as mfont
from os import path

font_menu = [path.splitext(path.basename(font))[0] for font in mfont.findSystemFonts(fontpaths=None, fontext='ttf')]

for font in sorted(font_menu):
    indigo.server.log(font)
[EDIT3] Updates for Indigo 2023.1 and Python 3.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jun 13, 2017 4:06 pm
notfamous offline
Posts: 14
Joined: May 07, 2008

Re: Simple Calendar Image Generator Script

Another great bit of useful stuff, Dave.

However. Fonts. No matter what font I call in the script, a generic sans font appears on the control page. Andale? nope. Monaco? nope. Courier? nope. Any known monospaced font on the system or the fonts available in Indigo? nope.

I can't reckon why. Can you?

Cheers,
Tim

Posted on
Tue Jun 13, 2017 6:07 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Simple Calendar Image Generator Script

Hmmm. Do me a solid and run the following script from an Indigo scripting shell:

Code: Select all
import matplotlib.font_manager as mfont
from os import path

font_menu = []

for font in mfont.findSystemFonts(fontpaths=None, fontext='ttf'):
    font_name = path.splitext(path.basename(font))[0]
    if font_name not in font_menu:
        font_menu.append(font_name)

for font in sorted(font_menu):
   indigo.server.log(font)

What do you see?

[EDIT] for a cleaner version of this script, see the first post in this thread.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jun 13, 2017 8:58 pm
notfamous offline
Posts: 14
Joined: May 07, 2008

Re: Simple Calendar Image Generator Script

Wow. That was cool:

Script Andale Mono
Script Apple Braille
Script Apple Braille Outline 6 Dot
Script Apple Braille Outline 8 Dot
Script Apple Braille Pinpoint 6 Dot
Script Apple Braille Pinpoint 8 Dot
Script Apple Chancery
Script Apple Color Emoji
Script AppleGothic
Script AppleMyungjo
Script AppleSDGothicNeo-Bold
Script AppleSDGothicNeo-ExtraBold
Script AppleSDGothicNeo-Heavy
Script AppleSDGothicNeo-Light
Script AppleSDGothicNeo-Medium
Script AppleSDGothicNeo-Regular
Script AppleSDGothicNeo-SemiBold
Script AppleSDGothicNeo-Thin
Script AppleSDGothicNeo-UltraLight
Script Arial
Script Arial Black
Script Arial Bold
Script Arial Bold Italic
Script Arial Italic
Script Arial Narrow
Script Arial Narrow Bold
Script Arial Narrow Bold Italic
Script Arial Narrow Italic
Script Arial Rounded Bold
Script Arial Unicode
Script Ayuthaya
Script BigCaslon
Script Bodoni 72 Smallcaps Book
Script Bodoni Ornaments
Script Bradley Hand Bold
Script Brush Script
Script Chalkduster
Script Comic Sans MS
Script Comic Sans MS Bold
Script Courier New
Script Courier New Bold
Script Courier New Bold Italic
Script Courier New Italic
Script DIN Alternate Bold
Script DIN Condensed Bold
Script Diwan Thuluth
Script Farisi
Script Georgia
Script Georgia Bold
Script Georgia Bold Italic
Script Georgia Italic
Script GujaratiMT
Script GujaratiMTBold
Script Gungseouche
Script Gurmukhi
Script HeadlineA
Script Herculanum
Script HiraKakuInterface-W1
Script HiraKakuInterface-W2
Script Hiragino Sans GB W3
Script Hiragino Sans GB W6
Script Hoefler Text Ornaments
Script Impact
Script InaiMathi
Script Kailasa
Script Keyboard
Script Khmer Sangam MN
Script Kokonor
Script Krungthep
Script Lao Sangam MN
Script LastResort
Script Luminari
Script Microsoft Sans Serif
Script Mishafi
Script Mishafi Gold
Script MshtakanBold
Script MshtakanBoldOblique
Script MshtakanOblique
Script MshtakanRegular
Script Myanmar Sangam MN
Script NISC18030
Script Osaka
Script OsakaMono
Script PCmyoungjo
Script Pilgiche
Script PlantagenetCherokee
Script STIXGeneral
Script STIXGeneralBol
Script STIXGeneralBolIta
Script STIXGeneralItalic
Script STIXIntDBol
Script STIXIntDReg
Script STIXIntSmBol
Script STIXIntSmReg
Script STIXIntUpBol
Script STIXIntUpDBol
Script STIXIntUpDReg
Script STIXIntUpReg
Script STIXIntUpSmBol
Script STIXIntUpSmReg
Script STIXNonUni
Script STIXNonUniBol
Script STIXNonUniBolIta
Script STIXNonUniIta
Script STIXSizFiveSymReg
Script STIXSizFourSymBol
Script STIXSizFourSymReg
Script STIXSizOneSymBol
Script STIXSizOneSymReg
Script STIXSizThreeSymBol
Script STIXSizThreeSymReg
Script STIXSizTwoSymBol
Script STIXSizTwoSymReg
Script STIXVar
Script STIXVarBol
Script Sathu
Script SignPainter
Script Silom
Script Skia
Script Symbol
Script Tahoma
Script Tahoma Bold
Script Times New Roman
Script Times New Roman Bold
Script Times New Roman Bold Italic
Script Times New Roman Italic
Script Trattatello
Script Trebuchet MS
Script Trebuchet MS Bold
Script Trebuchet MS Bold Italic
Script Trebuchet MS Italic
Script Verdana
Script Verdana Bold
Script Verdana Bold Italic
Script Verdana Italic
Script WawaSC-Regular
Script WawaTC-Regular
Script Webdings
Script WeibeiSC-Bold
Script WeibeiTC-Bold
Script Wingdings
Script Wingdings 2
Script Wingdings 3
Script Yu Gothic Bold
Script Yu Gothic Medium
Script Yu Mincho Demibold
Script Yu Mincho Medium
Script YuppySC-Regular
Script YuppyTC-Regular
Script ZapfDingbats
Script Zapfino
Script ヒラギノ丸ゴ Pro W4
Script ヒラギノ丸ゴ ProN W4
Script ヒラギノ明朝 Pro W3
Script ヒラギノ明朝 Pro W6
Script ヒラギノ明朝 ProN W3
Script ヒラギノ明朝 ProN W6
Script ヒラギノ角ゴ Pro W3
Script ヒラギノ角ゴ Pro W6
Script ヒラギノ角ゴ ProN W3
Script ヒラギノ角ゴ ProN W6
Script ヒラギノ角ゴ Std W8
Script ヒラギノ角ゴ StdN W8
Script 儷宋 Pro
Script 儷黑 Pro
Script 华文仿宋
Script 华文细黑
Script 华文黑体

In the meantime, I seem to have some sort of cache refresh issue with the browser as now Andale Mono works.

Posted on
Wed Jun 14, 2017 5:39 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Simple Calendar Image Generator Script

Glad to hear that's working for you now. In case it's not obvious, the list of fonts is only the fonts that matplotlib can see; there may be other fonts on your system.

Enjoy!
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Jun 14, 2017 5:53 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Simple Calendar Image Generator Script

P.S. I've added a cleaner version of the font listing script to the OP.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Jun 14, 2017 9:46 am
notfamous offline
Posts: 14
Joined: May 07, 2008

Re: Simple Calendar Image Generator Script

Dave.

My mistake was not realizing that python had access to a completely different font set than indigo and the OS. The more you now...

Cheers,
Tim

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron