def test_init(self): drawer1 = Drawer.Drawer("total production", ["STATE"], [100]) self.assertEqual(drawer1.state_array, ["STATE"]) self.assertEqual(drawer1.total_production_array, [100]) self.assertEqual(drawer1.production_value_array, []) self.assertEqual(drawer1.mode, "total production") drawer2 = Drawer.Drawer("production value", ["STATE"], [100]) self.assertEqual(drawer2.state_array, ["STATE"]) self.assertEqual(drawer2.total_production_array, []) self.assertEqual(drawer2.production_value_array, [100]) self.assertEqual(drawer2.mode, "production value") with self.assertRaises(SystemExit) as cm: drawer3 = Drawer.Drawer("zly mode", ["STATE"], [100]) self.assertEqual(cm.exception.code, 1)
def to_ansi(self): """ this method starts the drawer class with ansi """ try: _tuple = self.get_ascii_img() drawer = DrCls.Drawer(self.filename) ansi_image = drawer.to_ansi_art(_tuple) with open("%s.txt" % self.name, "w") as f: f.write(ansi_image) msg = QMessageBox() msg.setText("Now you can find your image on %s.txt \n" % self.name) msg.exec_() print("Now you can find your image on %s.txt \n" % self.name) except Exception as e: if self.name == "": msg = QMessageBox() msg.setText("Empty name \n") msg.exec_() print("Empty name") print(e) else: msg = QMessageBox() msg.setText("Choose file at first \n") msg.exec_() print("Choose file at first")
def to_ascii(self): """ this method starts the drawer class with ascii """ try: drawer = DrCls.Drawer(self.filename) _tuple = self.get_ascii_img() self.ascii_img = drawer.to_ascii_art(_tuple[0], _tuple[1][0]) with open("%s.txt" % self.name, "w") as f: f.write(self.ascii_img) self.result_window = Result(ascii_img=self.ascii_img) self.result_window.show() msg = QMessageBox() msg.setText("Now you can find your image on %s.txt \n" % self.name) msg.exec_() print("Now you can find your image on %s.txt \n" % self.name) print(self.ascii_img) except Exception as e: print(e) if self.name == "": msg = QMessageBox() msg.setText("Empty name \n") msg.exec_() print("Empty name") print(e) else: msg = QMessageBox() msg.setText("Choose file at first \n") msg.exec_() print("Choose file at first")
def setUp(self): self.drawer = DrCls.Drawer("test.png") self.incorrect_asciiArt = "BBBBBBBBBBBBBBBBBBBBB" \ "BBSSSSSSS#######&&&&&&" \ "@@@@@@$$$$$$%%%%%%****" \ "***!!!!!!!:::::::::::" \ ".............." self.name = 'test'
def get_ascii_img(self): """ this method gets an ascii string with picture """ while self.name == '': self.name, ok = QInputDialog.getText(self, "Name", "Enter your filename") if self.name == '': msg = QMessageBox() msg.setText("Please type filename!!!") msg.exec_() drawer = DrCls.Drawer(self.filename) res = drawer.resize_image(self.res) pixels = drawer.get_image_data() arr = drawer.draw_picture(pixels) return arr, res
def save_as_img(self, name=None): """ this method saves an image """ image = DrCls.Drawer(self.filename).get_img(self.name) while name is None or name == '': name, ok = QInputDialog.getText(self, "Name", "Enter your filename") if name == '': msg = QMessageBox() msg.setText("Please type filename!!!") msg.exec_() image.save("%s.png" % name) msg = QMessageBox() msg.setText("Done!") msg.exec_()
def createDrawing(self, reducedWidth=500, reducedHeight=200): # get list of chars from selected file and store in object field if len(self.filesBox.curselection()) is 0: print("Please upload or select a file first") return selectedFileNumber = self.filesBox.curselection()[0] characters = self.filenameList[selectedFileNumber] self.characterList = characters # create turtle if needed, else clear canvas if not self.createdTurtle: self.makeTurtle() else: self.clearCanvas() # draw picture and update canvas self.turt.getscreen().tracer(0) self.drawer = drawer.Drawer(self.characterList, self.turt, self.initDx - reducedWidth, self.initDy - reducedHeight) self.drawer.draw() self.turt.getscreen().update()
def __init__(self): self.logger = ObjectLogger.ObjectLogger("WordCloudGenerator") self.logger.log("Initialising pygame") pygame.init() self.windowHeight = 800 self.windowWidth = 800 self.logger.log("Creating DISPLAYSURF with dimensions %dx%d" % (self.windowWidth, self.windowHeight)) self.DISPLAYSURF = pygame.display.set_mode( (self.windowWidth, self.windowHeight)) self.logger.log("Creating wordCloudContainerRect") self.wordCloudContainerRect = self.DISPLAYSURF.get_rect() self.wordCloudContainerRect.width -= 150 self.wordCloudContainerRect.height -= 150 self.wordCloudContainerRect.topleft = (75, 75) self.logger.log("Creating drawer object") self.drawer = Drawer.Drawer(self.DISPLAYSURF) self.drawer.fillBackground()
def main(arg, width): """ this method runs the app """ if arg == "" and width == 0: try: arg = str(parser.parse_args()).split("'")[1] width = parser.parse_args().w save_name = parser.parse_args().save_name ansi_flag = parser.parse_args().ansi_flag image_flag = parser.parse_args().img_flag if save_name is None: sys.stdout.write('!!!Type filename to save in!!!\n' 'Use -s *filename*') sys.exit(1) except Exception as e: print(e) app = GuiCls.QApplication(sys.argv) GuiCls.Window() parser.parse_args() sys.exit(app.exec_()) try: drawer = DrCls.Drawer(arg) res = drawer.resize_image(width) pixels = drawer.get_image_data() arr = drawer.draw_picture(pixels) img = drawer.to_ascii_art(arr, res[0]) with open("%s.txt" % save_name, "w") as f: f.write(img) print('\n------------------------------------\n' 'Now you can find your image on %s.txt!' '\n------------------------------------\n' % save_name) print(img + '\n') if ansi_flag: _tuple = (arr, res) ansi_img = drawer.to_ansi_art(_tuple) sys.stdout.write('Type filename to save ansi in: ') ansi_name = input() with open("%s.txt" % ansi_name, "w") as f: f.write(ansi_img) print('\n------------------------------------\n' 'Now you can find your ansi image on %s.txt!' '\n------------------------------------\n' % ansi_name) if image_flag: sys.stdout.write('Type filename to save image in: ') image_name = input() result_image = drawer.get_img(save_name) result_image.save("%s.png" % image_name) print('\n------------------------------------\n' 'Now you can find your png image on %s.png!' '\n------------------------------------\n' % image_name) return img except Exception as e: print(e) raise
import sys, pygame from pygame.locals import * from PyGame import * from Drawer import * import random if __name__ == "__main__": pygame.init() clock = pygame.time.Clock() window = pygame.display.set_mode((640, 480)) # Use Drawer Class to deal with drawing drawer = Drawer(window) count = 0 new_line = True pygame.display.set_caption("PyGame") content = Content(12, 6) window.fill(Drawer.BG_COLOR) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.__dict__['key'] == K_UP: random_column = random.randint(0, 5) random_list = random.sample(range(1, 9), random.randint(1, 5)) content.add_line(random_column, random_list) if event.__dict__['key'] == K_SPACE: content.rotate() if event.__dict__['key'] == K_LEFT:
import io import socket import struct import cv2 import numpy as np import pygame from Drawer import * from utils import * import time if __name__ == '__main__': print("START SERVER") ####### pygame ####### drawer = Drawer() joy = pygame.joystick.Joystick(0) joy.init() ####### end of pygame ####### ####### socket ######## server_socket = socket.socket() server_socket.bind((IP_Address, Port)) server_socket.listen(1) client_socket, address = server_socket.accept() ###### end of socket ####### ###### recording data set ###### frames = [] angles = [] ###### end of recording data set ######
import turtle import random import Drawer import time don = turtle.Turtle() don.speed(0) don.hideturtle() don.width(2) screen = turtle.Screen() screen.bgcolor('orange') screen.colormode(255) screen.delay(0) screen.tracer(0) drawer = Drawer.Drawer(don) class Card: def __init__(self, color, number): self.face = 'up' self.color = color self.number = number def get_color(self): return self.color def get_number(self): return self.number def flip(self):
def main(argv=None): #loading options optParser = OptionsHandler() optParser.load() #file reading file_in = open(optParser.input_file, "r") buff = file_in.read().split("\n") file_in.close() #drawing configuration setting drawer = Drawer(buff[0].split(optParser.pattern_delimiter)) mainList = TestsList(drawer.nbX) totalNbJobs = 0 #each line loop for line in buff: if line == "": continue if line[0] == '#': continue jobLine = line.split(optParser.pattern_delimiter) job_ts_start = TimeStamp() job_ts_end = TimeStamp() job_res = 0 job_nom = jobLine[0] #throw exception( cast str -> int and assertion) try: job_ts_start.initTimeStamp(jobLine[1]) job_ts_end.initTimeStamp(jobLine[2]) assert job_ts_start.getTimeStamp() <= job_ts_end.getTimeStamp() job_res = int(jobLine[3]) except: print("ERROR: Unable to parse line: ", line) continue #adding mainList.append(job_nom, job_res, job_ts_start, job_ts_end) totalNbJobs += 1 sorted(mainList.testList, key=lambda obj: obj.t0.getTimeStamp()) #scheduling loop for i in range(0, totalNbJobs): #find test with time the smallest nextObj = mainList.testList.pop(0) #compare with treated tests mainList.fixPosition(nextObj) #update refNodes (adjust to the good size) nextObj.finalize(drawer.nbX) #fix treated test mainList.treatedTestList.append(nextObj) totalFilledSurface += ( nextObj.nbBloc * (nextObj.t1.getTimeStamp() - nextObj.t0.getTimeStamp())) sys.exit(0) #header writing in file file_out = open(optParse.output_file, "w") nb = file_out.write(header_svg) #setting Y dimensions y_timeMax = mainList.findLastTest().t1.getTimeStamp( ) - drawer.initTimeStamp if y_timeMax <= 1: y_timeMax = 1 y_timeUnit = float(float(y_timeMax) / float(y_nbUnits)) y_timePerPx = float(float(y_timeUnit) / float(y_sizeUnit)) #color cpt j = 0 #tests writing for current_test in mainList.treatedTestList: current_test.writingJob(file_out, x_sizeUnit, y_timePerPx, x_nbUnits, x_oh, y_oh, begin_time, colorTab[j % NB_COLORS]) #color id j += 1 #line trace to delimit the graph #totalAvailableSurface=int(x_nbUnits*y_timeMax) #surfacefilledAverage=float((totalFilledSurface/totalAvailableSurface)*100) drawer.generate(file_out) file_out.close()
import ImageAnalyzer import random import time pygame.init() screen = pygame.display.set_mode((1200, 700)) drawings = ["apple", "bird", "candle", "clock", "coffee mug", "finger", "moustache", "smiley face"] textColor = (10, 10, 10) largeFont = pygame.font.SysFont("leelawadeeuisemilight", 48) smallFont = pygame.font.SysFont("leelawadeeuisemilight", 36) inactiveButtonColor = (255, 220, 84) activeButtonColor = (255, 204, 0) pen = Drawer.Drawer(textColor, largeFont, smallFont, inactiveButtonColor, activeButtonColor) analyzer = ImageAnalyzer.ImageAnalyzer() def clearScreen(backgroundColor = (255, 112, 112)): """Fills entire screen with a single color""" screen.fill(backgroundColor) def homeScreen(): """Displays Home screen""" clearScreen() homeScreenLoop = True path = os.path.abspath('Stats.txt') statsFile = open(path, "r") successRate = int(int(statsFile.readlines(1)[0]) / int(statsFile.readlines(2)[0]) * 100)
def drawDXF(self): if hasattr(self, 'printFile'): drawer = Drawer.Drawer(self.printFile, self.cnc) else: self.addLogMessage("ERROR: No file selected.")
def test_ansi_art_with_incorrect_str(self): incorrect_ansiArt = "[41m[31m&[0m[41m" \ "[31m&[0m[41m[31m&[0m" \ "[41m[31m&[0m[41m" \ "[31m&[0m[41m[31m&[0m" \ "[41m[31m&[0m[41m" \ "[31m&[0m[41m[31m&[0m" \ "[41m[31m&[0m[41m" \ "[31m&[0m[41m[31m&[0m" \ "[41m[31m&[0m[41m" \ "[31m&[0m[41m[31m&[0m" \ "[41m[31m$[0m[41m" \ "[31m$[0m[41m[31m$[0m" \ "[41m[31m$[0m[41m" \ "[31m$[0m[41m[31m$[0m" \ "[41m[31m$[0m[41m" \ "[31m$[0m[41m[31m$[0m" \ "[41m[31m$[0m[41m" \ "[31m$[0m[41m[31m$[0m" \ "[41m[31m$[0m[41m" \ "[31m$[0m[43m[33m![0m" \ "[43m[33m:[0m[43m" \ "[33m:[0m[43m[33m:[0m" \ "[43m[33m:[0m[43m" \ "[33m:[0m[43m[33m:[0m" \ "[43m[33m:[0m[43m" \ "[33m:[0m[43m[33m:[0m" \ "[43m[33m:[0m[43m" \ "[33m:[0m[43m[33m:[0m" \ "[43m[33m:[0m[43m" \ "[33m:[0m[42m[32m&[0m" \ "[42m[32m&[0m[42m" \ "[32m&[0m[42m[32m&[0m" \ "[42m[32m&[0m[42m" \ "[32m&[0m[42m[32m&[0m" \ "[42m[32m&[0m[42m" \ "[32m&[0m[42m[32m&[0m" \ "[42m[32m&[0m[42m" \ "[32m&[0m[42m[32m&[0m" \ "[42m[32m&[0m[42m" \ "[32m&[0m[46m[36m%[0m" \ "[46m[36m%[0m[46m" \ "[36m%[0m[46m[36m%[0m" \ "[46m[36m%[0m[46m" \ "[36m%[0m[46m[36m%[0m" \ "[46m[36m%[0m[46m" \ "[36m%[0m[46m[36m%[0m" \ "[46m[36m%[0m[46m" \ "[36m%[0m[46m[36m%[0m" \ "[46m[36m%[0m[46m" \ "[36m%[0m[44m[34m#[0m" \ "[44m[34m#[0m[44m" \ "[34m#[0m[44m[34m#[0m" \ "[44m[34m#[0m[44m" \ "[34m#[0m[44m[34m#[0m" \ "[44m[34m#[0m[44m" \ "[34m#[0m[44m[34m#[0m" \ "[44m[34m#[0m[44m" \ "[34m#[0m[44m[34m#[0m" \ "[44m[34m#[0m[45m" \ "[35m&[0m[45m[35m&[0m" \ "[45m[35m&[0m[45m" \ "[35m&[0m[45m[35m&[0m" \ "[45m[35m&[0m[45m" \ "[35m&[0m[45m[35m&[0m" \ "[45m[35m&[0m[45m" \ "[35m&[0m[45m[35m&" \ "[0m[47m[37m:[0m" width = 120 height = 1.2352941176470587 res = ("MMMMMMMM..............xxxxooooodddddd" "MMMMMMMMMxxxxxxxxxxxxxxxxoooooooood" "xxxxxxxxxx.............oooooo" "MMMMMMMMMMMMMkkkkkk", (width, height)) dr = DrCls.Drawer('test.png') ansi_img = dr.to_ansi_art(res) self.assertNotEqual(incorrect_ansiArt, ansi_img)
from turtle import * from Drawer import * from ArgCreator import * argType = [ ArgType.LINE, ArgType.TRIANGLE, ArgType.SQUARE, ArgType.CIRCLE, ArgType.MANY_ANGLE ] def ChooseFigure(): return int( input( "1: Отрезок\n2: Треугольник\n3: Квадрат\n4: Круг\n5: Многоугольник\n\nНомер:" )) tr = Turtle() tr.begin_fill() drawer = Drawer(tr) argCreator = ArgCreator() choosen = ChooseFigure() while (choosen >= 1 and choosen <= 5): index = choosen - 1 drawer.Draw(argType[index], argCreator.CreateArg) choosen = ChooseFigure() tr.end_fill() print("Выход из программы...")