class ListMenuWindow(): def __init__(self): self.win = Window() self.win.set_title("List Options") self.win.set_size(400,250) table = Gtk.Table(1, 2, False) self.win.add_to_win(table) button = Gtk.Button("_Close", use_underline=True) button.connect("clicked", self.win.hide) table.attach(button, 0, 1, 1, 2, xpadding=10, ypadding=10) check_button = Gtk.CheckButton with open('config.json') as json_file: jsonfile = json.load(json_file) count = len(jsonfile['all']) table2 = Gtk.Table(1, count, False) table.attach(table2, 0, 1, 0, 1, xpadding=10, ypadding=10) poss = 0 for label in jsonfile['all']: label_text = Gtk.Label(label['name'] + " ( " + label['val'] + " )") table2.attach(label_text, 0, 1, poss, poss+1, xpadding=10, ypadding=10) poss += 1 self.win.show_all() accGroup = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('Escape') accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit) self.win.add_accel_group(accGroup)
def make(self, group): self.save() for d in Direction.objects.all(): Window.create(data=self, direction=d) parts = list(self.parts()) self.cost = sum(p.cost for p in parts) self.delta = sum(p.delta for p in parts) self.save()
def drive(window: Window, model_path: str, multiplier: int): model: Sequential = keras.models.load_model(model_path) window.align() jd = JoystickEmulator() while True: angle = multiplier * float( model.predict(grab_screen(window)[None, :, :, :], batch_size=1)) jd.emulate(angle) print(angle)
class AddMenuWindow(): def __init__(self): self.win = Window() self.win.set_title("Add url") self.win.set_size(400,250) table2 = Gtk.Table(4, 2, False) self.win.add_to_win(table2) table3 = Gtk.Table(1, 2, False) self.name_textentry = Gtk.Entry() self.key_textentry = Gtk.Entry() self.url_textentry = Gtk.Entry() name_label = Gtk.Label("Name") key_label = Gtk.Label("Key") url_label = Gtk.Label("URL") button1 = Gtk.Button("_Close", use_underline=True) button1.connect("clicked", self.win.hide) button2 = Gtk.Button("Ok") button2.connect("clicked", self.add_to_json) table2.attach(self.name_textentry, 1, 2, 0, 1, xpadding=10, ypadding=10) table2.attach(self.key_textentry, 1, 2, 1, 2, xpadding=10, ypadding=10) table2.attach(self.url_textentry, 1, 2, 2, 3, xpadding=10, ypadding=10) table2.attach(name_label, 0, 1, 0, 1, xpadding=5, ypadding=10) table2.attach(key_label, 0, 1, 1, 2, xpadding=5, ypadding=10) table2.attach(url_label, 0, 1, 2, 3, xpadding=5, ypadding=10) table2.attach(table3, 1, 2, 3, 4) table3.attach(button2, 0, 1, 0, 1, xpadding=5, ypadding=10) table3.attach(button1, 1, 2, 0, 1, xpadding=5, ypadding=10) self.win.show_all() accGroup = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('Escape') accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit) self.win.add_accel_group(accGroup) def add_to_json(self, widget): name_textentry_text = self.name_textentry.get_text() key_textentry_text = self.key_textentry.get_text() url_textentry_text = self.url_textentry.get_text() new = {"name": name_textentry_text, "val": key_textentry_text, "url": url_textentry_text} with open('config.json') as json_file: jsonfile = json.load(json_file) jsonfile['all'].append(new) with open('config.json', 'w') as json_file: json.dump(jsonfile, json_file) sys.exit()
def drive_full(window: Window, model_path: str, angle_multiplier: int, acce_multiplier: int): model: Sequential = keras.models.load_model(model_path) window.align() jd = JoystickEmulator() while True: prediction = model.predict(grab_screen(window)[None, :, :, :], batch_size=1)[0] angle = angle_multiplier * float(prediction[0]) acce = acce_multiplier * float(prediction[1]) jd.emulate(angle) print(angle, acce)
class App(): def __init__(self): self.app = Window() self.app.set_size(400,70) self.app.set_title("Searchapp") self.menuu = MenuBar() self.vbox = Gtk.VBox(False, 10) self.vbox.pack_start(self.menuu.return_menu(), False, False, 0) self.textentry = Gtk.Entry() self.textentry.connect("activate", self.do_stuff) self.table = Gtk.Table(2, 1, False) self.app.add_to_win(self.table) self.table.attach(self.vbox, 0, 1, 0, 1) self.table.attach(self.textentry, 0, 1, 1, 2, xpadding=10, ypadding=10) accGroup = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('Escape') accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit) self.app.add_accel_group(accGroup) self.app.show_all() def do_stuff(self, widget): text = widget.get_text() # Gets text from widget parsed = text.split(" ", 1) # Splits until the first space with open('config.json', 'rb') as json_file: data = json.load(json_file) alldata = data['all'] commandsdata = data['commands'] if parsed[0] == '!default' and parsed[1] == 'none': StuffDoer().set_default_none() if parsed[0] == '!default' and parsed[1] != 'none': StuffDoer().set_default(parsed[1]) if commandsdata[0]['val'] == 'true': StuffDoer().search_default(text) if commandsdata[0]['val'] == 'false' and len(parsed) > 1: StuffDoer().search_common(parsed[0], parsed[1]) else: dialog2 = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,Gtk.ButtonsType.OK, "Error") dialog2.format_secondary_text("Doesn't work that way. See 'How to' on the Menu.") dialog2.run() dialog2.destroy()
def __init__(self, cam: DashboardCamera, window_shape=(80, 61), search_margin=200, max_frozen_dur=15): """ The primary interface for fitting lane lines. Used to initialize lane finding with desired settings and provides extensive options for visualization. :param cam: A calibrated camera. :param window_shape: Desired (window height, window width) that the sliding window search will use. :param search_margin: The maximum pixels of movement allowed between each level of windows. :param max_frozen_dur: The maximum amount of frames a window can continue to be used when frozen (eg when not found or when measurements are uncertain). """ self.camera = cam # Create windows self.windows_left = [] self.windows_right = [] for level in range(cam.img_height // window_shape[0]): x_init_l = cam.img_width / 4 x_init_r = cam.img_width / 4 * 3 self.windows_left.append( Window(level, window_shape, cam.img_size, x_init_l, max_frozen_dur)) self.windows_right.append( Window(level, window_shape, cam.img_size, x_init_r, max_frozen_dur)) self.search_margin = search_margin # Initialize visuals VIZ_OPTIONS = ('dash_undistorted', 'overhead', 'lab_b', 'lab_b_binary', 'lightness', 'lightness_binary', 'value', 'value_binary', 'pixel_scores', 'windows_raw', 'windows_filtered', 'highlighted_lane', 'presentation') self.visuals = {name: None for name in VIZ_OPTIONS } # Storage location of visualization images self.__viz_desired = None # The visuals we want to save self.__viz_dependencies = { 'windows_raw': ['pixel_scores'], # Dependencies of visuals on other visuals 'windows_filtered': ['pixel_scores'], 'presentation': [ 'highlighted_lane', 'overhead', 'windows_raw', 'windows_filtered', 'pixel_scores' ] }
def __init__(self, cam, window_shape=(20, 61), search_margin=200, max_frozen_dur=15): self.camera = cam # Create windows self.windows_left = [] self.windows_right = [] for level in range(cam.img_height // window_shape[0]): # 图像高度240,一个窗口高度20,一列有12个窗口,左右两列 x_init_l = cam.img_width / 4 x_init_r = cam.img_width / 4 * 3 # 窗口序号从下往上逐渐增大 self.windows_left.append( Window(level, window_shape, cam.img_size, x_init_l, max_frozen_dur)) self.windows_right.append( Window(level, window_shape, cam.img_size, x_init_r, max_frozen_dur)) self.search_margin = search_margin
def __init__(self): self.win = Window() self.win.set_title("Add url") self.win.set_size(400,250) table2 = Gtk.Table(4, 2, False) self.win.add_to_win(table2) table3 = Gtk.Table(1, 2, False) self.name_textentry = Gtk.Entry() self.key_textentry = Gtk.Entry() self.url_textentry = Gtk.Entry() name_label = Gtk.Label("Name") key_label = Gtk.Label("Key") url_label = Gtk.Label("URL") button1 = Gtk.Button("_Close", use_underline=True) button1.connect("clicked", self.win.hide) button2 = Gtk.Button("Ok") button2.connect("clicked", self.add_to_json) table2.attach(self.name_textentry, 1, 2, 0, 1, xpadding=10, ypadding=10) table2.attach(self.key_textentry, 1, 2, 1, 2, xpadding=10, ypadding=10) table2.attach(self.url_textentry, 1, 2, 2, 3, xpadding=10, ypadding=10) table2.attach(name_label, 0, 1, 0, 1, xpadding=5, ypadding=10) table2.attach(key_label, 0, 1, 1, 2, xpadding=5, ypadding=10) table2.attach(url_label, 0, 1, 2, 3, xpadding=5, ypadding=10) table2.attach(table3, 1, 2, 3, 4) table3.attach(button2, 0, 1, 0, 1, xpadding=5, ypadding=10) table3.attach(button1, 1, 2, 0, 1, xpadding=5, ypadding=10) self.win.show_all() accGroup = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('Escape') accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit) self.win.add_accel_group(accGroup)
def __init__(self): self.app = Window() self.app.set_size(400,70) self.app.set_title("Searchapp") self.menuu = MenuBar() self.vbox = Gtk.VBox(False, 10) self.vbox.pack_start(self.menuu.return_menu(), False, False, 0) self.textentry = Gtk.Entry() self.textentry.connect("activate", self.do_stuff) self.table = Gtk.Table(2, 1, False) self.app.add_to_win(self.table) self.table.attach(self.vbox, 0, 1, 0, 1) self.table.attach(self.textentry, 0, 1, 1, 2, xpadding=10, ypadding=10) accGroup = Gtk.AccelGroup() key, modifier = Gtk.accelerator_parse('Escape') accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit) self.app.add_accel_group(accGroup) self.app.show_all()
def run(): #Manual tiling maxy, maxx = stdscr.getmaxyx() splity = int(maxy * .8) splitx = int(maxx * .8) #initialize windows #specify Upper left corner, size, title, color scheme and border/no-border main_border = Window((0, 0), (maxx, maxy), "Main Window", TITLE_INACTIVE) display_output = FakeChatWindow((1, 1), (splitx - 1, splity - 1), "Chat", TITLE_INACTIVE) menu_window = MenuWindow((splitx, 1), ((maxx - splitx - 1), maxy - 2), "Menu", TITLE_INACTIVE) editor_window = EditorWindow((1, splity), (splitx - 1, maxy - splity - 1), "Text Edit", palette=TITLE_INACTIVE, callback=display_output.add_str) #Set menu options with corrisponding callbacks menu_actions = [ MenuTuple( "Say 'Hi'", (display_output.add_str, "Hello from the Menu", MENU_MESSAGE)), MenuTuple( "Say something else", (display_output.add_str, "From the Menu, Hello!", MENU_MESSAGE)), MenuTuple("I Prefer Cyan", (curses.init_pair, TITLE_INACTIVE, COLOR_CYAN, COLOR_BLACK)), MenuTuple( "I Prefer Green", (curses.init_pair, TITLE_INACTIVE, COLOR_GREEN, COLOR_BLACK)), MenuTuple( "I Prefer Plain", (curses.init_pair, TITLE_INACTIVE, COLOR_WHITE, COLOR_BLACK)), ] menu_window.set_menu(menu_actions) #Put all the windows in a list so they can be updated together windows = [main_border, display_output, menu_window, editor_window] #create input window cycling # an input window must have a process_key(key) method input_windows = cycle([menu_window, editor_window]) active_window = input_windows.next() active_window.draw_border(TITLE_ACTIVE) #Main Program loop. CTRL+C to break it. while True: #asynchronously try to get the key the user pressed key = stdscr.getch() if key == curses.ERR: #no key was pressed. Do house-keeping dirtied = 0 for win in windows: dirtied += win.dirty win.update() #if dirtied: stdscr.refresh() sleep(.1) #don't be burnin up the CPU, yo. elif key == KEY_TAB: #cycle input window active_window.draw_border() #uses window default active_window = input_windows.next() active_window.draw_border(TITLE_ACTIVE) else: #every other key gets processed by the active input window active_window.process_key(key)
import driving from windows import Window if __name__ == '__main__': window = Window('Grand Theft Auto V', 310, 26, 2) driving.drive(window, 'xception.h5', 5)
# -*- coding: utf-8 -*- """ Created on Wed Dec 12 22:14:41 2018 @author: Vedhus """ from windows import Window from PyQt5 import QtWidgets import sys if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = Window() window.setGeometry(500, 300, 800, 600) window.show() sys.exit(app.exec_())