Пример #1
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.setupUi(self)
     self.Dialog = WindowConfig()
     self.bag = self.Dialog
     self.my_field = Field(self, self.BlockHeight, self.BlockWidth,
                           self.Difficulty)
     self.timer = QBasicTimer()
     self.count_deleted_blocks = 0
     self.painter = Painter(self, self.BlockHeight, self.BlockWidth)
     self.is_paused = False
     self.is_started = False
     self.setFocusPolicy(Qt.StrongFocus)
     self.setCentralWidget(self.painter)
     self.msgStatusbar[str].connect(self.statusbar.showMessage)
     self.bag.punched.connect(self.env_punched)
     self.create_menu()
Пример #2
0
def celebA_128(use_model, rgb, reconstruct_iter, update_freq, input_size,
               show_area):
    if use_model:
        from painter_celebA_128 import VAEGAN_128_RGB as model

    p = Painter.Painter(use_model, rgb, reconstruct_iter, update_freq,
                        input_size, show_area, model)
    p.main()
Пример #3
0
    def humanWrite(self):

        self.tts.say("Human write start")

        # Stop awareness
        self.awareness.stopAwareness()

        self.tts.say("Start the painter")
        painter = Painter.Painter()
        painter.humanWrite()
Пример #4
0
                # First time, calibration
                first_time = False
                root1 = tk.Tk()
                calibration1 = Calibration.Calibration(root1)
                calibration1.tts.say("Open the window")
                print "Open the calibration window."
                print "Please give me the tablet."
                app.tts.say("Please give me the tablet.")
                calibration1.startCalibrationWindow()
                calibration1.window.mainloop()
            app.prepare_Pen()

            # Touch Frot tactile to grasp the pen
            app.graspPen(touchCommand)

            painter = Painter.Painter()
            painter.keyboardControl()
            app.penUp()

            # Release the pen
            app.releasePen(touchCommand)

            # Return to initial pos
            app.returnInitial()

        # if touchCommand.buttonName == "RearTactile":
        if "RearTactile" in touchCommand.touch_list:
            touchCommand.touch_list = []
            # touchCommand.buttonName = None
            app.tts.say("End the programe")
            print "Please Move the box away."
#
#  main.py
#  HackThe6ix
#
#  Created by Jeffrey, Maliha, Justin  and Lennart on 2016-08-06.
#  Copyright 2016 Researchnix. All rights reserved.
#

import sys
import time

import Painter
#import visualization



if __name__ == "__main__":
    t = time.time()

    # Initialize the Master and check its state
    #mas = Master.Master()
    #mas.printState()
    #mas.run()
    #visualization.visualization()

    pain = Painter.Painter()
    pain.mainloop()


    print "\n\nDone in " + str(time.time() - t) + " s"
Пример #6
0
 def __init__(self):
     self.painter = Painter()
Пример #7
0
class Perceptron:
    w = []
    X = []
    Y = []
    eta = 0.5

    def __init__(self):
        self.painter = Painter()

    def __del__(self):
        self.painter.show()

    def setData(self, _X, _Y):
        i = 0
        for row in _X:
            rowArray = [1]
            for item in row:
                rowArray.append(item)
            if _Y[i] == 1:
                self.painter.addPoint(rowArray[1], rowArray[2], "ro")
            else:
                self.painter.addPoint(rowArray[1], rowArray[2], "x")
            self.X.append(rowArray)
            self.Y.append(_Y[i])
            i += 1

    def initWeight(self):
        countX = len(self.X[0])
        for i in range(0, countX):
            self.w.append(1)

    def adder(self, index):
        summ = 0
        i = 0
        for x in self.X[index]:
            summ += x * self.w[i]
            i += 1
        return summ

    def activationFunction(self, z):
        if z > 0:
            return 1
        if z < 0:
            return -1

    def calculate(self):
        a = True
        i = 0
        counter = 0
        goodCounter = 0
        while a:
            z = self.adder(i)
            h = self.activationFunction(z)
            # print h
            if h != self.Y[i]:
                goodCounter = 0
                # change weight
                print("changing weight...")
                delta = self.Y[i] - z
                j = 0
                for w in self.w:
                    self.w[j] += self.eta * delta * self.X[i][j]
                    j += 1
                x1 = float(-self.w[0] - self.w[2] * 2) / float(self.w[1])
                x2 = float(-self.w[0] - self.w[1] * 2) / float(self.w[2])
                self.painter.paintLine([x1, 2], [2, x2])
            else:
                goodCounter += 1
                if float(goodCounter) / float(len(self.X)) == 1:
                    print("success")
                    self.painter.show()
                    return
            if counter >= 1000:
                print("iteration was ended")
                return
            i += 1
            if i == len(self.X):
                i = 0
            counter += 1
            print("iteration #" + str(counter))
Пример #8
0
class MainWindow(QMainWindow, MainWindowUI):
    Difficulty = 3
    BlockWidth = 10
    BlockHeight = 17
    Speed = 5000
    msgStatusbar = pyqtSignal(str)

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        self.Dialog = WindowConfig()
        self.bag = self.Dialog
        self.my_field = Field(self, self.BlockHeight, self.BlockWidth,
                              self.Difficulty)
        self.timer = QBasicTimer()
        self.count_deleted_blocks = 0
        self.painter = Painter(self, self.BlockHeight, self.BlockWidth)
        self.is_paused = False
        self.is_started = False
        self.setFocusPolicy(Qt.StrongFocus)
        self.setCentralWidget(self.painter)
        self.msgStatusbar[str].connect(self.statusbar.showMessage)
        self.bag.punched.connect(self.env_punched)
        self.create_menu()

    def create_menu(self):
        self.menubar = QtWidgets.QMenuBar(self)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1200, 20))
        self.menubar.setObjectName("menubar")

        self.menu = QtWidgets.QMenu(self.menubar)
        self.menu.setObjectName("menu")

        self.act_new = QtWidgets.QAction(self)
        self.act_new.setObjectName("new")
        self.act_settings = QtWidgets.QAction(self)
        self.act_settings.setObjectName("settings")
        self.act_info = QtWidgets.QAction(self)
        self.act_info.setObjectName("info")

        self.menu.addActions([self.act_new, self.act_info, self.act_settings])
        self.menubar.addAction(self.menu.menuAction())

        self.setMenuBar(self.menubar)

        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.menu.setTitle(_translate("MainWindow", "Game"))
        self.act_new.setText(_translate("MainWindow", "&New"))
        self.act_settings.setText(_translate("MainWindow", "&Settings"))
        self.act_info.setText(_translate("MainWindow", "&Help"))

        self.act_new.triggered.connect(self.start)
        self.act_info.triggered.connect(self.help)
        self.act_settings.triggered.connect(self.show_dialog_for_settings)

    @pyqtSlot()
    def show_dialog_for_settings(self):
        self.Dialog.showDialog()

    @pyqtSlot(int, int)
    def env_punched(self, color_num, dif_num):
        colors = [
            ColorTables.Bright, ColorTables.Soft, ColorTables.Mono,
            ColorTables.Neon, ColorTables.Dark
        ]
        self.painter.ColorScheme = colors[color_num]
        self.Difficulty = dif_num + 1
        self.my_field.Difficulty = self.Difficulty
        self.painter.update()

    def help(self):
        text = "    Тетрис наоборот - это игра, в которой нужно не " \
               "дать опуститься блокам до низа поля, управляя платформой.\n\n" \
               "    Во время игры через равные промежутки времени будут появляться " \
               "новые блоки, опуская старые на ряд ниже.\n\n" \
               "    Чтобы переместить платформу нажимайте стрелки вправо и влево на клавиатуре. " \
               "Чтобы уронить блоки на платформу или подкинуть их вверх к остальным нажмите пробел."
        QMessageBox.information(self, 'Help', text)

    def start(self):
        self.is_paused = False
        self.is_started = True
        self.count_deleted_blocks = 0
        self.my_field.start()

        self.timer.start(self.Speed, self)

        self.painter.refresh(self.my_field.field)

        self.msgStatusbar.emit(str(self.count_deleted_blocks * 1000))

    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            self.my_field.one_line_down()
            self.painter.refresh(self.my_field.field)
            self.game_over()

        else:
            super(MainWindow, self).timerEvent(event)

    def game_over(self):
        if self.my_field.check_for_game_over():
            self.is_paused = not self.is_paused
            self.timer.stop()
            self.msgStatusbar.emit("game over")
            score = self.count_deleted_blocks * 1000
            QMessageBox.information(self, 'GAME OVER',
                                    "Your score: " + str(score))
            #tkinter.messagebox.showinfo("GAME OVER", )

    def pause(self):

        if not self.is_started:
            return

        self.is_paused = not self.is_paused

        if self.is_paused:
            self.timer.stop()
            self.msgStatusbar.emit("pause")
        else:
            self.timer.start(Field.Speed, self)
            self.msgStatusbar.emit(str(self.count_deleted_blocks * 1000))

        self.painter.refresh(self.my_field.field)

    def keyPressEvent(self, event):

        #if not self.is_started:
        #    super(MainWindow, self).keyPressEvent(event)
        #    return

        key = event.key()

        if key == Qt.Key_P:

            self.pause()
            return
        elif key == Qt.Key_1:
            self.painter.ColorScheme = ColorTables.Bright
            self.update()

        elif key == Qt.Key_2:
            self.painter.ColorScheme = ColorTables.Soft
            self.update()

        elif key == Qt.Key_3:
            self.painter.ColorScheme = ColorTables.Mono
            self.update()

        elif key == Qt.Key_4:
            self.painter.ColorScheme = ColorTables.Dark
            self.update()

        elif key == Qt.Key_5:
            self.painter.ColorScheme = ColorTables.Neon
            self.update()

        elif key == Qt.Key_Plus:
            self.Difficulty += 1

        elif key == Qt.Key_Minus:
            self.Difficulty -= 1

        elif key == Qt.Key_N:
            self.start()

        elif self.is_paused:
            return

        elif key == Qt.Key_Left:
            self.my_field.move(-1)
            self.painter.refresh(self.my_field.field)

        elif key == Qt.Key_Right:
            self.my_field.move(1)
            self.painter.refresh(self.my_field.field)

        elif key == Qt.Key_Space:
            self.count_deleted_blocks += self.my_field.action()
            self.msgStatusbar.emit(str(self.count_deleted_blocks * 1000))
            self.game_over()
            self.painter.refresh(self.my_field.field)

        else:
            super(MainWindow, self).keyPressEvent(event)
