def __init__(self, hook=False): path = os.path.dirname(__file__) path = os.path.join(path, "screen.ui") self.logger = Logger() self.builder = gtk.Builder() self.builder.add_from_file(path) self.builder.connect_signals(self) self.screen = self.builder.get_object("screen_show") self.notebook = self.builder.get_object("notebook") self.statusbar = self.builder.get_object("statusbar") self.algorithm = None self.create_algorithms_menu() self.screen.connect('key_press_event', self.keyboard_press) self.screen.parent_screen = self self.notebook.set_scrollable(True) self.notebook.set_group_id(0) tab = None if not hook: tab = Graph(self.builder, self.tab_changed) self.add_notebook_tab(tab) self.screen.show_all() # HACK # For some reason the size of scroll only exist after show_all above if tab: tab.centralize_scroll()
def menu_file_open(self, widget): self.logger.info("Opening file") file_chooser = FileChooser("open") file_chooser.run() if file_chooser.path: tab = Graph(self.builder, self.tab_changed) tab.graph = tab.graph.open(file_chooser.path) tab.area.graph = tab.graph tab.changed = False self.add_notebook_tab(tab) self.tab_changed(tab) del file_chooser current_page_number = self.notebook.get_current_page() tab = self.notebook.get_nth_page(current_page_number) return tab, current_page_number
def __init__(self): Graph.__init__(self) self.defaults["distance"] = "0-100" self.name = "DPS" self.fitDps = None self.mainFrame = gui.mainFrame.MainFrame.getInstance()
from gui.graph import * from pygame.locals import * import pygame from sys import exit from tools.game import Game from gui.graph import Graph from gui.lost import Lost from gui.win import Win from gui.welcome import Welcome row = 4 # 行数 gb = Game(row, False) gb.start_test() gr = Graph(row) gr.start_graph('2048') we = Welcome(gr.screen) we.get_welcome() # 随机生成数和位置并初始化 n = gb.get_rand_num() v = gb.get_rand_vector() gb.change_num(v, n) gr.background() box = gb.get_box() gr.playbox(box) gr.flash() win_number = 2048
def __init__(self): Graph.__init__(self) self.defaults["distance"] = "0-20" self.name = "DPS" self.fitDps = None self.mainFrame = gui.mainFrame.MainFrame.getInstance()
from gui.graph import * from pygame.locals import * import pygame from sys import exit from tools.game import Game from gui.graph import Graph from gui.lost import Lost from gui.win import Win from gui.welcome import Welcome row=4# 行数 gb=Game(row,True) gb.start_test() gr=Graph(row) gr.start_graph('2048') we=Welcome(gr.screen) we.get_welcome() # 随机生成数和位置并初始化 n=gb.get_rand_num() v=gb.get_rand_vector() gb.change_num(v,n) gr.background() box=gb.get_box() gr.playbox(box) gr.flash() win_number=2048
class Bot(ttk.Frame): def __init__(self, app, parent, owner, persist=None, stub=False, auto_start=False, starting_stats=None, *args, **kwargs): ttk.Frame.__init__(self, parent, style="app.TFrame", *args, **kwargs) self.app = app # root self.parent = parent # containing frame self.owner = owner self.stub = stub self.is_active = False self.title_var = tk.StringVar() self.coin_title = "coin" self.base_title = "base" self.exchange_title = "<exchange>" if self.stub: self.name = "XMR/BTC Stub" else: self.name = "New Merkato" self.title_var.set(str(self.name)) # merkato args #self.auth_frame = ttk.Frame(self, style="app.TFrame") self.bot = None if persist: self.name = persist["coin"] + "/" + persist[ "base"] + " " + persist["configuration"]["exchange"] self.title_var.set(str(self.name)) self.bot = Merkato(**persist) #presumably from db # -------------------- self.exchange_frame = ttk.Frame(self, style="app.TFrame") self.exchange_menu, self.exchange_index = database_utils.get_all_exchanges( ) self.exchange_name = MyWidget(self.app, self.exchange_frame, handle="exchange", startVal="test", choices=self.exchange_menu) self.coin = MyWidget(self.app, self.exchange_frame, handle="coin", startVal="XMR", choices=["XMR", "LTC", "ETH", "DOGE", "PEPECASH"]) self.base = MyWidget(self.app, self.exchange_frame, handle="base", startVal="BTC", choices=["BTC", "USDT"]) #self.public_key = MyWidget(self.app, self.exchange_frame, handle="pub. key", choices="entry") #self.private_key = MyWidget(self.app, self.exchange_frame, handle="priv. key", is_password=True, choices="entry") self.ask_budget = MyWidget(self.app, self.exchange_frame, handle="coin reserve", startVal=636, choices="entry") self.bid_budget = MyWidget(self.app, self.exchange_frame, handle="base reserve", startVal=10, choices="entry") self.spread = MyWidget(self.app, self.exchange_frame, handle="spread [%]", startVal=5.0, choices="entry") self.margin = MyWidget(self.app, self.exchange_frame, handle="profit margin [%]", startVal="0", choices=[str(i) for i in range(101)]) self.execute = ttk.Button(self.exchange_frame, text="Launch", cursor="shuttle", command=self.start) self.exchange_name.grid(row=0, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.coin.grid(row=1, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.base.grid(row=2, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.public_key.grid(row=3, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.private_key.grid(row=4, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.ask_budget.grid(row=5, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.bid_budget.grid(row=6, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.spread.grid(row=7, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.margin.grid(row=8, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.execute.grid(row=9, column=0, sticky=tk.NE, padx=(10, 5), pady=(15, 5)) # -------------------- self.util_frame = ttk.Frame(self, style="app.TFrame") self.kill_button = ttk.Button(self.util_frame, text="Kill", cursor="shuttle", command=self.kill) self.kill_button.grid(row=0, column=0, sticky=tk.SE, padx=(10, 5), pady=(15, 5)) self.add_assets_type = MyWidget( self.app, self.util_frame, handle="Add Asset", startVal="XMR", choices=["XMR", "BTC", "ETH", "DOGE", "PEPECASH"]) self.add_assets_type.grid(row=1, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_amount = MyWidget(self.app, self.util_frame, handle="amount to add", startVal=1.0, choices="entry") self.add_assets_amount.grid(row=2, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_button = ttk.Button(self.util_frame, text="Add Assets", cursor="shuttle", command=self.add_assets) self.add_assets_button.grid(row=3, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) # -------------------- if not starting_stats: starting_stats = {"price_x": []} self.graph = Graph(self.app, self, stub=self.stub, **starting_stats) self.graph.grid(row=0, column=0, rowspan=3, padx=(5, 10)) #self.auth_frame.grid(row = 0, column=1, sticky=tk.NE, padx=(10,10), pady=(20,5)) if not self.bot: self.exchange_frame.grid(row=0, column=1, sticky=tk.NE, padx=(10, 10), pady=(20, 5)) self.util_frame.grid(row=1, column=1, sticky=tk.SE, padx=(10, 10), pady=(10, 5)) def add_assets(self): add_assets_amount = self.add_assets_amount.get()[0] add_assets_type = self.add_assets_type.get()[0] self.bot.update_orders(add_assets_type, add_assets_amount) def update(self, initial_update=False): context = {} if self.stub or self.bot: # then we have something to update print("--------------- updating %s ----------------------" % self.name) if not self.stub: if self.bot.initialized: if initial_update == False: context = self.bot.update() if initial_update == True: print('doing initial update') context = self.bot.get_context_history() print('adding bid_reserved_balance') context['ask_reserved_balance'] = float( self.bot.ask_reserved_balance) context['bid_reserved_balance'] = float( self.bot.bid_reserved_balance) context['quote_volume'] = float(self.bot.quote_volume) context['base_volume'] = float(self.bot.base_volume) context['spread'] = float(self.bot.spread) else: context = self.graph.fake_data() if context: self.graph.refresh(data=context, active=self.is_active) try: self.title_var.set(str(self.name)) except: self.title_var.set(str(self.name) + " err") def start(self): for widget in [ self.exchange_name, self.coin, self.base, self.ask_budget, self.bid_budget ]: print("{}:\t\t{}".format(widget.handle, widget.get()[0])) self.merk_args = {} self.merk_args["configuration"] = konfig.decrypt_keys( self.exchange_index[self.exchange_name.get()[0]], self.owner.password) self.merk_args["coin"] = self.coin.get()[0] self.merk_args["base"] = self.base.get()[0] self.merk_args["ask_reserved_balance"] = float( self.ask_budget.get()[0]) self.merk_args["bid_reserved_balance"] = float( self.bid_budget.get()[0]) self.merk_args["spread"] = float(self.spread.get()[0]) / 100.0 self.merk_args["profit_margin"] = float(self.margin.get()[0]) / 100.0 self.merk_args["user_interface"] = self self.coin_title = self.merk_args["coin"] self.base_title = self.merk_args["base"] self.graph.profit_base.config(text="%s \u0394bal:" % self.base_title[:4]) self.graph.profit_alt.config(text="%s \u0394bal:" % self.coin_title[:4]) self.exchange_title = self.merk_args["configuration"]["exchange"] self.name = str(self.merk_args["coin"]) + "/" + str( self.merk_args["base"]) + " " + self.exchange_title self.title_var.set(str(self.name)) if not self.stub: try: self.bot = Merkato(**self.merk_args) self.update(initial_update=True) except Exception as e: raise Exception('bot failed to start', e) e2 = traceback.format_exc() safe_show = self.merk_args.copy() safe_show["configuration"] = "obfuscated: " + str( safe_show["configuration"]["exchange"]) MessageBox.showerror("Bot Start Fail", str(e2) + "\n" + repr(self.merk_args)) else: self.exchange_frame.destroy() def kill(self): # TODO: tell self.bot to cancel all orders and delete merkato from DB if self.bot: self.bot.kill() # merkato.kill() self.bot = None # garbage collect mMerkato object, basically self._root().after(10, self.owner.kill_screen, self) # remove from gui def confirm_price(self, price): self.confirmation = popupWindow(self.app, "Confirm starting price: %s" % price, price) self.app.wait_window(self.confirmation.top) price = self.confirmation.value return price # if not exchange_config: # # get args via gui # pass #self.bot = Merkato(exchange_config) """
def __init__(self, app, parent, owner, persist=None, stub=False, auto_start=False, starting_stats=None, *args, **kwargs): ttk.Frame.__init__(self, parent, style="app.TFrame", *args, **kwargs) self.app = app # root self.parent = parent # containing frame self.owner = owner self.stub = stub self.is_active = False self.title_var = tk.StringVar() self.coin_title = "coin" self.base_title = "base" self.exchange_title = "<exchange>" if self.stub: self.name = "XMR/BTC Stub" else: self.name = "New Merkato" self.title_var.set(str(self.name)) # merkato args #self.auth_frame = ttk.Frame(self, style="app.TFrame") self.bot = None if persist: self.name = persist["coin"] + "/" + persist[ "base"] + " " + persist["configuration"]["exchange"] self.title_var.set(str(self.name)) self.bot = Merkato(**persist) #presumably from db # -------------------- self.exchange_frame = ttk.Frame(self, style="app.TFrame") self.exchange_menu, self.exchange_index = database_utils.get_all_exchanges( ) self.exchange_name = MyWidget(self.app, self.exchange_frame, handle="exchange", startVal="test", choices=self.exchange_menu) self.coin = MyWidget(self.app, self.exchange_frame, handle="coin", startVal="XMR", choices=["XMR", "LTC", "ETH", "DOGE", "PEPECASH"]) self.base = MyWidget(self.app, self.exchange_frame, handle="base", startVal="BTC", choices=["BTC", "USDT"]) #self.public_key = MyWidget(self.app, self.exchange_frame, handle="pub. key", choices="entry") #self.private_key = MyWidget(self.app, self.exchange_frame, handle="priv. key", is_password=True, choices="entry") self.ask_budget = MyWidget(self.app, self.exchange_frame, handle="coin reserve", startVal=636, choices="entry") self.bid_budget = MyWidget(self.app, self.exchange_frame, handle="base reserve", startVal=10, choices="entry") self.spread = MyWidget(self.app, self.exchange_frame, handle="spread [%]", startVal=5.0, choices="entry") self.margin = MyWidget(self.app, self.exchange_frame, handle="profit margin [%]", startVal="0", choices=[str(i) for i in range(101)]) self.execute = ttk.Button(self.exchange_frame, text="Launch", cursor="shuttle", command=self.start) self.exchange_name.grid(row=0, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.coin.grid(row=1, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.base.grid(row=2, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.public_key.grid(row=3, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) #self.private_key.grid(row=4, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.ask_budget.grid(row=5, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.bid_budget.grid(row=6, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.spread.grid(row=7, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.margin.grid(row=8, column=0, sticky=tk.NE, padx=(10, 5), pady=(5, 5)) self.execute.grid(row=9, column=0, sticky=tk.NE, padx=(10, 5), pady=(15, 5)) # -------------------- self.util_frame = ttk.Frame(self, style="app.TFrame") self.kill_button = ttk.Button(self.util_frame, text="Kill", cursor="shuttle", command=self.kill) self.kill_button.grid(row=0, column=0, sticky=tk.SE, padx=(10, 5), pady=(15, 5)) self.add_assets_type = MyWidget( self.app, self.util_frame, handle="Add Asset", startVal="XMR", choices=["XMR", "BTC", "ETH", "DOGE", "PEPECASH"]) self.add_assets_type.grid(row=1, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_amount = MyWidget(self.app, self.util_frame, handle="amount to add", startVal=1.0, choices="entry") self.add_assets_amount.grid(row=2, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) self.add_assets_button = ttk.Button(self.util_frame, text="Add Assets", cursor="shuttle", command=self.add_assets) self.add_assets_button.grid(row=3, column=0, sticky=tk.SE, padx=(10, 5), pady=(15)) # -------------------- if not starting_stats: starting_stats = {"price_x": []} self.graph = Graph(self.app, self, stub=self.stub, **starting_stats) self.graph.grid(row=0, column=0, rowspan=3, padx=(5, 10)) #self.auth_frame.grid(row = 0, column=1, sticky=tk.NE, padx=(10,10), pady=(20,5)) if not self.bot: self.exchange_frame.grid(row=0, column=1, sticky=tk.NE, padx=(10, 10), pady=(20, 5)) self.util_frame.grid(row=1, column=1, sticky=tk.SE, padx=(10, 10), pady=(10, 5))
def __init__(self, master=None, file_manager: FileManager = None, **kwargs): super().__init__(master, **kwargs) self.file_manager = file_manager self.file_manager.bind(self.on_new_network) # upper self.upper_ui = Frame() self.upper_ui.pack(anchor='n', fill='x') self.status_label = StatusLabel(self.upper_ui) self.status_label.pack(side=LEFT, fill='both') self.progress_bar = Progressbar(self.upper_ui, maximum=60000, length=600) self.progress_bar.pack(side=LEFT, fill='both') self.start_button = Button(self.upper_ui, text='Start', command=self.start_training) self.start_button.pack(side=RIGHT) self.pause_button = Button(self.upper_ui, text='Pause', state='disabled', command=self.pause_training) self.pause_button.pack(side=RIGHT) self.test_button = Button(self.upper_ui, text='test', command=self.test_network) self.test_button.pack(side=RIGHT) # main self.main_ui = Frame() self.main_ui.pack(fill='both') self.require_loaded_trainer() self.net_info = NetworkInfoUI(self.main_ui, self.file_manager.current_file_name, self.file_manager.loaded_object) self.net_info.grid(column=0, row=0) self.graph_all_digits = Graph( self.main_ui, GraphConfig(limits=Limits(x_count=100), keys=Keys(labels=list(range(10))))) self.graph_all_digits.grid(column=1, row=0) self.graph_average = Graph(self.main_ui) self.graph_average.grid(column=0, row=1) self.status_label.push('loading') self.is_training = False self.update_idletasks() self.update() self.training_data = DataHandler.DataHandler( "../training_data/train/train-labels.idx1-ubyte", "../training_data/train/train-images.idx3-ubyte", ) self.testing_data = DataHandler.DataHandler( "../training_data/test/t10k-labels.idx1-ubyte", "../training_data/test/t10k-images.idx3-ubyte", ) self.status_label.pop() # settings_ui self.settings: TrainerSettings = TrainerSettings(self.main_ui) self.settings_ui = SettingsGUI(self.main_ui, schema=self.settings) self.settings_ui.grid(column=2, row=0, rowspan=2, ipadx=2)
class TrainerGUI(Frame): def __init__(self, master=None, file_manager: FileManager = None, **kwargs): super().__init__(master, **kwargs) self.file_manager = file_manager self.file_manager.bind(self.on_new_network) # upper self.upper_ui = Frame() self.upper_ui.pack(anchor='n', fill='x') self.status_label = StatusLabel(self.upper_ui) self.status_label.pack(side=LEFT, fill='both') self.progress_bar = Progressbar(self.upper_ui, maximum=60000, length=600) self.progress_bar.pack(side=LEFT, fill='both') self.start_button = Button(self.upper_ui, text='Start', command=self.start_training) self.start_button.pack(side=RIGHT) self.pause_button = Button(self.upper_ui, text='Pause', state='disabled', command=self.pause_training) self.pause_button.pack(side=RIGHT) self.test_button = Button(self.upper_ui, text='test', command=self.test_network) self.test_button.pack(side=RIGHT) # main self.main_ui = Frame() self.main_ui.pack(fill='both') self.require_loaded_trainer() self.net_info = NetworkInfoUI(self.main_ui, self.file_manager.current_file_name, self.file_manager.loaded_object) self.net_info.grid(column=0, row=0) self.graph_all_digits = Graph( self.main_ui, GraphConfig(limits=Limits(x_count=100), keys=Keys(labels=list(range(10))))) self.graph_all_digits.grid(column=1, row=0) self.graph_average = Graph(self.main_ui) self.graph_average.grid(column=0, row=1) self.status_label.push('loading') self.is_training = False self.update_idletasks() self.update() self.training_data = DataHandler.DataHandler( "../training_data/train/train-labels.idx1-ubyte", "../training_data/train/train-images.idx3-ubyte", ) self.testing_data = DataHandler.DataHandler( "../training_data/test/t10k-labels.idx1-ubyte", "../training_data/test/t10k-images.idx3-ubyte", ) self.status_label.pop() # settings_ui self.settings: TrainerSettings = TrainerSettings(self.main_ui) self.settings_ui = SettingsGUI(self.main_ui, schema=self.settings) self.settings_ui.grid(column=2, row=0, rowspan=2, ipadx=2) def on_new_network(self): self.net_info.update_network(self.file_manager.current_file_name, self.file_manager.loaded_object) def require_loaded_trainer(self): if type(self.file_manager.loaded_object) is ClassifierTrainer: return True else: self.status_label.push('error') LoadNetwork(self, self.file_manager) self.status_label.pop() return False def start_training(self): if not self.require_loaded_trainer(): return self.start_button.configure(state='disabled') self.pause_button.configure(state='normal') self.is_training = True self.status_label.push('running') while self.is_training: number_of_epochs = self.validate_input( self.settings.general.get_number_of_epochs) self.settings.general.number_of_epochs.set(number_of_epochs - 1) if self.validate_input( self.settings.general.get_number_of_epochs) == 0: self.pause_training() self.training_data.groups = self.validate_input( self.settings.data_handler.get_sub_set_size) for training_set in self.training_data.get_epoch(): self.progress_bar.step(self.training_data.groups) self.update_idletasks() self.update() gradient = self.file_manager.loaded_object.train(training_set) gradient_multiplier = self.validate_input( self.settings.network.get_gradient_multiplier) gradient = gradient.__idiv__(self.training_data.groups / gradient_multiplier) self.file_manager.loaded_object -= gradient if self.settings.general.test_network_after_epoch.get(): self.test_network() # as to get here we need to have paused so pop pausing and running self.status_label.pop() self.status_label.pop() self.start_button.configure(state='normal') def pause_training(self): self.pause_button.configure(state='disabled') self.status_label.push('pausing') self.is_training = False def test_network(self): if not self.require_loaded_trainer(): return self.status_label.push('testing') accuracies: List[float] = [0 for _ in range(10)] for label, value in self.testing_data.get_all_data(): self.update_idletasks() self.update() if self.file_manager.loaded_object.pick( self.file_manager.loaded_object.calculate(value)) == label: accuracies[label] += 1 for label in self.testing_data.data: accuracies[label] = accuracies[label] / len( self.testing_data.data[label]) self.graph_all_digits.write(accuracies) self.graph_average.write([sum(accuracies) / len(accuracies)]) self.status_label.pop() def validate_input(self, get_function, undesired=False): value = get_function() if value is undesired: self.status_label.push('error') value = self.settings_ui.wait_for(get_function) self.status_label.pop() return value
def __init__(self): Graph.__init__(self) self.name = "DPS" self.fitDps = None self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def __init__(self): Graph.__init__(self) self.defaults["distance"] = "0-20" self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.fields = {}