Skip to content

Commit

Permalink
clean up deprecated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen committed Feb 10, 2019
1 parent 11258de commit ae859bf
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 68 deletions.
4 changes: 2 additions & 2 deletions jython/AudioPlayer.py
Expand Up @@ -168,9 +168,9 @@ def updateSourcesList(self):
# Now populate
self.sourceCombo.addItem(self.SELECT)
# Retrieve system name list of AudioSources
for source in audio.getSystemNameList(Audio.SOURCE):
for source in audio.getNamedBeanSet(Audio.SOURCE):
# Add available sources to the list
self.sourceCombo.addItem(source)
self.sourceCombo.addItem(source.getSystemName())

def whenRangeChanged(self, event):
# store value & update sliders
Expand Down
43 changes: 17 additions & 26 deletions jython/AutoDispatcher2.py
Expand Up @@ -584,15 +584,13 @@ def getLayoutData(self) :
return

# Retrieve SignalHead names from JMRI (will be used to populate menus)
signalHeads = InstanceManager.signalHeadManagerInstance(
).getSystemNameList()
signalHeads = InstanceManager.getDefault(SignalHeadManager).getNamedBeanSet()
AutoDispatcher.signalHeadNames = [""]
for s in signalHeads :
# Use UserName (if available), otherwise SystemName
signalName = InstanceManager.signalHeadManagerInstance(
).getSignalHead(s).getUserName()
signalName = s.getUserName()
if signalName == None or signalName.strip() == "" :
signalName = s
signalName = s.getSystemName()
AutoDispatcher.signalHeadNames.append(signalName)
AutoDispatcher.signalHeadNames.sort()

Expand All @@ -611,20 +609,20 @@ def getLayoutData(self) :
[signalIcon, signalIcon.getClickMode()])

# Retrieve sections from JMRI
sections = InstanceManager.sectionManagerInstance().getSystemNameList()
# (it's unfortunate that this uses "sections" differently than the jmri_defaults style)
sections = InstanceManager.getDefault(jmri.SectionManager).getNamedBeanSet()
if sections.size() < 1 :
AutoDispatcher.chimeLog(ADsettings.ATTENTION_SOUND,
"Layout contains no sections, script" +
" cannot continue!")

# Create section and block instances
for section in sections :
ADsection(section)
ADsection(section.getSystemName())

if len(ADsection.getList()) == 0 :
AutoDispatcher.chimeLog(ADsettings.ATTENTION_SOUND,
"No valid section found, script" +
" cannot continue!")
"No valid section found, script cannot continue!")
AutoDispatcher.error = True
return

Expand Down Expand Up @@ -892,8 +890,7 @@ def setSignals(self) :
newName = "H" + s.getName() + extension[i]
# Check if a SignalMast or a SignalHead with such a name exists
newSignal = ADsignalMast.getByName(newName)
newHead = InstanceManager.signalHeadManagerInstance(
).getSignalHead(newName)
newHead = InstanceManager.getDefault(jmrix.SignalHeadManager).getSignalHead(newName)
# Assign a new SignalMast only if it was not yet assigned
# or it was automatically created in a previous call
# (provided we found a replacement!) Replacing signals
Expand All @@ -918,8 +915,7 @@ def setSignals(self) :
if s.manualSensor == None :
sensorName = s.getName() + "man"
if sensorName in ADsection.sensorNames :
s.manualSensor = InstanceManager.sensorManagerInstance(
).getSensor(sensorName)
s.manualSensor = InstanceManager.sensorManagerInstance().getSensor(sensorName)

# OPERATIONS ==============

