Looking for a way to make the drop down table and or list bigger, for better touchscreen control.
Works with the ‘List’ view style:
from com.inductiveautomation.factorypmi.application.components.PMIComboBox import DataSetListCellRenderer
from java.awt import Dimension
class BigDSRenderer(DataSetListCellRenderer):
def getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus):
component = DataSetListCellRenderer.getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus)
component.setPreferredSize(Dimension(event.source.width, event.source.height * 2))
return component
target = event.source.parent.getComponent('Dropdown 1')
target.setRenderer(BigDSRenderer(target))
You’ll need to update ‘target’ to point at the actual component. You could run this on visionWindowOpened
, or a propertyChange
event listening for componentRunning
.
Paul,
-
I find the event.source.height * 2 does not work correctly. It is returning row heights taller than the screen. I believe the dimension command is getting window dimensions. I ended up just setting my height to 50 pixels.
-
I want to use this technique for a dropdown list within a power table configure editor extension function. How do I do this? I can’t figure out what my target is…
This is great! But I have a likely dumb question… If I add this code into a script library, how can I use it in a component’s script? I can’t figure out how to import it to reference BigDSRenderer
Cheers!
Edit: worked out this part, I can just use, for example (duh):
target.setRenderer(project.ddm.BigDSRenderer(target))
But that leads me to another question:
How can I pass in the target component to access the size of it? I also want to pass in a height factor so that I can increase the height if needed.
There are many different ways to do this - here's where I would probably start (if you just want to pass in that scale factor dynamically):
from com.inductiveautomation.factorypmi.application.components.PMIComboBox import DataSetListCellRenderer
from java.awt import Dimension
class BigDSRenderer(DataSetListCellRenderer):
def __init__(self, target, scale):
DataSetListCellRenderer.__init__(self, target)
self.scale = scale
def getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus):
component = DataSetListCellRenderer.getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus)
component.setPreferredSize(Dimension(event.source.width, event.source.height * self.scale))
return component
target = event.source.parent.getComponent('Dropdown 1')
target.setRenderer(BigDSRenderer(target, 2))
What this does is override the __init__()
method on the BigDSRenderer
class. Technically, there is no __init__()
method on the original Java class (Java classes work differently to Python, using overloaded constructors) but Jython translates the Java method's initialization into the __init__()
form for use with Python. So, we define BigDSRenderer
to have it's own custom init
method - but the very first thing it does is call DataSetListCellRenderer
s __init__()
method. This is one way to call the superclass' instantiation method (meaning it's still going to do everything that the original class did, which we want). Then it's going to take the additional argument we gave the constructor (scale) and assign it to a variable on the instance.
Then when we create an instance of the BigDSRenderer
class, it expects two arguments - the target, and the scaling factor.
Disclaimer(s):
I haven't actually tested this modification, though I've done the same thing in many different areas, and some of my terminology may be slightly off (I'm mostly self-taught at this).
Awesome, thanks for that! I’m still relatively new to Python, and haven’t delved at all into classes so this is a big help.
for reference, I modified your code slightly and have this defined within a project script library under:
project.components.ddm
from com.inductiveautomation.factorypmi.application.components.PMIComboBox import DataSetListCellRenderer
from java.awt import Dimension
class BigDSRenderer(DataSetListCellRenderer):
def __init__(self, target, scale):
DataSetListCellRenderer.__init__(self, target)
self.target = target
self.scale = scale
def getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus):
component = DataSetListCellRenderer.getListCellRendererComponent(self, list, value, index, isSelected, cellHasFocus)
component.setPreferredSize(Dimension(self.target.width, int(self.target.height * self.scale)))
return component
Then on a ddm object on its componentRunning property change, i run this:
target = event.source
target.setRenderer(project.components.ddm.BigDSRenderer(target, 1.5))
Will this work in ‘table’ mode? I am using a dropdown list in table mode on a touchscreen and the users will need bigger rows. Is this possible? @PGriffith
The short answer is that no, there’s no good way to override the table renderer due to the way it’s nested inside the parent dropdown class.
Paul, I regularly use this approach for touch screens. However, I have noticed that if I set horizontal alignment to center on the dropdown, this script breaks it. What do I add to the script to set horizontal alignment to center?
I have added
component.setHorizontalAlignment(SwingConstants.CENTER)
to the script and now the string show correctly in the pre-dropdown view. However, now the dropdown list is right aligned and off the screen.
Hi
I try to use these script for check if it increase the cursor too, but in my case don’t work.
Dropdown open and close faster on event “property change”…
There is a way to increase dimension for cursor for use in touch screen project?
Thanks
What do you mean when you say the ‘cursor’?
this part…
You can set the scroll bar width Under Project -> Properties -> Client -> General -> Scroll Bar Width
Thanks!
Work fine