def DeletealldataClick(self, sender, e):
     result = MessageBox.Show(
         "Are you absolutely sure you want to delete all the downloaded data?",
         "Delete all data", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
     if result == DialogResult.Yes:
         #MessageBox.Show("Not yet implemented")
         #print self.Owner
         self.p = Progress.Progress()
         self.p.Text = "Deleting all downloaded data. Please wait...."
         self.p.Show()
         self._backWorker.RunWorkerAsync()
Esempio n. 2
0
def main(input_path, output_path_train, output_path_test, factor, samples, preserve_test_ids):
    output_dir = os.path.dirname(os.path.abspath(output_path_train))
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    output_dir = os.path.dirname(os.path.abspath(output_path_test))
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    kill_path = output_dir + '/kill'
    killfile_monitor = KillFileMonitor(kill_path, 1)

    output_path_train_temp = output_path_train + '.incomplete'
    output_path_test_temp = output_path_test + '.incomplete'

    try:
        test_ids = set()
        if preserve_test_ids and os.path.exists(output_path_test):
            with open(output_path_test, 'r') as in_file:
                in_file.readline()
                while True:
                    killfile_monitor.maybe_check_killfile()
                    line = in_file.readline()
                    if not line or len(line) <= 2:
                        break
                    first = line.index(';')
                    skipped_index = line[first + 1:]
                    second = skipped_index.index(';')
                    id = skipped_index[0:second]
                    test_ids.add(id)

        random_line_positions = get_line_positions(input_path, lambda: killfile_monitor.maybe_check_killfile())

        with open(input_path, 'r', encoding='utf8') as in_file:

            shuffle(random_line_positions)

            if samples:
                random_line_positions = random_line_positions[0:samples]

            testCount = int(len(random_line_positions) * factor)

            testLines = random_line_positions[0:testCount]
            trainLines = random_line_positions[testCount:]

            moveFromTrainToTest = [x for x in trainLines if x['Id'] in test_ids]
            potentialTrainInTest = [x for x in testLines if x['Id'] not in test_ids]
            moveFromTestToTrain = potentialTrainInTest[:min(len(moveFromTrainToTest), len(potentialTrainInTest))]

            testLines = [x for x in testLines if x not in moveFromTestToTrain] + moveFromTrainToTest
            trainLines = [x for x in trainLines if x not in moveFromTrainToTest] + moveFromTestToTrain

            if not all(not x['Id'] in test_ids for x in trainLines):
                raise Exception("train_lines in test_ids")

            if any(x in testLines for x in trainLines):
                raise Exception("train_lines in test_lines")

            if len(trainLines) + len(testLines) != len(random_line_positions):
                raise Exception("train_lines or test_lines missing")

            header = in_file.readline()

            i = 0

            in_file.seek(0)

            progress = Progress('split test/train: ', 1)
            progress.set_count(len(random_line_positions))

            with open(output_path_test_temp, 'w', encoding='utf8') as out_file:
                out_file.writelines([header])
                for item in testLines:
                    killfile_monitor.maybe_check_killfile()
                    in_file.seek(item['Position'])
                    line = in_file.readline()
                    if not line.endswith('\n'):
                        line += '\n'
                    out_file.writelines([line])
                    progress.add_item()
                    progress.maybe_print()
                    i += 1

            in_file.seek(0)

            with open(output_path_train_temp, 'w', encoding='utf8') as out_file:
                out_file.writelines([header])
                for item in trainLines:
                    killfile_monitor.maybe_check_killfile()
                    in_file.seek(item['Position'])
                    line = in_file.readline()
                    if not line.endswith('\n'):
                        line += '\n'
                    out_file.writelines([line])
                    progress.add_item()
                    progress.maybe_print()
                    i += 1

        if os.path.exists(output_path_train):
            os.remove(output_path_train)
        os.rename(output_path_train_temp, output_path_train)

        if os.path.exists(output_path_test):
            os.remove(output_path_test)
        os.rename(output_path_test_temp, output_path_test)

    except KilledException:
        killfile_monitor.delete_killfile()

        if os.path.exists(output_path_train_temp):
            os.remove(output_path_train_temp)

        if os.path.exists(output_path_test_temp):
            os.remove(output_path_test_temp)

        print_flush('Killed.')
Esempio n. 3
0
File: MyApp.py Progetto: pkopy/pyqt
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.windowTitleChanged.connect(self.onWindowTitleChange)
        self.windowTitleChanged.connect(lambda x: self.my_custom_fn(x, 25))
        self.setWindowTitle("My window")
        self.setFixedSize(1024, 600)
        # self.label = QLabel("THIS IS AWESOME!!!")
        # self.label.setTextFormat(Qt.RichText)
        # self.setCentralWidget(self.label)
        # self.label.setAlignment(Qt.AlignCenter)

        # self.label1 = QLabel("THIS IS AWESOME!!!")
        # self.label1.setAlignment(Qt.AlignCenter)
        # self.setCentralWidget(self.label1)
        # toolbar = QToolBar("My main toolbar")
        # toolbar.iconSize
        # self.addToolBar(toolbar)

        self.mainLayout = QVBoxLayout()
        self.layout1 = QHBoxLayout()
        self.layout1_1 = QVBoxLayout()
        self.layout1_2 = QHBoxLayout()
        self.layout2 = QHBoxLayout()
        self.layout3 = QHBoxLayout()
        self.thread = ListenWebsocket()
        self.thread.start()

        pixmap = QPixmap('progress.png')
        self.progress = Progress.Progress(pixmap)
        self.label = DisplayMass.Mass()
        # self.setCentralWidget(self.progress)
        # self.setCentralWidget(self.label)
        stableIcon = QPixmap('stable_black.svg')
        taraIcon = QPixmap('tara_black.svg')
        zeroIcon = QPixmap('zero.svg')
        self.iconT = Icon.Icon(taraIcon)
        self.iconS = Icon.Icon(stableIcon)
        self.iconZ = Icon.Icon(zeroIcon)
        self.layout1_1.addWidget(self.iconS)
        self.layout1_1.addWidget(self.iconT)
        self.layout1_1.addWidget(self.iconZ)
        # self.layout1.addWidget(self.icons)
        self.layout2.addWidget(self.progress)

        self.layout2.setAlignment(Qt.AlignCenter)
        self.layout1.addLayout(self.layout1_1)
        self.layout1_2.addWidget(self.label)
        self.layout1.addLayout(self.layout1_2)

        # button = QPushButton('New', self)
        second = SecondWindow.SecondWindow(self)
        second.menus()
        button_action = Butt.Butt(second)
        #         button_action.menus()
        self.layout3.addWidget(button_action)
        # self.layout3.addWidget(button)
        self.mainLayout.addLayout(self.layout1)
        self.mainLayout.addLayout(self.layout2)
        self.mainLayout.addLayout(self.layout3)
        #         self.setLayout(self.mainLayout)
        widget = QWidget()
        widget.setLayout(self.mainLayout)
        self.setCentralWidget(widget)

        # self.client = QtWebSockets.QWebSocket("",QtWebSockets.QWebSocketProtocol.Version13,None)
        # self.client.open(QUrl("ws://10.10.3.60:4101"))
        # self.client.sendTextMessage('{"COMMAND": "REGISTER_LISTENER", "PARAM": "MENU"}')
        # text = self.client.textMessageReceived
        # text.connect(self.onWindowTitleChange)
        # pprint(text)
        # for attr in dir(text):
        #     print("obj.%s = %r" % (attr, getattr(text, attr)))
        # button_action = QAction(QIcon("kolo.svg"),"Your button", self)
        # button_action2 = QAction(QIcon("kolo.svg"),"Second", self)
        # toolbar.setToolButtonStyle(Qt.ToolButtonTextOnly)
        # button_action.setStatusTip("This is your button")
        # button_action.triggered.connect(self.onMyToolBarButtonClick)
        # button_action.setCheckable(True)
        # toolbar.addAction(button_action)
        # toolbar.addSeparator()
        # button_action2.setStatusTip("Second")
        # button_action2.triggered.connect(self.onMyToolBarButtonClick)
        # button_action2.setCheckable(True)
        # toolbar.addAction(button_action2)
        # toolbar.addWidget(QLabel("Hello"))
        # toolbar.addWidget(QCheckBox())
        # toolbar.setIconSize(QSize(50,50))
        self.color = '#ff0000'

        self.setStatusBar(QStatusBar(self))

        # menu = self.menuBar()
        # file_menu = menu.addMenu("&File")
        # file_menu.addAction(button_action)
        # file_menu.addSeparator()
        # file_menu.addAction(button_action2)
        # socket = QtWebSockets.QWebSocket('test')

        self.xman = self.thread.getMessage()
Esempio n. 4
0
def init(data):
    # Board specs init
    data.size = data.width // 30
    data.border = data.size * 0.15
    data.offset = 51
    data.diff = 57.5

    # Player and board init
    data.player = Player(data)
    data.board = Board()

    # Walls init
    data.walls = Wall()
    data.walls.createWalls(data)
    data.all = data.walls.getWalls(data)

    # Leaderboard init
    data.leader = Leaderboard()

    # Start init
    data.timer = 0
    data.allPicked = list()
    data.boxText = "Check answer"
    data.stringColor = "white"

    # Bools init
    data.language = True
    data.home = False
    data.play = False
    data.learn = False
    data.custom = False
    data.progress = False
    data.leaderboard = False
    data.about = False
    data.correct = False
    data.wrong = False
    data.next = False
    data.saved = False
    data.showEnglish = False
    data.showPronounciation = False

    # Player stored info init
    data.cDict = dict()
    data.wDict = dict()
    data.aDict = dict()
    data.defaultList = list()
    data.customList = list()
    data.customEnglishList = list()
    data.defaultAndCustomList = list()

    # Leaderboard stored info init
    data.lDict = dict()

    # Progress info init
    data.prog = Progress()

    data.currXP = 0
    data.allXP = 0

    # Translator init
    data.translator = Translator()