def _scroll(self, start, stop, rows): if not rows: return csbi = GetConsoleScreenBufferInfo(HSTDOUT) # absolute position of window in screen buffer # interpret other coordinates as relative to the window window = csbi.srWindow # scroll region clip_rect = wintypes.SMALL_RECT( window.Left, window.Top + start, window.Right, window.Top + stop ) if rows > 0: region = wintypes.SMALL_RECT(window.Left, window.Top + rows, window.Right, window.Bottom) new_pos = wintypes._COORD(window.Left, window.Top) else: # minus signs since rows is a negative number region = wintypes.SMALL_RECT(window.Left, window.Top, window.Right, window.Bottom - rows) new_pos = wintypes._COORD(window.Left, window.Top - rows) # workaround: in this particular case, Windows doesn't seem to respect the clip area. if ( clip_rect.Bottom == window.Bottom-1 and region.Bottom >= window.Bottom-1 and new_pos.Y < region.Top ): # first scroll everything up clip_rect.Bottom = window.Bottom bottom, region.Bottom = region.Bottom, window.Bottom ScrollConsoleScreenBuffer(HSTDOUT, region, clip_rect, new_pos, u' ', self._attrs) # and then scroll the bottom back down new_pos.Y = window.Bottom region.Top = bottom-1 ScrollConsoleScreenBuffer(HSTDOUT, region, clip_rect, new_pos, u' ', self._attrs) else: ScrollConsoleScreenBuffer(HSTDOUT, region, clip_rect, new_pos, u' ', self._attrs)
def write(cls, handle, unistr): """Write character to console, avoid scroll on bottom line.""" csbi = CONSOLE_SCREEN_BUFFER_INFO() _GetConsoleScreenBufferInfo(handle, byref(csbi)) col, row = csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y width, height = csbi.dwSize.X, csbi.dwSize.Y for ch in unistr: if (col >= width - 1 and ch not in (u'\n', u'\b', u'\r') and not cls._overflow): ci = CHAR_INFO(ch, csbi.wAttributes) # do not advance cursor if we're on the last position of the # screen buffer, to avoid unwanted scrolling. _WriteConsoleOutputW(handle, byref(ci), wintypes._COORD(1, 1), wintypes._COORD(0, 0), wintypes.SMALL_RECT(col, row, col, row)) else: if cls._overflow and ch not in (u'\n', u'\r', u'\b'): _WriteConsoleW(handle, u'\r\n', 1, byref(wintypes.DWORD()), byref(wintypes.DWORD())) col = 0 cls._overflow = False _WriteConsoleW(handle, ch, 1, byref(wintypes.DWORD()), byref(wintypes.DWORD())) # if we don't include \n here we get glitches on regular console writes # is it necessary to treat CR and LF separately *in raw mode*? # i.e. in raw mode, shouldn't LF just move a line down without changing the column? if ch in (u'\r', u'\n'): col = 0 cls._overflow = False elif ch == u'\b': col = max(col - 1, 0) cls._overflow = False else: col = min(col + 1, width - 1)
def setPosition(self, left, top, right, bottom, handle=None): if not handle: handle = self.hdl #rect = wintypes.SMALL_RECT(0, 0, 100, 80) # (left, top, right, bottom) rect = wintypes.SMALL_RECT(left, top, right, bottom) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(handle, True, byref(rect))
def resize(self, height, width): """Resize terminal.""" csbi = GetConsoleScreenBufferInfo(self._hstdout) # SetConsoleScreenBufferSize can't make the buffer smaller than the window # SetConsoleWindowInfo can't make the window larger than the buffer (in either direction) # allow for both shrinking and growing by calling one of them twice, # for each direction separately new_size = wintypes._COORD(width, csbi.dwSize.Y) new_window = wintypes.SMALL_RECT(0, 0, width - 1, csbi.dwSize.Y - 1) _SetConsoleScreenBufferSize(self._hstdout, new_size) _SetConsoleWindowInfo(self._hstdout, True, new_window) _SetConsoleScreenBufferSize(self._hstdout, new_size) new_size = wintypes._COORD(width, height) new_window = wintypes.SMALL_RECT(0, 0, width - 1, height - 1) _SetConsoleScreenBufferSize(self._hstdout, new_size) _SetConsoleWindowInfo(self._hstdout, True, new_window) _SetConsoleScreenBufferSize(self._hstdout, new_size)
def setup_console(self, buffer=0): if getattr(sys, 'frozen', False) and self.os == 'Windows': if buffer > 0: windll.kernel32.SetConsoleScreenBufferSize(self.chandle, wintypes._COORD(100, 100 + round(buffer, -2))) else: windll.kernel32.SetConsoleWindowInfo(self.chandle, True, byref(wintypes.SMALL_RECT(0, 0, 99, 49))) windll.kernel32.SetConsoleScreenBufferSize(self.chandle, wintypes._COORD(100, 50)) elif self.os == 'Darwin': set_terminal_size(100, 50)
def set_console_size(buffer_width, buffer_height, window_width, window_height): """设备窗口的缓冲区大小及窗口大小""" stdout = -11 hdl = windll.kernel32.GetStdHandle(stdout) # 句柄 bufsize = wintypes._COORD(buffer_width, buffer_height) # rows, columns windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) # 设置窗口大小,窗口大小不能大于缓冲区大小,否则设置无效 # width = right - left + 1 # height = bottom - top + 1 rect = wintypes.SMALL_RECT(0, 0, window_width - 1, window_height - 1) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect))
def scroll(self, top, bottom, rows): """Scroll the region between top and bottom one row up (-) or down (+).""" if not rows: return # use zero-based indexing start, stop = top - 1, bottom - 1 # we're using opposuite sign conventions csbi = GetConsoleScreenBufferInfo(self._hstdout) # absolute position of window in screen buffer # interpret other coordinates as relative to the window window = csbi.srWindow # scroll region clip_rect = wintypes.SMALL_RECT(window.Left, window.Top + start, window.Right, window.Top + stop) if rows < 0: # minus signs since rows is a negative number region = wintypes.SMALL_RECT(window.Left, window.Top - rows, window.Right, window.Bottom) new_pos = wintypes._COORD(window.Left, window.Top) else: region = wintypes.SMALL_RECT(window.Left, window.Top, window.Right, window.Bottom + rows) new_pos = wintypes._COORD(window.Left, window.Top + rows) # workaround: in this particular case, Windows doesn't seem to respect the clip area. if (clip_rect.Bottom == window.Bottom - 1 and region.Bottom >= window.Bottom - 1 and new_pos.Y < region.Top): # first scroll everything up clip_rect.Bottom = window.Bottom bottom, region.Bottom = region.Bottom, window.Bottom ScrollConsoleScreenBuffer(self._hstdout, region, clip_rect, new_pos, u' ', self._attrs) # and then scroll the bottom back down new_pos.Y = window.Bottom region.Top = bottom - 1 ScrollConsoleScreenBuffer(self._hstdout, region, clip_rect, new_pos, u' ', self._attrs) else: ScrollConsoleScreenBuffer(self._hstdout, region, clip_rect, new_pos, u' ', self._attrs)
def setup_console(self, buffer=False): if getattr(sys, 'frozen', False): if buffer: windll.kernel32.SetConsoleScreenBufferSize( self.chandle, wintypes._COORD(100, 100)) else: windll.kernel32.SetConsoleWindowInfo( self.chandle, True, byref(wintypes.SMALL_RECT(0, 0, 99, 49))) windll.kernel32.SetConsoleScreenBufferSize( self.chandle, wintypes._COORD(100, 50)) else: os.system('mode con: cols=100 lines=50')
def _write_console(handle, unistr): """Write character to console, avoid scroll on bottom line.""" csbi = CONSOLE_SCREEN_BUFFER_INFO() _GetConsoleScreenBufferInfo(handle, byref(csbi)) col, row = csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y width, height = csbi.dwSize.X, csbi.dwSize.Y for ch in unistr: if (row == height - 1 and col >= width - 1 and ch != u'\n'): ci = CHAR_INFO(ch, csbi.wAttributes) # do not advance cursor if we're on the last position of the # screen buffer, to avoid unwanted scrolling. _WriteConsoleOutputW(handle, byref(ci), wintypes._COORD(1, 1), wintypes._COORD(0, 0), wintypes.SMALL_RECT(col, row, col, row)) else: _WriteConsoleW(handle, ch, 1, byref(wintypes.DWORD()), byref(wintypes.DWORD()))
import os from colorama import Fore, Back, Style ############################### # 系统设置 ############################### # 调整窗口大小,buffer,标题 from ctypes import windll, byref, c_bool, c_wchar_p, wintypes STDOUT = -12 hdl = windll.kernel32.GetStdHandle(STDOUT) bufsize = wintypes._COORD(101, 300) # rows, columns windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) rect = wintypes.SMALL_RECT(0, 0, 100, 40) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, c_bool(True), byref(rect)) windll.kernel32.SetConsoleTitleW(c_wchar_p("图书馆管理系统")) # 日志 logger = dm.logger # 中文对齐 pd.set_option('display.unicode.east_asian_width', True) pd.set_option('display.unicode.ambiguous_as_wide', True) pd.set_option('display.expand_frame_repr', False) pd.set_option('display.width', 100) pd.set_option('display.max_colwidth', 50) pd.set_option('display.max_row', 500)
os.nice(19) except: pass # Set window size. I do this mainly so when FFMPEG_LOGLEVEL is info or higher, it will display properly. if sys.platform == 'win32': try: from ctypes import windll, byref, wintypes import time time.sleep(.5) width = 90 height = 30 buffer_height = 200 hdl = windll.kernel32.GetStdHandle(-12) # os.system("mode con cols=" + str(width) + " lines=" + str(height)) # Kept here for reference rect = wintypes.SMALL_RECT(0, 50, 0 + width - 1, 50 + height - 1) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) time.sleep( .5 ) # Allow time for window size to change before changing buffer size. bufsize = wintypes._COORD(width, buffer_height) # columns, rows windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) os.system("cls") # Don't panic if the above doesn't work. except: pass #*********************************************************************** # Check FFMEGP location #***********************************************************************
import sys #import textwrap from colorama import init init(strip=not sys.stdout.isatty()) # strip colors if stdout is redirected --- from termcolor import cprint from pyfiglet import figlet_format import os from ctypes import windll, byref,wintypes #os.system("mode con cols=79 lines=43") STDOUT = -11 hdl = windll.kernel32.GetStdHandle(STDOUT) rect = wintypes.SMALL_RECT(0, 50, 90, 180) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) bufsize = wintypes._COORD(1000, 100) # rows, columns windll.kernel32.SetConsoleScreenBufferSize(bufsize) cprint(figlet_format(' EISENRECORDER ', font='standard'), 'white', 'on_red', attrs=(['underline','bold', 'dark'])) with open("artwork/barbell_ascii.txt") as bb: print(bb.read())
import sys from videos import * import YAPO.settings import os, platform x = 0 os.system('mode con: cols=140 lines=4096') os.system('cls' if os.name == 'nt' else 'clear') if platform.system() == "Windows": from ctypes import windll, byref import ctypes.wintypes as wintypes STDOUT = -11 hdl = windll.kernel32.GetStdHandle(STDOUT) rect = wintypes.SMALL_RECT(0, 0, 132, 55) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) bufsize = wintypes._COORD(140, 4096) # rows, columns windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize) if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YAPO.settings") from videos import apps from YAPO import pagination a = apps a = pagination if x == 0: print("") print(
class Game(): done = False x = 510 y = 40 os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x, y) STDOUT = -11 hdl = windll.kernel32.GetStdHandle(STDOUT) rect = wintypes.SMALL_RECT(0, 50, 50, 79) # (left, top, right, bottom) windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect)) windll.kernel32.SetConsoleCursorPosition(hdl, 0, 0) def __init__(self, width=610, height=610): pygame.init() hr = 48 print(" " + "-" * hr + " ") print("|" + " " * 15 + "Welcome to aiRPG" + " " * 15 + " |") print("|" + " COS30002-Artificial Intelligence for Games" + " |") print("|" + " " * 17 + "Created By " + " " * 17 + " |") print("|" + " " * 10 + "Kaelob Smythe ( 100597078 ) " + " " * 7 + " | ") print(" " + "-" * hr + " ") self.width, self.height = width, height self.clock = pygame.time.Clock() self.screen = pygame.display.set_mode((self.width, self.height)) self.done = False pygame.display.set_caption("aiRPG") ## Create the Hero, and set variables for GOAP self.hero = character(0, 9) self.hero.setHP(20) self.hero.setDamage(4) self.hero.setHeal(10) ## Create the Enemy, and set variables for GOAP self.enemy = character(9, 3) self.enemy.setHP(20) self.enemy.setDamage(6) self.enemy.setHeal(6) self.grid = Grid_World(self) def main_loop(self): while not self.done: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True break # break out of the for loop if self.done: break # to break out of the while loop self.draw() self.update() def draw(self): self.screen.fill(Color("black")) self.grid.draw() pygame.display.flip() def update(self): self.grid.updateChar(self.hero) self.grid.updateChar(self.enemy)