Exemplo n.º 1
0
def pump_out(time_: int):
    switch.on()

    progress_bar = ProgressBar()
    progress_bar.initialize()

    for i in range(time_):
        time.sleep(1)
        percentage = (i + 1) / time_ * progress_bar.width
        progress_bar.update(percentage)

    progress_bar.finish()
    switch.off()
Exemplo n.º 2
0
    def __init__(self, path, max_load=None):
        self.path = path

        with open(os.path.join(self.path, 'meta.json'), 'r') as file:
            self.meta = json.loads(file.read())['classes']

        self.data = []

        files = [e for e in os.listdir(self.path) if e.split('.')[-1] == 'npy']
        files = sorted(files)

        if max_load is not None:
            idx = np.random.choice(range(len(files)), max_load, replace=False)
            f = []
            m = []
            for i in idx:
                f.append(files[i])
                m.append(self.meta[i])
            self.meta = m
            files = f

        pb = ProgressBar("Loading", 15, len(files), update_every=2000, ea=15)
        for i, file in enumerate(files):
            f = os.path.join(self.path, file)
            self.data.append(np.load(f))
            pb.update(i + 1)

        pb.finish()
Exemplo n.º 3
0
 def __init__(self, controller=None):
     self.root = Tk()
     tksupport.install(self.root)
     # h = self.root.winfo_screenheight()
     w = self.root.winfo_screenwidth()
     self.screenSize = (w, w / 2)  # the width of the picture for this game is twice as wide as its height
     # d = MyDialog(self.root)
     # print "result", d.size
     self.canvas = Canvas(self.root, width=self.screenSize[0], height=self.screenSize[1])
     self.controller = controller
     topFrame = Frame(self.root)
     topFrame.pack(side=TOP)
     self.question = StringVar()
     self.answer = StringVar()
     self.timeText = StringVar()
     self.scoreText = StringVar()
     self.scoresText = StringVar()
     self.nextRound = StringVar()
     self.nameInput = Entry(topFrame)
     self.nameInput.grid(row=0, column=1, sticky=W)
     Label(topFrame, text="Enter your name here:   ").grid(row=0, column=0, sticky=W)
     Label(topFrame, textvariable=self.question).grid(row=1, column=2, sticky=W)
     Label(topFrame, textvariable=self.answer).grid(row=1, column=3, sticky=W)
     Label(topFrame, textvariable=self.scoreText).grid(row=0, column=3, sticky=E)
     # Label(topFrame, textvariable=self.timeText).grid(row=2, column=1, sticky=W)
     self.progressBar = ProgressBar(topFrame, value=0, max=5, width=400)
     self.progressBar.grid(row=0, column=2, sticky=W)
     # self.nextRoundBar = ProgressBar(topFrame, value=5000, max=5000, width=400)
     # self.nextRoundBar.grid(row=1, column=2, sticky=W)
     Label(topFrame, textvariable=self.nextRound).grid(row=0, column=3, sticky=W)
     # Button(topFrame, text="Get Question", command=self.controller.getQuestion).grid(row=2, column=1, sticky=W)
     # Button(topFrame, text="New Game", command=self.controller.restartGame).grid(row=2, column=3, sticky=W)
     Button(topFrame, text="Quit", command=self.quit).grid(row=0, column=4, sticky=W)
     Button(topFrame, text="Restart", command=self.restart).grid(row=0, column=5, sticky=W)
     large = 1600
     self.imageId = None
     # self.makeImage(mapFile, None)
     self.canvas.bind("<Button-1>", self.controller.mouseEvent)
     self.canvas.pack(side=BOTTOM)
     self.lines = []
     self.map = None
