return font, size def format(self, weeks, title): pos = [self.font.measure(title[:title.find(day)+len(day)]) for day in title.split()] space = u'\u200a' # hair space space_width = self.font.measure(space) str_list = [] for week in weeks: str = "" for i, day in enumerate(week): number_of_spaces = (pos[i] - self.font.measure(str) - self.font.measure(day)) / space_width str += space * int(round(number_of_spaces)) str += day str_list.append(str) return str_list if __name__ == "__main__": from util import DEFAULT_SETTINGS key = "alfred.theme.custom.A1911D25-FB72-4E1C-9180-7A8A71DB327F" path = "~/Library/Application Support/Alfred 2/Alfred.alfredpreferences" f = Format(key, path) from cal import Cal c = Cal(DEFAULT_SETTINGS, key, path) arr = f.format(c.get_cal(c.get_weeks(2015, 1, 6)), c.week_text(6)) print c.week_text(6) for str in arr: print(str)
str += day str_list.append(str) return str_list def new_format(self, weeks, title): width_measure = self.font.measure(title.split()[0]) pos = [ self.font.measure(title[:title.find(day)]) for day in title.split() ] space_width = self.font.measure(u' ') str_list = [] for week in weeks: str = "" for i, day in enumerate(week): number_of_spaces = (pos[i] - self.font.measure(str) - width_measure) / space_width str += u' ' * number_of_spaces str += day str_list.append(str) return str_list if __name__ == "__main__": key = "alfred.theme.custom.A1911D25-FB72-4E1C-9180-7A8A71DB327F" path = "/Users/owen/Library/Application Support/Alfred 2/Alfred.alfredpreferences" f = Format(key, path) from cal import Cal c = Cal({}, key, path) print f.format(c.get_cal(c.get_weeks(2015, 1)), c.week_text(6))