I'm trying to implement a generic popup window, to avoid having to create a popup window for every template that I want as a popup.
So the window accepts a TemplatePath and a Dataset holding the template parameters.
Now I'm at the part where I want the popup window to resize itself to the template's design-time size.
Below is a snippet that includes a few lines from posts in this forum to retrieve the template size.
I'm wondering though, does TemplateManager's
getTemplateInstance() method create a new instance and store it in its cache? Is that potentially bad in any way?
from com.inductiveautomation.factorypmi.application.components.util import FPMILayout
from com.inductiveautomation.ignition.client.util.gui import DrawingUtilities
# Get template size
wnd = visionUtils.getParentWindow(self)
appCtx = wnd.getAppContext()
templateManager = appCtx.getTemplateManager()
templateInstance = templateManager.getTemplateInstance(templatePath)
mastersize = DrawingUtilities.round(FPMILayout.getBounds(templateInstance))
print 'MasterSize: %s' % mastersize
# Apply parameters
templatePath = self.TemplatePath
template = visionUtils.getFirstChildTemplateEx(self)
dsParams = self.TemplateParameters
if dsParams is None or dsParams.getRowCount() == 0:
colNames = dsParams.getColumnNames()
for colName in colNames:
paramName = colName
paramValue = dsParams.getValueAt(0, colName)
if hasattr(template, paramName):
setattr(template, paramName, paramValue)
So you're trying to use a single popup window with an embedded template in it whose template path is based on a parameter you've passed into the popup? And the template parameters are based on the values in a dataset passed in?
Do you need the dataset? Can your templates just all use the same parameters? This would make this much simpler and more standardised, and less effort and knowledge of the project from a dev point of view. A fixed set of parameters on the other hand is simple since you can see all of the options available
Yes, that's right.
Well about the dataset vs fixed set of parameters, the problem is that many of my popups are about many different (MES) things, and not HMI things (tags, UDT, etc).
For example, I have different workorders with different properties and so I built multiple templates to edit each type of work orders. I'm also having to edit things from Sepasoft, such as Segment's Material Properties, and things like that, because the Sepasoft Vision components are limited in what they allow you to do, and so I have a popup to edit/view a matProp, and then another popup to select a specific material (since the mes object selector is kind of limited). Things like that. I must have 10+ popups so far, and I think I might build more of them. So I thought, couldn't there be a way to make popups like they're done in Perspective? Simply create a view and call a method to show it as a popup? That'd be great.
Of course, I could avoid all that by only using windows, but I'd sacrifice reusability. A template can be a popup, it can be embedded into another template or be a main window. That's why I always build my components with a Template instead of a Window :s
Oy! This makes my head hurt. The functional overlap between window duties, popup duties, and an embedded template's requirements makes this seem like a stretch. I would make popups with the same name as the template to contain it and perform the template-specific handoffs. And to hold the buttons or other functions (Save and cancel, perhaps, for editors) that aren't applicable within the template.
If you are passing parameters into the template to change its behavior and/or hide some parts based on container, then I would say your architectural boundary is drawn in the wrong place.
I might have exagerated my uses of a template, but here's an example that I find reasonable. I repeated this dual use for a few templates, for my own convenience:
Case 1: selecting a lot number from a table, and using the right-click context menu to open a lot in the "Lot Editor" popup.
Case 2: enter a lot number manually in a textbox to pass to the template within a window accessible from the header menu: