def js_click(self, element): # DriverUtil.get_driver().find_element(element).click() # try: print("{}JS点击按钮成功".format(element)) Driver.get_driver().execute_script("arguments[0].click();", element) # webdriver.ActionChains(DriverUtil.get_driver()).click(element).perform() except Exception as e: print(e, "{}JS点击按钮失败".format(element))
def date_input(self, style, ele, index): """ :param style: CSS元素类型 :param ele: CSS元素 :param index: 下标 :return: """ self.js = 'document.getElementsBy{}("{}")[{}].removeAttribute("readonly")'.format( style, ele, index) Driver.get_driver().execute_script(self.js)
def load_saved_drivers() -> List[Driver] or None: """Load all drivers saved in globals.SAVE_DRIVER_FILE_PATH Returns: List of saved driver None if no driver is saved """ try: if os.path.exists(SAVE_DRIVER_FILE_PATH): dummy_driver = Driver([0], 0, 0, '') deserialized = DriverSerializer._deserialize_saved_drivers() for driver in deserialized: assert (isinstance(driver, Driver) and dir(dummy_driver) == dir(driver)) return deserialized logging.error("No driver is currently saved.") except: logging.critical("The driver file is corrupted.") logging.info( "Execute 'linux-enable-ir-emitter fix driver' to reset the file." ) sys.exit(ExitCode.FAILURE)
def __init__(self, device): """ :param device: the linux event file of the Wacom device to connect to (eg: /dev/input/event12) """ self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) self.driver = Driver(device) self.driver.start() # Start Async Task self.driver.set_state_running() # Externally set variables self.activeDrawingWindow = None # load keras model self.model = load_model(globals.keras_model_name) self.model._make_predict_function( ) # have to initialize before threading globals.keras_graph = tf.get_default_graph()
def execute() -> NoReturn: """Display the current driver in the default editor""" if not os.path.exists(SAVE_DRIVER_FILE_PATH): dummy_driver = Driver([0], 0, 0, "/dev/videoX") DriverSerializer.save_drivers([dummy_driver]) try: subprocess.run([EDITOR_PATH, SAVE_DRIVER_FILE_PATH]) except FileNotFoundError: logging.critical( "No editor found, set the envion variable 'EDITOR' or install nano." ) sys.exit(ExitCode.MISSING_DEPENDENCY) sys.exit(ExitCode.SUCCESS)
def execute_driver(self, driver: Driver) -> bool: """Execute a driver Args: driver: driver to execute Raises: DriverGeneratorError: error_code:ExitCode.FILE_DESCRIPTOR_ERROR Returns: ExitCode returned by the driver execution """ # debug print are disabled because it is not relevent while automatic configuration init_log_level = logging.getLogger().level logging.getLogger().setLevel(logging.INFO) exit_code = driver.run() logging.getLogger().setLevel(init_log_level) self._raise_if_file_descriptor_error(exit_code) return exit_code
from driver.Driver import Driver from driver.Driver import Dummy2RPMDriver c = Driver(Dummy2RPMDriver()) print(c.getRPM())
from Tkinter import * # This interface allow us to draw windows from Tkinter import * from driver.Driver import Driver from driver.Driver import DummyRPMDriver from driver.Driver import Dummy2RPMDriver import threading import time c = Driver(DummyRPMDriver()) d = Driver(Dummy2RPMDriver()) root = Tk() #root["bg"] = "black" #root.overrideredirect(True) #root.overrideredirect(False) #root.attributes('-fullscreen',True) logo = PhotoImage(file="telemetry-pi/connected.pgm") w1 = Label(root, image=logo) w1.pack() root.mainloop() def total(): threading.Timer(5.0, total).start() w = Label(root, text=c.getRPM(), fg="white", bg="black") w.pack() g = Label(root, text=d.getRPM(), fg="white", bg="black") g.pack() root.mainloop()
class Server(object): """This class is the interface between the async task that collects the raw data from the Wacom tablet and the GUI. It handles managing the data, triggering events, updating the GUI with new information, controlling the async task, etc. More specifically: - Creating the async process - Getting the raw data from the async process - Clearing the async process's buffer - Dealing with save, reset, and cancel operations - Managing the different phases of the drawing part """ def __init__(self, device): """ :param device: the linux event file of the Wacom device to connect to (eg: /dev/input/event12) """ self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) self.driver = Driver(device) self.driver.start() # Start Async Task self.driver.set_state_running() # Externally set variables self.activeDrawingWindow = None # load keras model self.model = load_model(globals.keras_model_name) self.model._make_predict_function( ) # have to initialize before threading globals.keras_graph = tf.get_default_graph() def predict(self): digit = self.driver.get_buffer_copy() if len(digit) > 2: digit = preprocessing.apply_mean_centering(digit) digit = preprocessing.apply_unit_distance_normalization(digit) try: digit = preprocessing.spline_interpolate_and_resample( digit, 50) except TypeError: # if not enough points are provided to generate a spline, just ignore and go on return None digit = np.array([digit]) return self.model.predict_classes(digit, verbose=0)[0] else: return None # Support Functions def get_device_resolution_width(self): return Settings.RESOLUTION_WIDTH def get_device_resolution_height(self): return Settings.RESOLUTION_HEIGHT def get_device_pen_resolution(self): return Settings.PEN_PRESSURE def attach_active_drawing_window(self, window): """Attach the Server to the currently active Drawing Window""" self.activeDrawingWindow = window self.driver.set_state_running() def detach_active_drawing_window(self): """Detach the currently active Drawing Window from the Server""" self.activeDrawingWindow = None self.driver.set_state_idle() # Other Operations def reset_digit(self): self.driver.clear_buffer()
def generate(self, neg_answer_limit: int, pipe_format: bool) -> None: """Try to find a driver DriverGenerator.device Args: neg_answer_limit: after k negative answer the pattern will be skiped. Use 256 for unlimited pipe_format: if True, input messages are print on a seperate line Raises: DriverGeneratorError: error_code:DriverGeneratorError.DRIVER_ALREADY_EXIST DriverGeneratorError: error_code:ExitCode.FILE_DESCRIPTOR_ERROR """ if self.emitter_is_working(pipe_format): raise DriverGeneratorError( "a driver already exists", DriverGeneratorError.DRIVER_ALREADY_EXIST) for unit in self._units: for selector in range(0, 256): selector = str(selector) # get the control instruction lenght control_size = self._control_size(unit, selector) if not control_size: continue # get the current control instruction value curr_control = self._curr_control(unit, selector, control_size) if not curr_control: continue initial_driver = Driver(curr_control, unit, selector, self._device) exit_code = self.execute_driver(initial_driver) if exit_code != ExitCode.SUCCESS: # if an unit and selector exists but can't be modified continue # get the max control instruction value max_control = self._max_control(unit, selector, control_size) if not max_control or curr_control == max_control: # or: because maxControl isn't a possible instruction for enable the ir emitter continue res_control = self._res_control(unit, selector, control_size, curr_control, max_control) logging.debug( "unit: {}, selector: {}, curr control: {}, max control: {}, res control: {}" .format(unit, selector, curr_control, max_control, res_control)) # try to find the right control instruction next_control = curr_control neg_answer_counter = 0 while (next_control and neg_answer_counter < neg_answer_limit): next_control = self._next_curr_control( next_control, res_control, max_control) if not next_control: continue logging.debug("control: {}".format(next_control)) driver = Driver(next_control, unit, selector, self._device) if self.driver_is_working(driver, pipe_format): self._driver = driver return neg_answer_counter += 1 if neg_answer_counter > neg_answer_limit: logging.debug( "Negative answer limit exceeded, skipping the pattern." ) # reset the control self.execute_driver(initial_driver)
def js(self, ele): Driver.get_driver().execute_script(ele)
def scroll(self, ele): Driver.get_driver().execute_script("arguments[0].scrollIntoView();", ele)
def __init__(self): super(Xueqiu, self).__init__(Driver.driver(), "https://xueqiu.com") self.open()
from Tkinter import * from driver.Driver import Driver from driver.Driver import DummyRPMDriver from driver.Driver import Dummy2RPMDriver from driver.Driver import DummyConnectedDriver c = Driver(DummyRPMDriver()) d = Driver(Dummy2RPMDriver()) e = Driver(DummyConnectedDriver()) root = Tk() root["bg"] = "black" root.overrideredirect(True) root.overrideredirect(False) root.attributes('-fullscreen', True) lab = Label(root) lab.pack() lab2 = Label(root) lab2.pack() lab.config(font=("Arial", 44)) lab2.config(font=("Arial", 44)) connection = e.getConnection() if connection == 1: logo = PhotoImage(file="connected.pgm") w1 = Label(root, image=logo, borderwidth=0, highlightthickness=0) w1.pack()
def __init__(self): super(Search, self).__init__(Driver.driver())
def pytest_runtest_setup(item): Driver.initialize()
def teardown(self): Driver.quit()
def enter_text_iframe(self, iframeid): # 切入 Driver.get_driver().switch_to.frame(iframeid)
def __init__(self): super(Login, self).__init__(Driver.driver())
def out_text_iframe(self): # 切出 Driver.get_driver().switch_to.default_content()