Expand Down Expand Up @@ -1834,8 +1830,7 @@ def putSectionsTable() :
section.manualSensor = None
elif sensorName.strip() != "" :
section.manualSensor = (
InstanceManager.sensorManagerInstance(
).getSensor(sensorName))
InstanceManager.sensorManagerInstance().getSensor(sensorName))
if len(i) > 7 :
section.stopAtBeginning = i[7]
if len(i) > 9 and ADsettings.autoRestart :
Expand Down Expand Up @@ -1952,7 +1947,7 @@ def removeListeners() :
def __init__(self, systemName):
# Retrieve Section.java instance from JMRI
self.jmriSection = (
InstanceManager.sectionManagerInstance().getBySystemName(systemName))
InstanceManager.getDefault(jmri.SectionManager).getBySystemName(systemName))
# Get section name
self.name = self.jmriSection.getUserName()
if self.name == None or self.name.strip() == "" :
Expand Down Expand Up @@ -2063,19 +2058,16 @@ def __init__(self, systemName):
# Remove from the list sensors associated with blocks
# (this makes user selection easier and faster)
# Get all blocks
blocks = InstanceManager.blockManagerInstance().getSystemNameList()
blocks = InstanceManager.getDefault(jmri.BlockManager).getNamedBeanSet()
blockSensors = []
for b in blocks :
sensor = InstanceManager.blockManagerInstance(
).getBlock(b).getSensor()
sensor = b.getSensor()
if sensor != None :
blockSensors.append(sensor.getSystemName())
sensors = InstanceManager.sensorManagerInstance(
).getSystemNameList()
blockSensors.append(sensor)
sensors = InstanceManager.sensorManagerInstance().getNamedBeanSet()
for s in sensors:
if not s in blockSensors :
sensorName = InstanceManager.sensorManagerInstance(
).getSensor(s).getUserName()
sensorName = s.getUserName()
if sensorName == None or sensorName.strip() == "" :
sensorName = s
if sensorName != "ISCLOCKRUNNING" :
Expand Down Expand Up @@ -5657,8 +5649,7 @@ def __init__(self, signalName) :
self.signalHead = None
self.iconOnLayout = False
if signalName.strip() != "" :
self.signalHead = InstanceManager.signalHeadManagerInstance(
).getSignalHead(signalName)
self.signalHead = InstanceManager.signalHeadManagerInstance().getSignalHead(signalName)
if self.signalHead != None :
self.setHeld(False)
self.iconOnLayout = signalName in AutoDispatcher.signalIcons
Expand Down
14 changes: 7 additions & 7 deletions jython/BlockOccupancyAnnouncer.py
Expand Up @@ -74,18 +74,18 @@ def propertyChange(self, event):
# and new sensors)
class ManagerListener(java.beans.PropertyChangeListener):
def propertyChange(self, event):
list = event.source.getSystemNameList()
for i in range(list.size()) :
event.source.getSensor(list.get(i)).removePropertyChangeListener(listener)
event.source.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = event.source.getNamedBeanSet()
for sensor in list :
sensor.removePropertyChangeListener(listener)
sensor.addPropertyChangeListener(listener)

# Attach the sensor manager listener
sensors.addPropertyChangeListener(ManagerListener())

# For the sensors that exist, attach a sensor listener
list = sensors.getSystemNameList()
for i in range(list.size()) :
sensors.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = sensors.getNamedBeanSet()
for i in list :
sensor.addPropertyChangeListener(listener)

speak("block occupancy announcer started")

Expand Down
7 changes: 3 additions & 4 deletions jython/InitTurnouts.py
Expand Up @@ -10,12 +10,11 @@

import jmri

def initTurnout(turnout):
to = turnouts.provideTurnout(turnout)
def initTurnout(to):
to.setState(to.getKnownState())
return

# invoke for all defined turnouts
for x in turnouts.getSystemNameList().toArray() :
initTurnout(x)
for to in turnouts.getNamedBeanSet() :
initTurnout(to)

2 changes: 1 addition & 1 deletion jython/RobotThrottle3.py
Expand Up @@ -1902,7 +1902,7 @@ def setup(self) :
self.redFlashSignalIcon = jmri.jmrit.catalog.NamedIcon("resources/icons/smallschematics/searchlights/right-flashred-short.gif", "RedFlashCabSignal")
self.darkSignalIcon = jmri.jmrit.catalog.NamedIcon("resources/icons/smallschematics/searchlights/right-dark-short.gif", "DarkCabSignal")
self.unknownSignalIcon = jmri.jmrit.catalog.NamedIcon("resources/icons/misc/Question-black.gif", "UnknownCabSignal")
self.throttleManager = jmri.InstanceManager.throttleManagerInstance()
self.throttleManager = jmri.InstanceManager.getDefault(jmri.ThrottleManager)
if (self.throttleManager == None) :
print("No command station found!!\nRT has no way to control the trains.\n")
return
Expand Down
14 changes: 7 additions & 7 deletions jython/SensorLog.py
Expand Up @@ -52,17 +52,17 @@ def propertyChange(self, event):
# and new sensors)
class ManagerListener(java.beans.PropertyChangeListener):
def propertyChange(self, event):
list = event.source.getSystemNameList()
for i in range(list.size()) :
event.source.getSensor(list.get(i)).removePropertyChangeListener(listener)
event.source.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = event.source.getNamedBeanSet()
for sensor in list :
sensor.removePropertyChangeListener(listener)
sensor.addPropertyChangeListener(listener)

