def make_counter(msg, color): poster = Poster() rect = Rectangle(80, 50, color) poster.pin(rect, -40, -25) textbox = TextBox(msg, "Courier", "40") poster.pin(textbox, 0, 0) return poster
def make_button(msg, color): poster = Poster() circle = Circle(100, color, filled=True) poster.pin(circle, 0, 0) textbox = TextBox(msg, "Helvetica", "40") poster.pin(textbox, 0, 0) return poster
def __init__(self, config): self.board = BulletinBoard(config.get_board_width(), config.get_board_height()) self.wall = BrickWall(self.board.get_width(), self.board.get_height() * 0.3, config.get_color_matrix(), config.get_color_map(), config.outline_bricks()) paddle_width = self.board.get_width() // 8 paddle_height = self.board.get_height() // 40 self.paddle = Rectangle(paddle_width, paddle_height, "black", filled=True) self.board.pin(self.wall, 0, 0.1 * self.board.get_height()) self.board.pin(self.paddle, self.board.get_width() / 2, 0.9 * self.board.get_height()) self.reset_ball() self.message_box = TextBox("", "Helvetica Neue", 20, "#0000FF") self.dy = config.get_initial_y_velocity() self.dx = random.uniform(config.get_min_x_velocity(), config.get_max_x_velocity()) self.dx = random.choice([-1, 1]) * self.dx self.lives_left = config.get_num_balls() self.time_step = config.get_time_step() self.game_in_progress = False self.game_over = False
def main(datee, data, save=False, graphtime=graph_time): date = Date(datee) img = Image.new('RGB', (width, height), bg_color) draw = ImageDraw.Draw(img) configure_draw_parameters(img.width, img.height, draw.line, draw.text) t, c = dissect(data) file = DynamicFile(date, t, c, graphtime) g = Graph.fromfile(file, (.13, .13), .8, .8, graph_width=2) g.draw() tb = TextBox("Data from " + date.to_string_display() + ' data type: ' + data, (.5, .02), is_cell=True) tb.draw() try: print(date.tostring() + ' at ' + Time.get_time_without_seconds(file.get_last_measurement_time())) except IndexError: print(date.tostring()) img.show() if save: if lab_computer == black: save_str = 'fridgelogB_' else: save_str = 'fridgelog_' try: img.save(save_to_location + save_str + data + '.png') except IOError: file = open(save_to_location + save_str + data + '.png', 'w+') img.save(save_to_location + save_str + data + '.png') file.close() img.close() file.close()
from graphics import BulletinBoard, Poster from graphics import Circle, Rectangle, TextBox board = BulletinBoard(200, 350) # Code for creating the "counter display" poster = Poster() rect = Rectangle(80, 50, "#7BA4DB") poster.pin(rect, -40, -25) textbox = TextBox("000", "Courier", "40") poster.pin(textbox, 0, 0) board.pin(poster, 100, 50) # TODO: Code for creating a "fizz button" # fill me in!
from graphics import BulletinBoard, Poster from graphics import Circle, Rectangle, TextBox board = BulletinBoard(200, 350) # Code for creating the "counter display" poster = Poster() rect = Rectangle(80, 50, "#7BA4DB") poster.pin(rect, -40, -25) textbox = TextBox("000", "Courier", "40") poster.pin(textbox, 0, 0) board.pin(poster, 100, 50) # TODO: Code for creating a "fizz button" button = Poster() circle = Circle(100, "gray") button.pin(circle, 0, 0) textbox = TextBox("fizz", "Helvetica", "40") button.pin(textbox, 0, 0) board.pin(button, 100, 150)
def main(): pressure_file = None date = get_most_recent_record_date(Date(str(datetime.now()))) temperature_files = [] graph_files = [] types = ('T', 'maxigauge') temperature_chambers = (1, 2, 5, 6) pressure_chambers = (1, 2, 3, 4, 5, 6) try: pressure_file = FridgeFile(date.tostring(), types[1]) pressure_file.open() except IOError: print(pressure_file.tostring() + ' not found') for x in range(0, len(temperature_chambers)): try: temperature_files.append( FridgeFile(date.tostring(), types[0], temperature_chambers[x])) except IOError: print(temperature_files[x].tostring() + ' not found') temperature_files[x] = None img = [] draw = [] for i in range(0, 11): img.append(Image.new('RGB', (width, height), bg_color)) draw.append(ImageDraw.Draw(img[-1])) i = 0 for t, chambers in zip(types, [temperature_chambers, pressure_chambers]): for c in chambers: configure_draw_parameters(img[i].width, img[i].height, draw[i].line, draw[i].text) if t == 'maxigauge': graph_files.append(DynamicFile(date, t, c, scale_nums=1)) else: graph_files.append(DynamicFile(date, t, c)) if lab_computer == tester: print(graph_files[-1]) if not graph_files[-1].is_empty(): g = Graph.fromfile(graph_files[-1], (.13, .33), .8, .6, graph_width=2, log_vals=t == 'maxigauge') g.draw() try: tb = TextBox.datetime_box( date, graph_files[-1].get_last_measurement_time(), i) except IndexError: tb = TextBox("Data from " + date.to_string_display() + ' ' + 'Chamber ' + str(convert(i)).replace('_', ' '), (.5, .02), is_cell=True) tb.draw() i += 1 data = [] for t in graph_files: data.append(t.get_last_measurement()) t_temp = Table((.1, .05), .4, .2, ['Plate', 'Temperature'], ['T1: 40k', 'T2: 4k', 'T5: Still', 'T6: MC'], ['numeral', 'K'], [data[:4]]) t_pres = Table((.5, .05), .4, .2, ['Gauge', 'Pressure'], [ 'P1: OVC1', 'P2: Still', 'P3: Condense', 'P4: LN2 Trap', 'P5: Tank', 'P6: OVC2' ], ['numeral', 'bar'], [data[4:]]) for imgs, draws in zip(img, draw): configure_draw_parameters(imgs.width, imgs.height, draws.line, draws.text) t_temp.draw() t_pres.draw() try: configure_draw_parameters(img[-1].width, img[-1].height, draw[-1].line, draw[-1].text) flowmeter_file = FridgeFile(date.tostring(), 'Flowmeter') flowmeter_file.open() flow = Table((.65, .27), .23, .05, ['Flow'], [], ['mol/s'], [scientific_sf(flowmeter_file.get_last_measurement())]) g = Graph.fromfile(flowmeter_file, (.13, .33), .8, .6, graph_width=2) g.draw() try: tb = TextBox.datetime_box( date, graph_files[-1].get_last_measurement_time(), i) except IndexError: tb = TextBox("Data from " + date.to_string_display() + ' ' + 'Chamber ' + str(convert(i)).replace('_', ' '), (.5, .02), is_cell=True) tb.draw() for i in range(0, len(img)): configure_draw_parameters(img[i].width, img[i].height, draw[i].line, draw[i].text) flow.draw() flowmeter_file.close() except IOError: print("Flowmeter not found") pass try: print(date.tostring() + ' at ' + Time.get_time_without_seconds( graph_files[0].get_last_measurement_time())) except IndexError: print(date.tostring()) if lab_computer == black: save_str = 'fridgelogB_' else: save_str = 'fridgelog_' for i in range(0, len(img)): try: img[i].save(save_to_location + save_str + str(convert(i)) + '.png') except IOError: file = open(save_to_location + save_str + str(convert(i)) + '.png', 'w+') img[i].save(save_to_location + save_str + str(convert(i)) + '.png') file.close() img[i].close() if i < len(graph_files): graph_files[i].close()
def main_m(): table_files = [] date = get_most_recent_record_date(Date(str(datetime.now()))) yt = ('T', 'P') units = ('numeral', 'K', 'numeral', 'bar') xt = (1, 2, 5, 6) pressure_chambers = (2, 3, 1, 4) try: print('running backup program: ' + date.tostring()) except IndexError: print(date.tostring()) # print("collecting data from " + date.tostring()) for y in range(0, len(yt)): table_files.append([]) for x in range(0, len(xt)): try: if y == 0: table_files[y].append( FridgeFile(date.tostring(), str(yt[y]), xt[x])) else: table_files[y].append( FridgeFile(date.tostring(), str(yt[y]))) table_files[y][x].open() except IOError: print(table_files[y][x].tostring() + ' not found') table_files[y][x] = None pass img = Image.new('RGB', (width, height), bg_color) draw = ImageDraw.Draw(img) data = [[]] data[0] = ['40k', '4k', 'Still', 'MC'] data.append([]) for x in table_files[0]: if x is not None: data[1].append(str(x.get_last_measurement())) else: data[1].append("no data") data.append([]) data[2] = ['Still', 'Condense', 'OVC', 'Scroll 1'] data.append([]) for x in pressure_chambers: try: data[3].append(table_files[1][0].get_last_measurement(chamber=x) / 1000) except AttributeError: print("file not found") data[3].append("no data") pass try: flowmeter_file = FridgeFile(date.tostring(), 'Flowmeter') data[1].append("Flowmeter") flowmeter_file.open() data[2].append(flowmeter_file.get_last_measurement()) flowmeter_file.close() except IOError: print("Flowmeter not found") data[2].append("no data") pass datetext = TextBox(date.to_string_display(), [.5, .05]) textboxes = [[]] for i in range(0, len(data)): textboxes.append([]) for j in range(0, len(data[i])): if data[i][j] is not None: if units[i] is not "numeral": textboxes[i].append( TextBox(str(data[i][j]), [(i + 1) / (len(data) + 1) - .04, (j + 1) / (len(data[0]) + 1) - .07], units=units[i])) else: textboxes[i].append( TextBox(str(data[i][j]), [(i + 1) / (len(data) + 1) - .04, (j + 1) / (len(data[0]) + 1) - .07])) else: textboxes[i].append( TextBox("", [(i + 1) / (len(data) + 1) - .04, (j + 1) / (len(data[0]) + 1) - .07])) for i in range(0, len(data)): for j in range(0, len(data[i])): if data[i][j] is not None: configure_draw_parameters(img.width, img.height, draw.line, draw.text) textboxes[i][j].draw() datetext.draw('#000000') if lab_computer == black: save_loc = 'fridgelogB.png' else: save_loc = 'fridgelog.png' try: img.save(save_to_location + save_loc) except IOError: file = open(save_to_location + save_loc, 'w+') img.save(save_to_location + save_loc) file.close() img.close() for y in range(0, len(table_files)): for x in range(0, len(table_files[y])): if table_files[y][x] is not None: table_files[y][x].close()
def update_count(self, count): self.unpin(self.textbox) self.textbox = TextBox(str(count), "Courier", "40", font_color="black") self.pin(self.textbox, -30, 0)
def display_message(self, msg): self.board.unpin(self.message_box) self.message_box = TextBox(msg, "Helvetica Neue", 20, "#0000FF") self.board.pin(self.message_box, self.board.get_width() // 2, 10)