Created
June 24, 2022 12:51
-
-
Save SumOfAllN00bs/8cc35734c47b18e5ad57e5a8af635ac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
class Application: | |
def __init__(self): | |
self.root = Tk() | |
self.root.geometry('355x380') | |
self.root.title('ansi SHIT') | |
self.WIDTH = 30 | |
self.HEIGHT = 13 | |
self.COLORS = ['white', 'black', 'red', 'green', 'blue', 'cyan', 'yellow', 'magenta'] | |
self.COLORCODES = { | |
'white': '[0;47m', | |
'black': '[0;30m', | |
'red': '[0;31m', | |
'green': '[0;32m', | |
'blue': '[0;34m', | |
'cyan': '[0;36m', | |
'yellow': '[0;33m', | |
'magenta': '[0;35m' | |
} | |
self.COLOR = 'white' | |
def main(self): | |
self.frame = Frame(self.root) | |
self.frame.grid(row=0, column=0) | |
self.btn = [[0 for x in range(self.HEIGHT)] for x in range(self.WIDTH)] | |
for x in range(self.WIDTH): | |
for y in range(self.HEIGHT): | |
self.btn[x][y] = Button( | |
self.frame, command=lambda x1=x, y1=y: self.color_change(x1, y1)) | |
self.btn[x][y].grid(column=x, row=y) | |
self.btn[x][y].config(bg='white') | |
buttons = 5 | |
self.palette = Button(self.frame, text='Color', bg=self.COLOR, command=lambda: self.palette_change()) | |
self.palette.grid(column=0, row=80, columnspan=int(self.WIDTH/buttons)) | |
self.bucket = Button(self.frame, text='Bucket', command=lambda: self.fill()) | |
self.bucket.grid(column=int(self.WIDTH/buttons), row=80, columnspan=int(self.WIDTH/buttons)) | |
self.left = Button(self.frame, text='Left', command=lambda: self.shift_left()) | |
self.left.grid(column=int(self.WIDTH/buttons)*2, row=80, columnspan=int(self.WIDTH/buttons)) | |
self.right = Button(self.frame, text='Right', command=lambda: self.shift_right()) | |
self.right.grid(column=int(self.WIDTH/buttons)*3, row=80, columnspan=int(self.WIDTH/buttons)) | |
self.copy = Button(self.frame, text='Copy', command=lambda: self.save_to_clipboard()) | |
self.copy.grid(column=int(self.WIDTH/buttons)*4, row=80, columnspan=int(self.WIDTH/buttons)) | |
self.root.mainloop() | |
def color_change(self, x, y): | |
self.btn[x][y].config(bg=self.COLOR) | |
def palette_change(self): | |
ind = self.COLORS.index(self.COLOR) | |
if (ind + 1 >= len(self.COLORS)): | |
self.COLOR = self.COLORS[0] | |
else: | |
self.COLOR = self.COLORS[ind+1] | |
self.palette.config(bg=self.COLOR) | |
def fill(self): | |
for x in range(self.WIDTH): | |
for y in range(self.HEIGHT): | |
self.btn[x][y].config(bg=self.COLOR) | |
def shift_left(self): | |
for y in range(self.HEIGHT): | |
first = self.btn[0][y].cget('bg') | |
for x in range(self.WIDTH): | |
if x + 1 == self.WIDTH: | |
self.btn[x][y].config(bg=first) | |
continue | |
self.btn[x][y].config(bg=self.btn[x+1][y].cget('bg')) | |
def shift_right(self): | |
for y in range(self.HEIGHT): | |
last = self.btn[self.WIDTH-1][y].cget('bg') | |
for x in reversed(range(self.WIDTH)): | |
if x == 0: | |
self.btn[x][y].config(bg=last) | |
continue | |
self.btn[x][y].config(bg=self.btn[x-1][y].cget('bg')) | |
def save_to_clipboard(self): | |
self.root.clipboard_clear() | |
self.root.clipboard_append("```ansi\n") | |
for y in range(self.HEIGHT): | |
col = None | |
for x in range(self.WIDTH): | |
if col != self.btn[x][y].cget('bg'): | |
if col == None: | |
col = self.btn[x][y].cget('bg') | |
self.root.clipboard_append(self.COLORCODES[col]) | |
else: | |
col = self.btn[x][y].cget('bg') | |
self.root.clipboard_append('[0m' + self.COLORCODES[col]) | |
self.root.clipboard_append('█') | |
# print(self.btn[x][y].cget('bg')[0], end='') | |
self.root.clipboard_append("[0m\n") | |
self.root.clipboard_append("```") | |
self.root.update() | |
if __name__ == '__main__': | |
m = Application() | |
m.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment