Geektool Line Calendar

Discussion in 'UI Customization' started by yetiboy, May 1, 2014.

  1. yetiboy macrumors member

    Joined:
    Mar 23, 2011
    #1
    I'm trying to set up a vertical calendar and found this post:

    http://forums.macrumors.com/showpost.php?p=13332530&postcount=3266

    Unfortunately, everything works except for making the current day colorized. When that command line argument is used (-c or --colorize), the result is no output. All other command line arguments work properly.

    Anyone have any idea how to make this work properly? Or have an alternative? I'd like a vertical calendar that produces one column with the days of the week and one column with the date as this one does.

    yeti
     
  2. tag macrumors 6502a

    tag

    Joined:
    Apr 29, 2005
    Location:
    PA, US
    #2
    Not sure how to fix that one but I did come across this other one which does seem to work, though to change the current days color from the default yellow you need to manually edit the 'highlighted' variable on line 52.

    Code:
    #!/usr/bin/python
    # VertiCal: A slim monthly calendar (that's perfect for GeekTool)
    # by Rob Dumas
    # Copyright (c) 2012 GNU Public License version 3.
    # See http://www.gnu.org/licenses/licenses.html for details on this license.
    
    import sys
    import datetime
    import calendar
    
    # Get the current date and create our vertiCal.
    today = datetime.date.today()
    vertiCal = []
    
    # Create a calendar object, whose weeks start on Sunday.
    cal = calendar.Calendar(6)
    
    # Set a variable for the day.
    for i in cal.itermonthdays2( today.year, today.month ):
      if   i[1] == 0:
        theday = "Mon"
      elif i[1] == 1:
        theday = "Tue"
      elif i[1] == 2:
        theday = "Wed"
      elif i[1] == 3:
        theday = "Thu"
      elif i[1] == 4:
        theday = "Fri"
      elif i[1] == 5:
        theday = "Sat"
      elif i[1] == 6:
        theday = "Sun"
      else:
        print "Error: Day of week is not between 0 and 6."
      
      # Make sure the date is nonzero before appending to our list.
      if i[0] != 0:
        
        # ANSI codes:
        # 'black':      '0;30',   'bright gray':      '0;37',
        # 'blue':       '0;34',   'white':            '1;37',
        # 'green':      '0;32',   'bright blue':      '1;34',
        # 'cyan':       '0;36',   'bright green':     '1;32',
        # 'red':        '0;31',   'bright cyan':      '1;36',
        # 'purple':     '0;35',   'bright red':       '1;31',
        # 'yellow':     '0;33',   'bright purple':    '1;35',
        # 'dark gray':  '1;30',   'bright yellow':    '1;33',
        # 'normal':     '0'
        startofline = ""                 # empty by default
        default     = '''\033[1;37m'''   # white by default
        highlighted = '''\033[0;33m'''   # yellow
        endofline   = ''' \033[0m'''     # return to normal at EOL
        
        separator = ""
        monthlen = len( today.strftime( "%B" ) )
        if monthlen < 6: monthlen = 6
        for d in range( monthlen ):
          separator += "-"
        
        if i[0] == today.day:
          startofline = highlighted
          spacer = " "
        else:
          startofline = default
          spacer = " "
        
        thestring = startofline + theday + spacer
        # At this point, thestring should look something like:
        # \033[1;37mMon  (normal)
        # \033[0;33mTue  (highlighted)
        
        # Add an extra space to the line if the date is a single digit.
        if 1 <= i[0] <= 9: thestring += " "
        
        # Add the date to thestring.
        thestring += str(i[0]) + endofline
        # At this point, thestring should look something like:
        # \033[1;37mMon  9\033[0m (normal)
        # \033[0;33mTue 10\033[0m (highlighted)
        
        vertiCal.append(thestring)
    
    # Print it all out.
    print highlighted + today.strftime( "%B\n%Y" ) + endofline
    print default + separator + endofline
    for item in vertiCal: print item
     

Share This Page