def run_program(entry, path, parent): # noqa import re cmdline = entry_to_cmdline(entry, path) flags = win32con.CREATE_DEFAULT_ERROR_MODE | win32con.CREATE_NEW_PROCESS_GROUP if re.match(r'"[^"]+?(.bat|.cmd|.com)"', cmdline, flags=re.I): flags |= win32con.CREATE_NO_WINDOW console = ' (console)' else: flags |= win32con.DETACHED_PROCESS console = '' print('Running Open With commandline%s:' % console, repr(entry['cmdline']), ' |==> ', repr(cmdline)) try: with sanitize_env_vars(): process_handle, thread_handle, process_id, thread_id = CreateProcess( None, cmdline, None, None, False, flags, None, None, STARTUPINFO()) WaitForInputIdle(process_handle, 2000) except Exception as err: return error_dialog( parent, _('Failed to run'), _('Failed to run program, click "Show Details" for more information' ), det_msg='Command line: %r\n%s' % (cmdline, as_unicode(err)))
def run_program(entry, path, parent): # noqa cmdline = entry_to_cmdline(entry, path) print('Running Open With commandline:', repr(entry['cmdline']), ' |==> ', repr(cmdline)) try: with sanitize_env_vars(): process_handle, thread_handle, process_id, thread_id = CreateProcess( None, cmdline, None, None, False, win32con.CREATE_DEFAULT_ERROR_MODE | win32con.CREATE_NEW_PROCESS_GROUP | win32con.DETACHED_PROCESS, None, None, STARTUPINFO()) WaitForInputIdle(process_handle, 2000) except Exception as err: return error_dialog( parent, _('Failed to run'), _( 'Failed to run program, click "Show Details" for more information'), det_msg='Command line: %r\n%s' %(cmdline, as_unicode(err)))
def StartYardServer(self): try: rkey = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Webers\\Y.A.R.D") path = RegQueryValueEx(rkey, "program")[0] if not os.path.exists(path): raise Exception except: raise self.Exception( "Please start Yards.exe first and configure it.") try: hProcess = CreateProcess(None, path, None, None, 0, CREATE_NEW_CONSOLE, None, None, STARTUPINFO())[0] except Exception as exc: raise eg.Exception(FormatError(exc[0])) WaitForInputIdle(hProcess, 10000)
class YARD(eg.PluginBase): def __init__(self): self.AddEvents() self.isEnabled = False self.mapTable = {} self.timer = Timer(0, self.OnTimeOut) self.lastEvent = "" self.timeout = 0.2 self.remote_control_timeout = 0.4 self.disableUnmapped = False self.thread = None self.comObj = None self.workerThread = None self.buttons = [False] * 16 self.AddAction(SendRemoteKey) self.AddAction(ClearScreen) self.AddAction(Print) def __start__(self): try: self.comObj = GetActiveObject(YARD_CLSID) except com_error: self.StartYardServer() try: self.comObj = GetActiveObject(YARD_CLSID) except: raise if self.comObj: self.comObj = Dispatch(YARD_CLSID) class SubEventHandler(EventHandler): plugin = self TriggerEvent = self.TriggerEvent self.workerThread = YardWorkerThread(self, SubEventHandler) try: self.workerThread.Start( 60.0 ) except: self.workerThread = None raise self.Exception( self.text.errorMesg ) self.isEnabled = True def __stop__(self): self.isEnabled = False if self.workerThread is not None : if self.workerThread.Stop( TERMINATE_TIMEOUT ) : eg.PrintError("Could not terminate YARD thread") self.workerThread = None if self.comObj: del self.comObj self.comObj = None def OnTimeOut(self): self.EndLastEvent() self.lastEvent = "" def HandleEventEx(self, keyhex, keymapped, keytype, keyevent): if not self.isEnabled: return # keytype # 0 = remote control # 1 = rotary encoder # 2 = keypad from keylcd # keyevent # 0 - a key (without up down detection) # 1 - key down event # 2 - key repeat event # 3 - key up event # keymapped - Yard Mapped keyname (symbolic one) # keyhex - native hex code of the key (just info?) if keytype == 0: if keyevent == 0: # 0 up down detection in yards disabled if self.timer: self.timer.cancel() self.TriggerEnduringEvent(keymapped) self.timer = Timer(self.remote_control_timeout, self.OnTimeOut) self.timer.start() elif keyevent == 1: # Yard Received a new key down... self.TriggerEnduringEvent(keymapped) elif keyevent == 2: # Yard Received a repeated key... if self.timer: self.timer.cancel() self.timer = Timer(self.remote_control_timeout, self.OnTimeOut) self.timer.start() elif keyevent == 3: # Yard detected a keyup... if self.timer: self.timer.cancel() self.timer = None self.EndLastEvent() elif keytype == 1: self.TriggerEvent(keymapped) elif keytype == 2: # key pad keylcd if keyevent == 1: self.TriggerEvent(keymapped+".down") elif keyevent == 2: # +".repeat" self.TriggerEvent(keymapped) elif keyevent == 3: self.TriggerEvent(keymapped+".up") def HandleEvent(self, eventString): if not self.isEnabled: return if eventString[:2] == "07": if eventString[6:8] == "01": i = int(eventString[10:12]) self.buttons[i] = True buttons = [ "Button%i" % i for i, btn in enumerate(self.buttons) if btn ] self.TriggerEvent("+".join(buttons)) elif eventString[6:8] == "03": i = int(eventString[10:12]) self.buttons[i] = False self.EndLastEvent() elif eventString == "070000001080FF": buttons = [ "Button%i" % i for i, btn in enumerate(self.buttons) if btn ] buttons.append("JogLeft") self.TriggerEvent("+".join(buttons)) elif eventString == "070000001081FF": buttons = [ "Button%i" % i for i, btn in enumerate(self.buttons) if btn ] buttons.append("JogRight") self.TriggerEvent("+".join(buttons)) else: self.TriggerEvent(eventString) return if eventString in self.mapTable: eventString, timeout = self.mapTable[eventString] else: if self.disableUnmapped: return timeout = self.timeout self.timer.cancel() if self.lastEvent != eventString: self.TriggerEnduringEvent(eventString) self.lastEvent = eventString self.timer = Timer(timeout, self.OnTimeOut) self.timer.start() def Map(self, what, to, timeout=None): self.mapTable[what] = (to, timeout or self.timeout) def StartYardServer(self): try: rkey = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Webers\\Y.A.R.D") path = RegQueryValueEx(rkey, "program")[0] if not os.path.exists(path): raise Exception except: raise self.Exception( "Please start Yards.exe first and configure it." ) try: hProcess = CreateProcess( None, path, None, None, 0, CREATE_NEW_CONSOLE, None, None, STARTUPINFO() )[0] except Exception, exc: raise eg.Exception(FormatError(exc[0])) WaitForInputIdle(hProcess, 10000)