Exemplo n.º 4
0
class WorldView:
    def __init__(self, controller=None):
        self.root = Tk()
        tksupport.install(self.root)
        # h = self.root.winfo_screenheight()
        w = self.root.winfo_screenwidth()
        self.screenSize = (w, w / 2)  # the width of the picture for this game is twice as wide as its height
        # d = MyDialog(self.root)
        # print "result", d.size
        self.canvas = Canvas(self.root, width=self.screenSize[0], height=self.screenSize[1])
        self.controller = controller
        topFrame = Frame(self.root)
        topFrame.pack(side=TOP)
        self.question = StringVar()
        self.answer = StringVar()
        self.timeText = StringVar()
        self.scoreText = StringVar()
        self.scoresText = StringVar()
        self.nextRound = StringVar()
        self.nameInput = Entry(topFrame)
        self.nameInput.grid(row=0, column=1, sticky=W)
        Label(topFrame, text="Enter your name here:   ").grid(row=0, column=0, sticky=W)
        Label(topFrame, textvariable=self.question).grid(row=1, column=2, sticky=W)
        Label(topFrame, textvariable=self.answer).grid(row=1, column=3, sticky=W)
        Label(topFrame, textvariable=self.scoreText).grid(row=0, column=3, sticky=E)
        # Label(topFrame, textvariable=self.timeText).grid(row=2, column=1, sticky=W)
        self.progressBar = ProgressBar(topFrame, value=0, max=5, width=400)
        self.progressBar.grid(row=0, column=2, sticky=W)
        # self.nextRoundBar = ProgressBar(topFrame, value=5000, max=5000, width=400)
        # self.nextRoundBar.grid(row=1, column=2, sticky=W)
        Label(topFrame, textvariable=self.nextRound).grid(row=0, column=3, sticky=W)
        # Button(topFrame, text="Get Question", command=self.controller.getQuestion).grid(row=2, column=1, sticky=W)
        # Button(topFrame, text="New Game", command=self.controller.restartGame).grid(row=2, column=3, sticky=W)
        Button(topFrame, text="Quit", command=self.quit).grid(row=0, column=4, sticky=W)
        Button(topFrame, text="Restart", command=self.restart).grid(row=0, column=5, sticky=W)
        large = 1600
        self.imageId = None
        # self.makeImage(mapFile, None)
        self.canvas.bind("<Button-1>", self.controller.mouseEvent)
        self.canvas.pack(side=BOTTOM)
        self.lines = []
        self.map = None

    def makeImage(self):
        if self.imageId != None:
            print "deleting image"
            self.canvas.delete(self.imageId)
        self.picture = ImageTk.PhotoImage(self.map.croppedImage)
        self.imageId = self.canvas.create_image(0, 0, anchor="nw", image=self.picture)

    def getData(self):
        self.controller.getLandmarks("easy")

    def restart(self):
        self.controller.restart()

    def start(self):
        self.root.mainloop()

    def quit(self):
        self.controller.quit()

    def deleteLines(self):
        for i in self.lines:
            self.canvas.delete(i)

    def startTimer(self):
        pass

    def updateProgressbar(self, time):
        self.progressBar.updateProgress(time)

    def updateNextRoundBar(self, score):
        value = self.nextRoundBar.value
        value -= score
        if value < 0:
            value = 0
        self.nextRoundBar.updateProgress(value)

    def drawLines(self, color, point):
        x, y = point
        self.lines.append(self.canvas.create_line(x - 10, y - 10, x + 10, y + 10, fill=color))
        self.lines.append(self.canvas.create_line(x - 10, y + 10, x + 10, y - 10, fill=color))

    def drawCircle(self, color, point, radius):
        x, y = point
        x1 = x - radius
        x2 = x + radius
        y1 = y - radius
        y2 = y + radius
        self.lines.append(self.canvas.create_oval(x1, y1, x2, y2, outline=color))

    def showScores(self, score):
        # pop up a dialog window with some text
        SimpleDialog(self.root, text=score, buttons=["OK"], default=0, title="Demo Dialog").go()

    def showMessage(self, message):
        # pop up a dialog window with some text
        SimpleDialog(self.root, text=message, buttons=["OK"], default=0, title="Demo Dialog").go()

    def makeLarge(self):
        pass
Exemplo n.º 5
0
    def load(self):
        subdirs = []
        dirclass = []
        names = []
        for entry in os.listdir(self.path):
            inner = os.path.join(self.path, entry)
            if os.path.isdir(inner):
                if len(entry) == 2:
                    subdirs.append(inner)
                    dirclass.append(chr(int(entry, 16)))
                    names.append('train_' + entry)

        self.data = []

        pb = ProgressBar("Loading", 15, len(subdirs), update_every=1, ea=15)

        # We now have a list of directories and their corresponding
        # characters. We need to load the images with opencv, convert
        # them to BGR, crop them and resize them.
        for idx, (c, d, n) in enumerate(zip(dirclass, subdirs, names)):
            subdir = os.path.join(d, n)
            for entry in os.listdir(subdir):
                ext = entry.split('.')[-1].lower()
                if ext == 'png':
                    self.data.append(
                        HandwrittenCharacter(os.path.join(subdir, entry), c,
                                             self.size))

            pb.update(idx + 1)

        pb.finish()

        pb = ProgressBar("Saving",
                         15,
                         len(self.data),
                         update_every=2000,
                         ea=15)

        self.meta = []

        for i, d in enumerate(self.data):
            outpath = os.path.join(self.out, "%06d.np" % i)
            self.meta.append(d.char)
            np.save(outpath, d.image)
            pb.update(i + 1)

        pb.finish()

        with open(os.path.join(self.out, 'meta.json'), 'w') as file:
            file.write(json.dumps({'classes': self.meta}))