Exemplo n.º 1
0
def main():
    pg.init()
    clock = Clock()
    chess_engine = ChessEngine()
    board_state = BoardState(chess_engine)
    renderer = Renderer(chess_engine, board_state)
    is_playing = True
    while is_playing:
        for e in pg.event.get():
            if e.type == pg.QUIT:
                is_playing = False
                continue
            if e.type == pg.MOUSEBUTTONDOWN:
                location = pg.mouse.get_pos()
                r = location[1] // sq_size
                c = location[0] // sq_size
                board_state.select_square(r, c)
                continue
            if e.type == pg.KEYDOWN:
                if e.key == pg.K_z:
                    board_state.undo()
                    continue
                if e.key == pg.K_r:
                    clock = Clock()
                    chess_engine = ChessEngine()
                    board_state = BoardState(chess_engine)
                    renderer = Renderer(chess_engine, board_state)
                    is_playing = True
                    continue
                continue
        board_state.handle_move_made()
        clock.tick()
        renderer.render()
Exemplo n.º 2
0
    def __init__(self, tickers, bithumb_account):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(QIcon("src/its_me.jpeg"))

        self.tickers = tickers
        self.bithumb_account = bithumb_account

        self.tableWidget.setRowCount(len(self.tickers) + 1)
        self.worker = Worker(bithumb_account, tickers)
        self.worker.finished.connect(self.update_table_widget)
        self.worker.start()

        self.clock = Clock()
        self.clock.tick.connect(self.update_time)
        self.clock.start()

        self.trader = Trader(bithumb_account, tickers)
        self.trader.sold.connect(self.srecord)
        self.trader.bought.connect(self.brecord)
        self.trader.tick.connect(self.printTime)
        self.trader.start()
Exemplo n.º 3
0
class MyWindow(QMainWindow, form_class):
    def __init__(self, tickers, bithumb_account):
        super().__init__()
        self.setupUi(self)
        self.setWindowIcon(QIcon("src/its_me.jpeg"))

        self.tickers = tickers
        self.bithumb_account = bithumb_account

        self.tableWidget.setRowCount(len(self.tickers) + 1)
        self.worker = Worker(bithumb_account, tickers)
        self.worker.finished.connect(self.update_table_widget)
        self.worker.start()

        self.clock = Clock()
        self.clock.tick.connect(self.update_time)
        self.clock.start()

        self.trader = Trader(bithumb_account, tickers)
        self.trader.sold.connect(self.srecord)
        self.trader.bought.connect(self.brecord)
        self.trader.tick.connect(self.printTime)
        self.trader.start()

    @pyqtSlot(dict)
    def update_table_widget(self, data):
        try:
            for ticker, infos in data.items():

                index = self.tickers.index(ticker)

                self.tableWidget.setItem(index, 0, QTableWidgetItem(ticker))
                self.tableWidget.setItem(index, 1,
                                         QTableWidgetItem(str(infos[0])))
                self.tableWidget.setItem(index, 2,
                                         QTableWidgetItem(str(infos[1])))
                self.tableWidget.setItem(index, 3,
                                         QTableWidgetItem(str(infos[2])))
                self.tableWidget.setItem(index, 4,
                                         QTableWidgetItem(str(infos[3][0])))

                if index + 1 == len(self.tickers):
                    self.tableWidget.setItem(4, 0, QTableWidgetItem("KRW"))
                    self.tableWidget.setItem(
                        4, 4, QTableWidgetItem(str(infos[3][2])))

        except:
            pass

    @pyqtSlot(str)
    def update_time(self, str_time):
        try:
            self.statusBar().showMessage(str_time)
        except:
            pass

    @pyqtSlot(str)
    def srecord(self, orderId):
        try:
            print("Sold BTC | Order ID: ", orderId)
        except:
            pass

    @pyqtSlot(str)
    def brecord(self, orderId):
        try:
            print("Bought BTC | Order ID: ", orderId)
        except:
            pass

    @pyqtSlot(str)
    def printTime(self, timestampStr):
        print(timestampStr)
Exemplo n.º 4
0
class Kernel(object):

    def __init__(self, malloc_strategy, scheduling_policy_class, round_robin_policy_on=True, round_robin_quantum=5):

        self.__mutex = RLock()
        self.__scheduling_policy_class = scheduling_policy_class
        self.__round_robin_policy_on = round_robin_policy_on
        self.__malloc_strategy = malloc_strategy
        self.__pcb_table = PcbTable()
        self.__quantum = round_robin_quantum
        self.g_mode = False

    def set_cpu(self, a_cpu):
        a_cpu.set_kernel(self)
        if self.__round_robin_policy_on:
            a_cpu.enable_round_robin(self.__quantum)
        self.__cpu = a_cpu

    def set_memory(self, a_memory_ram):
        self.__memory_ram = a_memory_ram

    def set_hard_drive(self, a_hard_drive):
        self.__hard_drive = a_hard_drive

    def file_exists(self, path):
        return self.__filesystem.file_exists( path )

    def install_program(self, path, program):
        program.append_instruction(Instruction("Close the program on memory.", "KILL"))
        self.__filesystem.put_file('/bin/' + path, program)

    def get_process_list(self):
        result = {}
        for id, pcb in self.__pcb_table.get_pcb_list().iteritems():
            result[id] = { 'name': pcb.get_program_name() , 'state': pcb.get_state() }
        return result

    def boot(self):
        self.__validate_kernel_setup()
        self.__setup_components()
