def add_sections(section_data, scene, bounding_box, font_base=12): """iterate over the list of Section objects, add each to the scene""" if not section_data: return scene v_tweak = -1.0 * font_base / 6 h_tweak = font_base / 2 for sect in section_data: r = timeslot(sect, scene) lines = [str(sect.num), sect.ta, time_to_str(sect.start) + " -- " + time_to_str(sect.end)] r.label_inside_multi(lines, font_base-2, h_tweak, v_tweak).fill(1.0) scene.add(r) return scene
def schedule_grid(title, scene, bounding_box, font_base=12): """Draws a standard Schedule grid: """ margin = 5 # add background (shaded area) title_font = font_base + 4 o, e = bounding_box.origin, bounding_box.extent bg = Rectangle(o, e) bg = bg.shrink(margin).lower(30).fill(0.8).label_above(title, title_font, 6) day_width = bg.width / 6.0 # label column on left lab = Rectangle(bg.origin.copy(), Point(bg.min_x + day_width, bg.max_y)) # add days adj = -2 # move labels slightly down fs = font_base - 2 mon = lab.copy().translate((day_width, 0)).label_above("Monday", fs, adj) tue = mon.copy().translate((day_width, 0)).label_above("Tuesday", fs, adj) wed = tue.copy().translate((day_width, 0)).label_above("Wednesday", fs, adj) thu = wed.copy().translate((day_width, 0)).label_above("Thursday", fs, adj) fri = thu.copy().translate((day_width, 0)).label_above("Friday", fs, adj) # add the days to the scene scene.add(bg, True) # make this the working canvas scene.add(mon) scene.add(tue) scene.add(wed) scene.add(thu) scene.add(fri) # fill in time labels (and draw horiz lines) linespacing = int(-1.0 * fs / 1.5) for t in start_times[:-1]: ypos = y_time(t, scene) h = HLine(Point(bg.min_x, ypos), bg.width) h.label_below_left(time_to_str(t), fs, 5, linespacing) scene.add(h) return scene