commit 3f02bb6cae814fad32e1fcd81b31096f9f2ec73e
parent cf51a13d8a7b8cfe768fd6d00a8f21fbd32cd5e3
Author: Suzanne Soy <ligo@suzanne.soy>
Date: Tue, 26 Jan 2021 09:15:11 +0000
02021-01-26 stream: List of tools per application in the workbench: create their command + toolbar icon & menu entry
Diffstat:
6 files changed, 95 insertions(+), 9 deletions(-)
diff --git a/AppCommand.py b/AppCommand.py
@@ -28,5 +28,5 @@ class AppCommand():
# return false to grey out the command in the menus, toolbars etc.
return True
-for appName in ExternalAppsList.apps:
+def createCommands(appName):
Gui.addCommand('ExternalAppsOpen' + appName + 'Command', AppCommand(appName))
diff --git a/AppTools.py b/AppTools.py
@@ -0,0 +1,32 @@
+import os
+import FreeCAD
+import FreeCADGui as Gui
+import PySide
+from PySide import QtGui
+from PySide import QtCore
+
+import ExternalAppsList
+import Embed
+
+class ToolCommand():
+ def __init__(self, appName, toolName):
+ self.Tool = ExternalAppsList.apps[appName].Tools[toolName]
+
+ def GetResources(self):
+ return {
+ 'Pixmap': self.Tool.Icon,
+ #'Accel': "Shit+T",
+ 'MenuText': self.Tool.ToolName,
+ 'ToolTip': "Runs the " + self.Tool.ToolName + " tool from " + self.Tool.AppName + "\n\n" + self.Tool.ToolTip,
+ }
+
+ def Activated(self):
+ print("tool " + self.Tool.ToolName + " of " + self.Tool.AppName + " was activated with xforms" + str(self.Tool.XForms))
+
+ def IsActive(self):
+ # return false to grey out the command in the menus, toolbars etc.
+ return True
+
+def createCommands(appName):
+ for toolName in ExternalAppsList.apps[appName].Tools:
+ Gui.addCommand('ExternalAppsTool' + appName + toolName + 'Command', ToolCommand(appName, toolName))
diff --git a/Embed.py b/Embed.py
@@ -106,6 +106,7 @@ def try_pipe_lines(commandAndArguments):
except:
return []
+# TODO: this is just a quick & dirty way to attach a field to the FreeCad object
class ExternalApps():
def __init__(self):
setattr(FreeCAD, 'ExternalApps', self)
diff --git a/ExternalAppsList.py b/ExternalAppsList.py
@@ -9,34 +9,71 @@ from PySide import QtCore
from MyX11Utils import *
+class Tool():
+ def __init__(self, *, appName, toolName, xForms, toolTip, icon, extendedDescription, openHelpFile):
+ self.AppName = appName
+ self.ToolName = toolName
+ self.XForms = xForms
+ self.ToolTip = toolTip
+ self.Icon = icon
+ self.ExtendedDescription = extendedDescription
+ self.OpenHelpFile = openHelpFile
+
+ @staticmethod
+ def fromXForms(*, appName, xForms):
+ # TODO: implement a tool cache which avoids parsing the XML and memorizes the name and icon
+ return Tool(appName=appName,
+ toolName = "from XForms … TODO",
+ xForms = xForms,
+ toolTip = "from XForms … TODO",
+ # TODO: get the icon from the XForms file
+ icon = os.path.dirname(__file__) + '/icons/' + appName + '.svg',
+ extendedDescription = "from XForms … TODO",
+ openHelpFile = None)
+
+class ToolsClass():
+ def __init__(self, tools):
+ # TODO: make this private
+ self.AllTools = {tool.ToolName: tool for tool in tools}
+ def __getitem__(self, k):
+ return self.AllTools[k]
+ def __iter__(self):
+ return self.AllTools.__iter__()
+
class App():
- def __init__(self, name, *, start_command_and_args, xwininfo_filter_re, extra_xprop_filter):
+ def __init__(self, name, *, start_command_and_args, xwininfo_filter_re, extra_xprop_filter, tools):
self.name = name
self.Icon = os.path.dirname(__file__) + '/icons/' + self.name + '.svg'
self.start_command_and_args = start_command_and_args
self.xwininfo_filter_re = re.compile(xwininfo_filter_re)
self.extra_xprop_filter = extra_xprop_filter
+ self.Tools = ToolsClass([Tool.fromXForms(appName=self.name, xForms=t) for t in tools])
class Apps():
def __init__(self, *apps):
# TODO: make this private
- self.apps = {app.name: app for app in apps}
+ self.AllApps = {app.name: app for app in apps}
def __getitem__(self, k):
- return self.apps[k]
+ return self.AllApps[k]
def __iter__(self):
- return self.apps.__iter__()
+ return self.AllApps.__iter__()
# app-specific infos:
apps = Apps(
App('Mousepad',
start_command_and_args = ['mousepad', '--disable-server'],
xwininfo_filter_re = r'mousepad',
- extra_xprop_filter = lambda processId, windowId, i: True),
+ extra_xprop_filter = lambda processId, windowId, i: True,
+ tools = []),
App('Inkscape',
start_command_and_args = ['inkscape'],
xwininfo_filter_re = r'inkscape',
- extra_xprop_filter = lambda processId, windowId, i: x11prop(windowId, 'WM_STATE', 'WM_STATE') is not None),
+ extra_xprop_filter = lambda processId, windowId, i: x11prop(windowId, 'WM_STATE', 'WM_STATE') is not None,
+ tools = [
+ "myTool.xforms"
+ ]),
App('GIMP',
start_command_and_args = ['env', '-i', 'DISPLAY=:0', '/home/suzanne/perso/dotfiles/nix/result/bin/gimp', '--new-instance'],
xwininfo_filter_re = r'gimp',
- extra_xprop_filter = lambda processId, windowId, i: x11prop(windowId, 'WM_STATE', 'WM_STATE') is not None))
+ extra_xprop_filter = lambda processId, windowId, i: x11prop(windowId, 'WM_STATE', 'WM_STATE') is not None,
+ tools = []))
diff --git a/InitGui.py b/InitGui.py
@@ -52,10 +52,20 @@ class XternalAppsWorkbench(Workbench):
super(XternalAppsWorkbench, self).__init__()
def Initialize(self):
+ # Load commands
import AppCommand
+ import AppTools
import Embed
Embed.ExternalApps()
- self.list = ['ExternalAppsOpen' + self.appName + 'Command']
+ AppCommand.createCommands(self.appName)
+ AppTools.createCommands(self.appName)
+
+ # List of commands for this workbench
+ self.list = ['ExternalAppsOpen' + self.appName + 'Command'] \
+ + ['ExternalAppsTool' + self.appName + toolName + 'Command'
+ for toolName in ExternalAppsList.apps[self.appName].Tools]
+
+ # Create menus and toolbars
self.appendMenu("ExternalApplications", self.list)
self.appendToolbar("ExternalApplications", self.list)
diff --git a/myTool.py b/myTool.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+import sys
+
+for arg in sys.argv:
+ print(str(arg)