#        self.get_cpu().start()
        self.__clock.start()

    def fork_execve(self,  path):
        with self.__cpu.pcb_not_set():
            with self.__mutex:
                program = self.__filesystem.get_file(path)
                pcb     = self.__loader.load(program)
                self.get_irq_manager().handle( Irq(NEW_INTERRUPT, pcb) )
            self.__cpu.pcb_not_set().notify()

    def get_mem_manager(self):
        return self.__mem_manager

    def get_filesystem_module(self):
        return self.__fs_module

    def get_partitions(self):
        return self.__hard_drive.partitions()


    def __validate_kernel_setup(self):

        if self.__cpu == None:
            raise NoDeviceException("CPU")

        if self.__hard_drive == None:
            raise NoDeviceException("Hard Drive")

        if self.__memory_ram == None:
            raise NoDeviceException("Memory")

    def __setup_components(self):
        self.__setup_memory()
        self.__setup_scheduling()
        self.__setup_irq_manager()
        self.__setup_clock()
        self.__setup_filesystems()
        self.__setup_program_loader()
        self.__setup_authentication()

    def __setup_memory(self):
        self.__mem_manager = MemoryManager(self.__memory_ram, self.__malloc_strategy)

    def __setup_filesystems(self):
        self.__mount_root()
        self.__filesystem = Filesystem(self.__fs_module) # For backwards compatibility only

    def __mount_root(self):
        self.__fs_module = FilesystemModule()
        self.__fs_module.mount('/', self.__hard_drive.partition(0)) # we assume root partition is the first partition

    def __setup_authentication(self):
        self.__authentication = UsersAccountService(self.__filesystem)

    def __setup_scheduling(self):
        self.set_scheduler(self.__scheduling_policy_class())

    def __setup_clock(self):
        self.__clock = Clock()
        self.__clock.add_listener( self.get_cpu() )


    def __setup_program_loader(self):
        self.__loader = ProgramLoader(self.__mem_manager, self.__pcb_table)

    def get_cpu(self):
        return self.__cpu

    def set_scheduler(self, a_scheduler):
        self.scheduler = a_scheduler
        
    def get_scheduler(self):
        return self.scheduler
        
    def get_memory_ram(self):
        return self.__memory_ram
    
    def get_hard_drive(self):
        return self.__hard_drive
    
    def set_irq_manager(self, a_irq_manager):
        self.irq_manager = a_irq_manager
        
    def get_irq_manager(self):
        return self.irq_manager
    
    def set_ready_queue(self, a_queue):
        self.ready_queue = a_queue
        
    def get_ready_queue(self):
        return self.ready_queue

    def get_fileSystem(self):
        return self.__filesystem

    def get_authentication(self):
        return self.__authentication

    def __setup_irq_manager(self):
        self.irq_manager = IrqManager()
        self.__setup_new_handler()
        self.__setup_io_handler()
        self.__setup_io_end_handler()
        self.__setup_kill_handler()
        self.__setup_timeout_handler()

    def __setup_timeout_handler(self):
        timeout_handler = TimeoutInterruptionHandler(self.get_scheduler(), self.get_cpu())
        self.get_irq_manager().reference_interruption_to_handler(TIMEOUT_INTERRUPT, timeout_handler)

    def __setup_kill_handler(self):
        kill_int_handler = KillInterruptionHandler(self.get_scheduler(), self.get_cpu(), self.__pcb_table, self.__mem_manager)
        self.get_irq_manager().reference_interruption_to_handler(KILL_INTERRUPT, kill_int_handler)

    def __setup_io_end_handler(self):
        io_end_interruption_handler = IOEndInterruptionHandler(self.get_scheduler(), self.get_cpu(), self.get_mem_manager())
        self.get_irq_manager().reference_interruption_to_handler(IO_END_INTERRUPT, io_end_interruption_handler)

    def __setup_io_handler(self):
        io_int_handler = IOInterruptionHandler(self.get_scheduler(), self.get_cpu(), IOManager(self), self.get_mem_manager())
        self.get_irq_manager().reference_interruption_to_handler(IO_INTERRUPT, io_int_handler)

    def __setup_new_handler(self):
        new_int_handler = NewInterruptionHandler(self.get_scheduler(), self.get_cpu())
        self.get_irq_manager().reference_interruption_to_handler(NEW_INTERRUPT, new_int_handler)

    def login(self):
        answer = raw_input('enable operative system with graphical environment? (yes or no)\n')

        if (answer == 'yes') | (answer =='y'):
            self.__log_with_graphical_environment()

        elif (answer == 'no') | (answer =='n'):
            self.__log_with_bash_environment()
        else:
            self.login()

    def __log_with_graphical_environment(self):
        self.g_mode = True
        self.get_authentication().graphical_login()

    def __log_with_bash_environment(self):
        self.get_authentication().login()
Exemplo n.º 5
0
 def __setup_clock(self):
     self.__clock = Clock()
     self.__clock.add_listener( self.get_cpu() )