Пример #9
0
    # Parse graphs:
    graphs = Parser.readFile(args.infile,
                             graphNum=args.tree,
                             afTrait=args.ancestralFragmentTrait,
                             debug=args.debug)
    if len(graphs)>1:
        print "Cannot yet deal with multiple trees.  Please select an individual tree using --tree."
        exit(1)
    graph = graphs[0]
    
    # Sort nodes:
    if args.sortTree:
        graph.reorder()
    
    # Position nodes within a unit square:
    Layout.layout(graph)
    
    # Draw positioned nodes to output file using Cairo:
    painting = Painter.Painting(graph,
                                rect=args.rect,
                                drawNodes=args.drawNodes,
                                nodeRadius=args.nodeRadius,
                                colourTrait=args.colourTrait,
                                lineWidth=args.lineWidth, aspect=args.aspectRatio)
    
    writerMap = {"svg": painting.writeSVG,
                 "pdf": painting.writePDF,
                 "ps": painting.writePS,
                 "png": painting.writePNG}
    writerMap[args.format](args.outfile)
Пример #10
0
        'time': time_request,
        'user_count': json_obj['msg']['user_count'],
        'raw': json_str
    }
    data.append(_data)
    x.append(time_request)
    y.append(json_obj['msg']['user_count'])
    print('当前已存储数据【 %s 】条' % len(data))

    # 将数据写入文件中
    write_res = WriteInXls.writeInXls({
        'filename': filename,
        'id': param['roomid'],
        'data': _data
    })
    print(write_res)


def doit():
    request(url)


# 定义 BlockingScheduler BackgroundScheduler
scheduler = BackgroundScheduler()
job = scheduler.add_job(doit, 'interval', seconds=3)

# 启动后台抓取任务
scheduler.start()
# 启动作图
drawer = Painter.Draw(data, x, y).start().show()