# Attach the sensor manager listener
sensors.addPropertyChangeListener(ManagerListener())

# For the sensors that exist, attach a sensor listener
list = sensors.getSystemNameList()
for i in range(list.size()) :
sensors.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = sensors.getNamedBeanSet()
for sensor in list :
sensor.addPropertyChangeListener(listener)


14 changes: 7 additions & 7 deletions jython/SensorToTurnout.py
Expand Up @@ -45,18 +45,18 @@ def propertyChange(self, event):
# and new sensors)
class ManagerListener(java.beans.PropertyChangeListener):
def propertyChange(self, event):
list = event.source.getSystemNameList()
for i in range(list.size()) :
event.source.getSensor(list.get(i)).removePropertyChangeListener(listener)
event.source.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = event.source.getNamedBeanSet()
for sensor in list :
sensor.removePropertyChangeListener(listener)
sensor.addPropertyChangeListener(listener)

# Attach the sensor manager listener
sensors.addPropertyChangeListener(ManagerListener())

# For the sensors that exist, attach a sensor listener
list = sensors.getSystemNameList()
for i in range(list.size()) :
sensors.getSensor(list.get(i)).addPropertyChangeListener(listener)
list = sensors.getNamedBeanSet()
for sensor in list:
sensor.addPropertyChangeListener(listener)



3 changes: 1 addition & 2 deletions jython/SetAllTurnoutsClosed.py
Expand Up @@ -10,9 +10,8 @@
chgCnt = 0

# loop thru all defined turnouts
for toName in turnouts.getSystemNameList().toArray() :
for to in turnouts.getNamedBeanSet():
toCnt += 1
to = turnouts.getTurnout(toName)
cs = to.getState()
if (cs != CLOSED) :
chgCnt += 1
Expand Down
3 changes: 1 addition & 2 deletions jython/SetAllTurnoutsToDirect.py
Expand Up @@ -8,9 +8,8 @@
toCnt = 0
chgCnt = 0
# loop thru all defined turnouts, setting each to DIRECT if not already DIRECT
for toName in turnouts.getSystemNameList().toArray() :
for to in turnouts.getNamedBeanSet():
toCnt += 1
to = turnouts.getTurnout(toName)
fm = to.getFeedbackMode()
if (fm != jmri.Turnout.DIRECT) :
to.setFeedbackMode(jmri.Turnout.DIRECT)
Expand Down
5 changes: 2 additions & 3 deletions jython/SetAllUnknownSensorsToInactive.py
Expand Up @@ -9,10 +9,9 @@
chgCnt = 0

# loop thru defined sensors, if UNKNOWN, set to INACTIVE
list = sensors.getSystemNameList()
for i in range(list.size()) :
list = sensors.getNamedBeanSet()
for s in list :
sCnt += 1
s = sensors.getSensor(list.get(i))
cs = s.getKnownState()
if cs == UNKNOWN :
chgCnt += 1
Expand Down
11 changes: 4 additions & 7 deletions jython/TurnoutStatePersistence.py
Expand Up @@ -46,7 +46,7 @@ class PersistTurnoutStateTask(jmri.implementation.AbstractShutDownTask):
def execute(self):

# Write an info entry to the log
self.log.info("Write turnout state to file: %s" % turnoutFile)
self.log.info("Write turnout state to file: {}}", turnoutFile)

# Open file
csvFile = com.csvreader.CsvWriter(turnoutFile)
Expand All @@ -63,14 +63,11 @@ def execute(self):
csvFile.endRecord()

# Loop through all known turnouts
for turnout in turnouts.getSystemNameList().toArray():
for to in turnouts.getNamedBeanSet():

# Write a debug entry to the log
if (self.log.isDebugEnabled()):
self.log.debug("Storing turnout: %s" % turnout)

# Get turnout object
to = turnouts.provideTurnout(turnout)
self.log.debug("Storing turnout: {}", to.getSystemName())

# Retrieve details to persist
csvFile.write(to.getSystemName())
Expand All @@ -86,7 +83,7 @@ def execute(self):
turnoutCount +=1

# Write an info entry to the log
self.log.info("Stored state of %d turnouts" % turnoutCount)
self.log.info("Stored state of {} turnouts", turnoutCount)

# Append a comment to the end of the file
csvFile.writeComment("Written by JMRI version %s on %s" % (jmri.Version.name(), (java.util.Date()).toString()))
Expand Down

0 comments on commit ae859bf

Please sign in to comment.