class PdsPlugin: def __init__(self, matrix=True, delay=0.2): self.matrix = matrix self.author = 'Infected' self.name = 'PDS Plugin' self.version = '0.1a' self.image = Image(64, 16) self.screen = Screen(matrix=matrix, show=True, fps=int(delay)) self.screen.add(self.image, mode="invert") # self.monitor = Stream(matrix=self.matrix) # self.delay = float(delay) def get_info(self): """Get the current state and information of the plugin""" print(self.name, self.author, self.version, sep='\n') def get_delay(self): return self.delay def get_image(self): return self.image def set_pixmap(self, pixmap): self.image.set_pixmap(pixmap) def get_pixmap(self): return self.image.get_pixmap() def stream(self): self.screen.refresh() def blank(self): self.image.blank()
def __init__(self, token): super(UnifiedCLIClient, self).__init__() self.token = token self.screen = Screen() self.__connected = False self.__logged = False self.loop = asyncio.get_event_loop() atexit.register(self.terminate)
class ClockPlugin: def __init__(self): self.author = 'Infected' self.name = 'Clock Plugin' self.version = 'V3.23-4.2-DOS.26__release' self.time = datetime.now() self.timer = Text() self.canvas = Image(64, 16) self.time_frame = Image(64, 16) self.canvas_draw = Drawer(self.canvas) self.invert = Image(64, 16) self.invert.fill() self.screen = Screen(matrix=True, show=False, fps=15) self.screen.add(self.time_frame, refresh=True) self.screen.add(self.timer, refresh=True, x=3, y=3) self.screen.add(self.canvas, refresh=False) self.screen.add(self.invert, mode='invert', refresh=False) self.gen_canvas() def get_info(self): """Get the current state and information of the plugin""" print(color(self.name, "red"), color(self.author, "green"), color(self.version, "magenta"), sep='\n') def gen_canvas(self): self.canvas_draw.line(0, 0, 63, 0) self.canvas_draw.line(0, 0, 0, 15) self.canvas_draw.line(0, 15, 63, 15) self.canvas_draw.line(63, 0, 63, 15) def refresh(self): self.time = datetime.now() def print_time(self): self.timer.edit('{}:{}:{}'.format( str(self.time.hour).zfill(2), str(self.time.minute).zfill(2), str(self.time.second).zfill(2)), font='fontbignum') def stream(self): self.refresh() self.print_time() self.screen.refresh()
def __init__(self): msg("input()", 2, "Hbd_plugin.__init__()") self.name_label = input(color("Enter label: ", "red")).lower() self.name_text = input(color("Enter name: ", "yellow")).lower() self.mask = Image(64,16) self.mask.fill() self.bg = Image(64, 16) self.drawer = Drawer(self.bg) self.drawer.dot(0, 0) self.drawer.dot(0, 15) self.drawer.dot(63, 0) self.drawer.dot(63, 15) self.label = Text(text="§" + self.name_label + "§") self.name = Text(text=self.name_text) self.screen = Screen(matrix=True, show=True, fps=1.7, tty='/dev/ttyACM1') self.screen.add(self.bg, refresh=False) xloc_label = (64 - abs(self.label.width)) // 2 self.screen.add(self.label, x=xloc_label, y=1, refresh=False) xloc_text = (64 - abs(self.name.width)) // 2 self.screen.add(self.name, x=xloc_text, y=8, refresh=False) self.screen.add(self.mask, refresh=False, mode="invert")
def __init__(self): self.screen = Screen(matrix=False, show=True, fps=23) self.label = Text() self.drawing = Image(64, 16) self.drawer = Drawer(self.drawing) self.screen.add(self.drawing) self.screen.add(self.label)
class Hbd_plugin: def __init__(self): msg("input()", 2, "Hbd_plugin.__init__()") self.name_label = input(color("Enter label: ", "red")).lower() self.name_text = input(color("Enter name: ", "yellow")).lower() self.mask = Image(64,16) self.mask.fill() self.bg = Image(64, 16) self.drawer = Drawer(self.bg) self.drawer.dot(0, 0) self.drawer.dot(0, 15) self.drawer.dot(63, 0) self.drawer.dot(63, 15) self.label = Text(text="§" + self.name_label + "§") self.name = Text(text=self.name_text) self.screen = Screen(matrix=True, show=True, fps=1.7, tty='/dev/ttyACM1') self.screen.add(self.bg, refresh=False) xloc_label = (64 - abs(self.label.width)) // 2 self.screen.add(self.label, x=xloc_label, y=1, refresh=False) xloc_text = (64 - abs(self.name.width)) // 2 self.screen.add(self.name, x=xloc_text, y=8, refresh=False) self.screen.add(self.mask, refresh=False, mode="invert") def stream(self): try: blink = False while True: blink = not blink if blink: self.mask.blank() else: self.mask.fill() self.screen.refresh() except KeyboardInterrupt: print() msg(self.name_label, 0, "label") msg(self.name_text, 0, "name") exit()
def __init__(self, matrix=True, delay=0.2): self.matrix = matrix self.author = 'Infected' self.name = 'PDS Plugin' self.version = '0.1a' self.image = Image(64, 16) self.screen = Screen(matrix=matrix, show=True, fps=int(delay)) self.screen.add(self.image, mode="invert")
def __init__(self): self.screen = Screen(matrix=False, show=False, fps=35) self.label = Text("download") self.loading = Text(font="fontbignum") self.percent = Text("0%") self.load = [' l','/','-','\\'] self.screen.add(self.label, refresh=False, x=0, y=0) self.screen.add(self.loading, refresh=True, x=29, y=8) self.screen.add(self.percent, refresh=False, x=0, y=6)
class CrepeBot(ApplicationSession): def __init__(self, *args,**kwargs): super(CrepeBot, self).__init__(*args, **kwargs) self.screen = Screen(matrix=True, show=True) self.pbm = Image() self.bar = Image() self.splash = Text('init v1.0') self.percentage_text = Text('0') self.bar_x = 40 self.bar_y = 7 self.screen.add(self.pbm, 0, 0, False) self.screen.add(self.bar, self.bar_x, self.bar_y, True) self.screen.add(self.splash, 25, 0, True) self.screen.add(self.percentage_text, 40, 10, True) @coroutine def onJoin(self, details): def onRefresh(*queue): try: self.refresh(queue[0]['percent'], queue[0]['name']) except ValueError as e: print(e) except IndexError as e: print(e) print(queue) self.subscribe(onRefresh, 'queue') def refresh(self, percentage, name): self.splash.edit(str(name).lower) self.refresh_bar(percentage) self.percentage_text.edit(str(percentage) + '%') self.screen.refresh() def refresh_bar(self, percentage): self.bar.draw_line(x1=0, y1=0, x2=percentage // 5, y2=0) self.bar.draw_line(x1=0, y1=1, x2=percentage // 5, y2=1)
def __init__(self, *args,**kwargs): super(CrepeBot, self).__init__(*args, **kwargs) self.screen = Screen(matrix=True, show=True) self.pbm = Image() self.bar = Image() self.splash = Text('init v1.0') self.percentage_text = Text('0') self.bar_x = 40 self.bar_y = 7 self.screen.add(self.pbm, 0, 0, False) self.screen.add(self.bar, self.bar_x, self.bar_y, True) self.screen.add(self.splash, 25, 0, True) self.screen.add(self.percentage_text, 40, 10, True)
def __init__(self): self.author = 'Infected' self.name = 'Clock Plugin' self.version = 'V3.23-4.2-DOS.26__release' self.time = datetime.now() self.timer = Text() self.canvas = Image(64, 16) self.time_frame = Image(64, 16) self.canvas_draw = Drawer(self.canvas) self.invert = Image(64, 16) self.invert.fill() self.screen = Screen(matrix=True, show=False, fps=15) self.screen.add(self.time_frame, refresh=True) self.screen.add(self.timer, refresh=True, x=3, y=3) self.screen.add(self.canvas, refresh=False) self.screen.add(self.invert, mode='invert', refresh=False) self.gen_canvas()
class ExamplePlugin: def __init__(self): self.screen = Screen(matrix=False, show=True, fps=23) self.label = Text() self.drawing = Image(64, 16) self.drawer = Drawer(self.drawing) self.screen.add(self.drawing) self.screen.add(self.label) def stream(self): for i in range(1, 101): self.drawer.line(i, 0, 9, i) self.label.edit(str(i)) self.screen.refresh() msg("Progression", 0, None, i)
class Updater: """ Class that simply serves to provide a live update to the matrix for the user drawing on the gui drawer """ def __init__(self, interface): self.interface = interface self.screen = Screen(matrix=False, guishow=True, fps=50) self.screen.add(self.interface.image, refresh=False) self.live = False def one_refresh(self): self.screen.refresh() def toggle_live(self): while self.live: self.screen.refresh()
class LoadPlugin: def __init__(self): self.screen = Screen(matrix=False, show=False, fps=35) self.label = Text("download") self.loading = Text(font="fontbignum") self.percent = Text("0%") self.load = [' l','/','-','\\'] self.screen.add(self.label, refresh=False, x=0, y=0) self.screen.add(self.loading, refresh=True, x=29, y=8) self.screen.add(self.percent, refresh=False, x=0, y=6) def stream(self): msg("Starting download...", 2, "Download", "0%") for p in range(0,101): self.percent.blank() self.percent.edit(p, font="fontbignum") for i in self.load: self.loading.edit(i) self.screen.refresh() msg("Downloading...", 1, "Download", "{0}%".format(p)) msg("Done", 0, "Download", "100%")
from libs.streamtools import Stream from libs.image import Image from libs.drawer import Drawer from libs.screen import Screen from libs.text import Text from libs.slide import Slide from libs.rainbow import msg, color if __name__ == '__main__': scr = Screen(matrix=True, show=False, fps=60, tty='/dev/ttyACM0') aa = Text("the slide frame works!") slide = Slide(aa) scr.add(slide) while True: slide.refresh() scr.refresh()
def __init__(self, interface): self.interface = interface self.screen = Screen(matrix=False, guishow=True, fps=50) self.screen.add(self.interface.image, refresh=False) self.live = False
#!/usr/bin/env python3 from libs.screen import Screen from libs.image import Image from libs.text import Text from os import system screen = Screen(matrix=True, show=True, fps=2555) label_1 = Text() label_2 = Text() screen.add(label_1, y=1) screen.add(label_2, y=9) while True: try: label_1.edit(input('Text line 1: ')) label_2.edit(input('Text line 2: ')) screen.refresh() except KeyboardInterrupt: print('\nEND') exit()
# -*- coding: utf-8 -*- from datetime import datetime from libs.screen import Screen from libs.result import Result url = 'https://www.google.co.jp/' screen = Screen() screen.open(url) screen.wait('body') screen.snapshot('google') # Save capture and HTML # Sample of store to database record = {} record['url'] = url record['html'] = screen.get_html() record['scraped_at'] = datetime.now() result = Result() result.save(record)
class UnifiedCLIClient(discord.Client): """ Discordのクライアント。 """ def __init__(self, token): super(UnifiedCLIClient, self).__init__() self.token = token self.screen = Screen() self.__connected = False self.__logged = False self.loop = asyncio.get_event_loop() atexit.register(self.terminate) async def launch(self): self.screen.initialize() greetings = \ " U n i f i e d C L I \n" + \ "D i s c o r d V i e w e r\n" grt_max_width = max([len(x) for x in greetings.split("\n")]) width, height = self.screen.get_size() self.screen.put_multiline( (width // 2 - grt_max_width // 2, 3), greetings) self.screen.put_x_center(6, "Logging in to Discord...") await self.login(self.token) self.__logged = True self.screen.put_x_center(6, "Connecting to the Server...") asyncio.ensure_future(self.connect()) # on_ready() 関数でこのフラグの値が変わります while not self.__connected: await asyncio.sleep(0.2) self.screen.console.clear() await self.mainloop() def terminate(self): if self.__logged: self.loop.run_until_complete(self.logout()) if self.__connected: self.loop.run_until_complete(self.close()) atexit.unregister(self.terminate) async def on_ready(self): self.__connected = True async def mainloop(self): locale.setlocale(locale.LC_ALL, "") root_w, root_h = self.screen.get_size() header_win = self.screen.create_window((0, 0), (root_w, 1)) read_win = self.screen.create_window((0, 1), (root_w, root_h - 4)) write_win = self.screen.create_window((0, root_h - 3), (root_w, 3)) write_win.nodelay(True) write_win.keypad(True) self.screen.console.clear() self.screen.console.refresh() inputted = "" channels = self.get_available_channel() sel_chn_idx = 0 while True: # ------------------------- # Text Input # ------------------------- # ----- Normal Input typed = bytearray() control_key = False while True: input_chr = write_win.getch() if input_chr == curses.ERR: break if not (0 <= input_chr <= 256): control_key = True break typed.append(input_chr) # ---- Key Binding if control_key: if input_chr == curses.KEY_UP and sel_chn_idx > 0: sel_chn_idx -= 1 elif input_chr == curses.KEY_DOWN and sel_chn_idx < len(channels) - 1: sel_chn_idx += 1 elif input_chr == curses.KEY_BACKSPACE: inputted = inputted[:-1] elif len(typed) > 0: if typed[0] in (10, 13): if len(inputted) > 0: asyncio.ensure_future( channels[sel_chn_idx].send(inputted)) inputted = "" else: text = typed.decode() inputted += text # ------------------------- # Screen Update # ------------------------- # ----- Erase read_win.erase() write_win.erase() header_win.erase() # ----- Screen Initialize Phase write_win.border("|", "|", "-", "-") header_win.bkgdset(" ", self.screen.get_color_pair(1)) # ----- Screen Drawing # --- Header header_win.addstr(0, 0, self.guilds[0].name) # --- Textbox (ish) cutted = charutil.right_visibility(root_w - 2, inputted) write_win.addstr(1, 1, cutted) write_win.addstr(0, 1, " " + channels[sel_chn_idx].name + " ", curses.A_BOLD) if inputted != cutted: write_win.addstr(1, 0, "<") write_win.move(1, 1 + charutil.get_visible_len(cutted)) # --- Message messages = self.calc_visible_message(root_w - 2, root_h - 4, pad=2) y = 1 for message in messages: read_win.addstr(y, 1, message.channel.name + " / " + message.author.name) lines = charutil.get_wrapped(root_w - 2, message.content) read_win.hline(y - 1, 0, "-", root_w) read_win.addstr(y, 10, str(len(lines))) for i in range(len(lines)): read_win.addstr(y + i + 1, 1, lines[i]) y += len(lines) + 2 # ----- Screen Updating header_win.refresh() read_win.refresh() write_win.refresh() # ----- Cleaning up await asyncio.sleep(1 / 30) async def on_error(self, event_method, *args, **kwargs): e = sys.exc_info() width, height = self.screen.get_size() self.screen.put_str((0, height - 1), e[1]) # ----- Utility Functions ----- def get_available_channel(self): channels = self.get_all_channels() available = filter(lambda x: isinstance( x, discord.TextChannel), channels) return list(available) def calc_visible_message(self, width, height, pad=1): """ メッセージ表示に必要な行数を計算し、 画面に収まりきるメッセージの配列を返す。 :self width: 表示領域の横幅。 :self height: 表示領域の縦幅。 :self pad: [デフォ値=1] 計算補正値。 """ cached_mes = list(self.cached_messages).copy() cached_mes.reverse() cached_mes_heights = [len(charutil.get_wrapped(width, x.content)) + pad for x in cached_mes] height_comsum = [sum(cached_mes_heights[:i+1]) for i in range(len(cached_mes_heights))] i = 0 for i in range(len(height_comsum) + 1): if len(height_comsum) == i or height_comsum[i] > height: break return cached_mes[: i][:: -1]