diff --git a/Embed.py b/Embed.py index 8ec44b8..68a5806 100644 --- a/Embed.py +++ b/Embed.py @@ -90,22 +90,30 @@ class ExternalAppInstance(QtCore.QObject): raise def attemptToFindWindowWrapped(self): - # use decode('utf-8', 'ignore') to use strings instead of byte strings and discard ill-formed unicode in case these tool doesn't sanitize their output for line in try_pipe_lines(['xwininfo', '-root', '-tree', '-int']): - if self.app.xwininfo_filter_re.search(line): - windowId = int(xwininfo_re.match(line).group(1)) - # use decode('utf-8', 'ignore') to use strings instead of byte strings and discard ill-formed unicode in case this tool doesn't sanitize their output - xprop_try_process_id = x11prop(windowId, '_NET_WM_PID', 'CARDINAL') - if xprop_try_process_id: - processId = int(xprop_try_process_id) # TODO try parse int and catch failure - if processId in self.appProcessIds: - if self.app.extra_xprop_filter(processId, windowId, len(self.foundWindows)): - self.foundWindow(processId, windowId) + self.attemptWithLine(line) if self.elapsed.elapsed() > self.startupTimeout: self.timer.stop() self.TimeoutHasOccurred = True + def attemptWithLine(self, line): + if not self.app.xwininfo_filter_re.search(line): + return + xwininfo_re_match_line = xwininfo_re.match(line) + if not xwininfo_re_match_line: + return + windowId = int(xwininfo_re_match_line.group(1)) + xprop_try_process_id = x11prop(windowId, '_NET_WM_PID', 'CARDINAL') + if not xprop_try_process_id: + return + processId = int(xprop_try_process_id) # TODO try parse int and catch failure + if processId not in self.appProcessIds: + return + if not self.app.extra_xprop_filter(processId, windowId, len(self.foundWindows)): + return + self.foundWindow(processId, windowId) + def foundWindow(self, processId, windowId): if windowId not in self.foundWindows.keys(): self.foundWindows[windowId] = EmbeddedWindow(self.app, self, processId, windowId) diff --git a/GIMPCommand.py b/GIMPCommand.py index dfaa093..0be18e3 100644 --- a/GIMPCommand.py +++ b/GIMPCommand.py @@ -7,21 +7,25 @@ from PySide import QtCore import Embed class GIMPCommand(): + def __init__(self, appName): + self.appName = appName + def GetResources(self): return { 'Pixmap': ':/icons/GIMP.svg', - 'Accel': "Shit+G", - 'MenuText': "Menu text", - 'ToolTip': "Tooltip", + 'Accel': "Shit+E", # E for Embed + 'MenuText': "Start " + self.appName, + 'ToolTip': "Start " + self.appName, } def Activated(self): - print("Command activated") - p = Embed.ExternalAppInstance('GIMP') + p = Embed.ExternalAppInstance(self.appName) p.waitForWindow() def IsActive(self): # return false to grey out the command in the menus, toolbars etc. return True -Gui.addCommand('GIMPCommand', GIMPCommand()) +Gui.addCommand('MousepadCommand', GIMPCommand('Mousepad')) +Gui.addCommand('InkscapeCommand', GIMPCommand('Inkscape')) +Gui.addCommand('GIMPCommand', GIMPCommand('GIMP')) diff --git a/InitGui.py b/InitGui.py index f123f5b..d2e36e0 100644 --- a/InitGui.py +++ b/InitGui.py @@ -44,17 +44,14 @@ class XternalAppsWorkbench(Workbench): global myIcon global XternalAppsWorkbench - ToolTip = "Embeds external Applications in FreeCAD" Icon = myIcon def __init__(self): - print('inside XternalAppsWorkbench __init__()') self.MenuText = "XternalApps: " + self.appName + self.ToolTip = "Embeds " + self.appName + " in FreeCAD" super(XternalAppsWorkbench, self).__init__() - print('finished XternalAppsWorkbench __init__()') def Initialize(self): - print('Initialize') if sys.version_info[0] == 2: import Resources2 else: @@ -67,11 +64,9 @@ class XternalAppsWorkbench(Workbench): self.appendToolbar("ExternalApplications", self.list) def Activated(self): - print('Activated') pass def Deactivated(self): - print('Deactivated') pass #def ContextMenu(self): diff --git a/MyX11Utils.py b/MyX11Utils.py index 7b57ee9..b4ffd09 100644 --- a/MyX11Utils.py +++ b/MyX11Utils.py @@ -17,7 +17,11 @@ def x11stillAlive(windowId): def x11prop(windowId, prop, type): try: - output = subprocess.check_output(['xprop', '-id', str(windowId), prop]).decode('utf-8', 'ignore').split('\n') + process_output = subprocess.check_output(['xprop', '-id', str(windowId), prop]) + # use decode('utf-8', 'ignore') to use strings instead of + # byte strings and discard ill-formed unicode in case this + # tool doesn't sanitize their output + output = process_output.decode('utf-8', 'ignore').split('\n') except subprocess.CalledProcessError as e: output = [] xprop_re = re.compile(r'^' + re.escape(prop) + r'\(' + re.escape(type) + r'\)((:)| =(.*))$')