def save(self, filename): #if not self.app.logen.check_string_syntax(self.text.get("1.0", "end")): # return False #steve remove parse check... ScrollText.save(self, filename) return True
def __init__(self,master=None, text="",readonly=True,app=None): ScrollText.__init__(self,master=master,text=text,readonly=readonly) self.app = app app.pref.register_listener('syntax highlights', self.colours_changed) self.colours_changed(app.colours.syn_colour) self.text.tag_configure("hilite", background="grey") ## force the selection cursor to have higher priority than ## all annotations self.text.tag_raise("sel",aboveThis="hilite")
def main(): try: fps = 50 surface = pygame.display.set_mode((600, 600)) pygame.init() origin = (surface.get_width() / 2, surface.get_height() / 2) theta = 1 step = math.pi / 180 center_x = surface.get_width() / 2 center_y = surface.get_height() / 2 # Cube( surface, color, center3d, size) spheres = ( Fire(surface, pygame.Rect(100, 100, 400, 200), 2), Sphere(surface, (100, 0, 0), Vec3d(-1.5, -1.5, -1.5), Vec3d(1, 1, 1)), #Sphere(surface, (100, 0, 0), Vec3d(0, 0, 0), Vec3d(1, 1, 1)), #Sphere(surface, (100, 0, 0), Vec3d(1.5, 1.5, 1.5), Vec3d(1, 1, 1)), Circle(surface, (100, 0, 0), Vec3d(1.5, -1.5, -1.5), Vec3d(1, 1, 1)), Tree(surface, pygame.Color(0, 100, 100), Vec2d(300, 500), 5, 50), Tree(surface, pygame.Color(0, 100, 100), Vec2d(330, 500), 5, 100), Starfield(surface, stars=100, depth=10), InfoRenderer(surface, pygame.Color(0, 255, 0), pos=Vec2d(100, 100), size=10), ScrollText(surface, "Dolor Ipsum Dolor uswef", 400, pygame.Color(255, 255, 0)), SinusText(surface, "Dolor Ipsum Dolor uswef", 200, 30, 2, pygame.Color(0, 255, 255)), ) clock = pygame.time.Clock() size_angle = 0 size_angle_step = math.pi / 720 cg = ColorGradient(0.0, 0.05, 0.05) background_gradient = GradientBackground(surface) # for 3d projection fov = 2 viewer_distance = 256 pause = False while True: clock.tick(fps) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit(0) keyinput = pygame.key.get_pressed() if keyinput is not None: # print keyinput if keyinput[pygame.K_ESCAPE]: sys.exit(1) #if keyinput[pygame.K_z]: # theta[2] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_z]: # theta[2] -= math.pi / 180 #if keyinput[pygame.K_x]: # theta[0] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_x]: # theta[0] -= math.pi / 180 #if keyinput[pygame.K_y]: # theta[1] += math.pi / 180 #if keyinput[pygame.KMOD_SHIFT | pygame.K_y]: # theta[1] -= math.pi / 180 if keyinput[pygame.K_UP]: viewer_distance += 1 if keyinput[pygame.K_DOWN]: viewer_distance -= 1 if keyinput[pygame.K_PLUS]: fov += .1 if keyinput[pygame.K_MINUS]: fov -= .1 if keyinput[pygame.K_p]: pause = not pause if keyinput[pygame.K_r]: viewer_distance = 256 fov = 2 if pause is not True: surface.fill((0, 0, 0, 255)) background_gradient.update() for thing in spheres: if type(thing) == InfoRenderer: thing.update(lines=("viewer_distance : %f" % viewer_distance, "fov: %f" % fov)) continue elif type(thing) == Tree: thing.update() continue elif type(thing) in ( Sphere, Circle, ): # rotate thing.rotate(dx=theta, dy=theta, dz=0.0, offset2d=Vec2d(0, 0)) theta += step * 16 # color changing color = cg.get_color() thing.set_color(color=color) # size wobbling # size_angle += size_angle_step # thing.set_size(0.5 + math.sin(size_angle) * 0.125) # draw thing.update(viewer_distance=viewer_distance, fov=fov) continue elif type(thing) in ( SinusText, ScrollText, ): thing.update() elif type(thing) == Tree: thing.update(center=Vec2d(0, 0), viewer_distance=viewer_distance, fov=fov) else: thing.update() pygame.display.flip() except KeyboardInterrupt: print('shutting down')
def loop(): if not gui.initialized: if config.MOUSE_VISIBLE: pygame.mouse.set_visible(config.MOUSE_VISIBLE) pygame.display.set_caption(localized_strings.title) gui.initialized = True perform_key_events() screen.fill(color=COLOR_BLUE_DARK) screen.image("res/images/banner-911778_1280.jpg", xy=(0, 0), align="top") if alarm.current_alarm is not None: # Alarm currently firing - Show the Alarm Page screen.text(ALARM_LABEL_TITLE["text"] % alarm.current_alarm, xy=ALARM_LABEL_TITLE["xy"], color=ALARM_LABEL_TITLE["color"], font_size=ALARM_LABEL_TITLE["font_size"], align=ALARM_LABEL_TITLE["align"]) p.player.mute() else: for child in gui.root[gui.current_page - 1]: name = child.get("name") position = child.find("position") align = child.get("align") xy = None if position is not None: xy = (int(position.get("x")), int(position.get("y"))) if child.tag in ["text", "rectangle", "scroll_text"]: color_node = child.find("color") color = (int(color_node.get("red")), int(color_node.get("green")), int(color_node.get("blue"))) if child.tag == "text": font_size = int(child.get("font_size")) text = child.find("text").text if name == "time": text = gui.current_time elif name == "date": text = gui.current_date elif name == "time_sep" and time.localtime( ).tm_sec % 2 != 1: continue if gui.current_page == PAGE_INDEX_RADIO: if child.get("name") == "station_name": text = gui.radio_station_name_text + '' screen.text(text, color=color, xy=xy, align=align, font_size=font_size) elif child.tag == "scroll_text": font_size = int(child.get("font_size")) text = child.find("text").text hpos = int(child.get("hpos")) margin_node = child.find("margin") margin = (int(margin_node.get("left")), int(margin_node.get("right"))) if gui.current_page == PAGE_INDEX_RADIO: if name == "station_info": text = gui.radio_station_info_text + '' if name not in gui.scroll_texts: gui.scroll_texts[name] = ScrollText( screen.surface, text, hpos, color, margin, font_size, font=os.path.join( os.path.dirname(inspect.getfile(tingbot)), 'Geneva.ttf')) else: gui.scroll_texts[name].update_text(text) gui.scroll_texts[name].update() elif child.tag == "rectangle": size_node = child.find("size") align = child.get("align") size = (int(size_node.get("w")), int(size_node.get("h"))) screen.rectangle(xy=xy, size=size, color=color, align=align) elif child.tag == "image": scale = float(child.get("scale")) src = child.get("src") screen.image(src, xy=xy, scale=scale, align=align)
def draw_radio_page(): screen.text( gui.current_time, #xy=(160, 20), #font_size=40, #color=COLOR_BLUE_LIGHT, xy=PAGE_RADIO_TEXT_TIME["xy"], font_size=PAGE_RADIO_TEXT_TIME["font_size"], color=PAGE_RADIO_TEXT_TIME["color"], align=PAGE_RADIO_TEXT_TIME["align"]) if time.localtime().tm_sec % 2 == 1: # Blink the time separator every second by # display it every other second screen.text( ":", #xy=(160, 20), #font_size=40, #color=COLOR_BLUE_LIGHT, xy=PAGE_RADIO_TEXT_TIME["xy"], font_size=PAGE_RADIO_TEXT_TIME["font_size"], color=PAGE_RADIO_TEXT_TIME["color"], align=PAGE_RADIO_TEXT_TIME["align"]) screen.text( gui.current_date, #xy=(160, 50), #font_size=20, #color=COLOR_TAN xy=PAGE_RADIO_TEXT_DATE["xy"], font_size=PAGE_RADIO_TEXT_DATE["font_size"], color=PAGE_RADIO_TEXT_DATE["color"], align=PAGE_RADIO_TEXT_DATE["align"]) # Radio Info Panel outer border screen.rectangle( #xy=(8,70), #size=(304,108), #color=COLOR_TAN, #align="topleft" xy=PAGE_RADIO_RECT_INFO_PANEL_OUTER["xy"], size=PAGE_RADIO_RECT_INFO_PANEL_OUTER["size"], color=PAGE_RADIO_RECT_INFO_PANEL_OUTER["color"], align=PAGE_RADIO_RECT_INFO_PANEL_OUTER["align"]) # Radio Info Top Panel - playback buttons and info screen.rectangle( #xy=(10,72), #size=(300,69), #color=COLOR_BLUE_DARK, #align="topleft" xy=PAGE_RADIO_RECT_INFO_PANEL_TOP["xy"], size=PAGE_RADIO_RECT_INFO_PANEL_TOP["size"], color=PAGE_RADIO_RECT_INFO_PANEL_TOP["color"], align=PAGE_RADIO_RECT_INFO_PANEL_TOP["align"]) # Radio Info Bottom Panel - Stream info (stream name and title/info) screen.rectangle( #xy=(10,143), #size=(300,33), #color=COLOR_BLUE_DARK, #align="topleft" xy=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["xy"], size=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["size"], color=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["color"], align=PAGE_RADIO_RECT_INFO_PANEL_BOTTOM["align"]) # Setup of the Stream Name and Title/Info radio_info = '(none)' # Initial value of the Stream Info station_name = p.player.get_name( ) # Get the Stream Name from the player output if station_name is None and 'name' in p.get_active_channel(): # If the Stream Name could not be set/not yet set from the player output, # then set the Station Name to the name from the station list instead station_name = p.get_active_channel()['name'] if p.player.title is not None: radio_info = p.player.title else: radio_info = '(none)' # if p.player.info is not None: # If the Player info is set, then try to get the latest StreamTitle (Info) # radio_info = p.player.info.get("StreamTitle") #else: # Otherwise, set the Info to the default "(none)" value #radio_info = '(none)' if radio_info is None: # If the Player info was set but the latest StreamTitle (Info) was not, # then set the Info to the default "(none)" value radio_info = '(none)' if current_coding is not None: # try decode the radio_info with the current coding # This is necessary with Windows systems where the # encoding is not Unicode or ASCII radio_info = radio_info.decode(current_coding) try: station_name = station_name.decode(current_coding) except Exception: station_name = p.get_active_channel()['name'] # Update the Web Frontend API Data with the current radio info web_frontend.api_data["radio"]["station"] = station_name # p.get_active_channel()['name'] web_frontend.api_data["radio"]["info"] = radio_info # radio_info = filter(onlyascii, radio_info) # radio_info = ''.join(c if is_ascii(c) else onlyascii(c) for c in radio_info) # radio_info = filter(lambda x: x in string.printable, radio_info) # Draw the Station Name at the start/top in the bottom info panel screen.text( station_name, #xy=(13, 143), #font_size=15, #color=COLOR_TAN, #align="topleft" xy=PAGE_RADIO_TEXT_STATION_NAME["xy"], font_size=PAGE_RADIO_TEXT_STATION_NAME["font_size"], color=PAGE_RADIO_TEXT_STATION_NAME["color"], align=PAGE_RADIO_TEXT_STATION_NAME["align"]) # Draw the Station Info at the end/bottom in the bottom info panel if gui.radio_info_scroll_text is None: gui.radio_info_scroll_text = ScrollText( screen.surface, radio_info, 159, COLOR_BLUE_LIGHT, (12, 12), 15, font=os.path.join(os.path.dirname(inspect.getfile(tingbot)), 'Geneva.ttf')) else: gui.radio_info_scroll_text.update_text(radio_info) gui.radio_info_scroll_text.update() # pygame.display.flip() #screen.text( # radio_info, # xy=(12, 159), # font_size=15, # color=COLOR_BLUE_LIGHT, # align="topleft" #) # Play Button - Drawn at the left in the top info panel screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_play_circle_outline_white_24dp.png", #xy=(21,81), #align="topleft" PAGE_RADIO_BUTTON_PLAY["src"], xy=PAGE_RADIO_BUTTON_PLAY["xy"], scale=PAGE_RADIO_BUTTON_PLAY["scale"], align=PAGE_RADIO_BUTTON_PLAY["align"]) # Pause button - Drawn to the right of the Play button in the top info panel screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_pause_circle_outline_white_24dp.png", #xy=(81,81), #align="topleft" PAGE_RADIO_BUTTON_PAUSE["src"], xy=PAGE_RADIO_BUTTON_PAUSE["xy"], scale=PAGE_RADIO_BUTTON_PAUSE["scale"], align=PAGE_RADIO_BUTTON_PAUSE["align"]) # Previous Station button - Drawn at the bottom left of the screen window screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_previous_white_24dp.png", #xy=(11,181), #align="topleft" PAGE_RADIO_BUTTON_STATION_PREV["src"], xy=PAGE_RADIO_BUTTON_STATION_PREV["xy"], scale=PAGE_RADIO_BUTTON_STATION_PREV["scale"], align=PAGE_RADIO_BUTTON_STATION_PREV["align"]) # Next Station button - Drawn to the right of the Previous Station button # at the bottom of the screen window screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_skip_next_white_24dp.png", #xy=(71,181), #align="topleft" PAGE_RADIO_BUTTON_STATION_NEXT["src"], xy=PAGE_RADIO_BUTTON_STATION_NEXT["xy"], scale=PAGE_RADIO_BUTTON_STATION_NEXT["scale"], align=PAGE_RADIO_BUTTON_STATION_NEXT["align"]) # Volume Down button - Drawn to the right of the Next Station button at # the bottom center of the screen window screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_down_white_24dp.png", #xy=(131,181), #align="topleft" PAGE_RADIO_BUTTON_VOL_DOWN["src"], xy=PAGE_RADIO_BUTTON_VOL_DOWN["xy"], scale=PAGE_RADIO_BUTTON_VOL_DOWN["scale"], align=PAGE_RADIO_BUTTON_VOL_DOWN["align"]) # Volume Up button - Drawn to the right of the Volume Down button at # the bottom of the screen window screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_up_white_24dp.png", #xy=(191,181), #align="topleft" PAGE_RADIO_BUTTON_VOL_UP["src"], xy=PAGE_RADIO_BUTTON_VOL_UP["xy"], scale=PAGE_RADIO_BUTTON_VOL_UP["scale"], align=PAGE_RADIO_BUTTON_VOL_UP["align"]) # Volume Mute button - Drawn at the bottom right of the screen window screen.image( #"res/icons/material-design-icons-2.0/av/2x_web/ic_volume_mute_white_24dp.png", #xy=(251,181), #align="topleft" PAGE_RADIO_BUTTON_VOL_MUTE["src"], xy=PAGE_RADIO_BUTTON_VOL_MUTE["xy"], scale=PAGE_RADIO_BUTTON_VOL_MUTE["scale"], align=PAGE_RADIO_BUTTON_VOL_MUTE["align"])