"""
Utility functions/classes for dealing with marquee screen
saver.
"""
import registry
import UserList
import string
__rootKeyName = registry.keyNameMake(('HKEY_CURRENT_USER',
'Control Panel'))
__marqueeRootKeyName = registry.keyNameMake((__rootKeyName,
'Screen Saver.Marquee'))
CurrentValueName = 'Text'
__registry = registry.Registry()
rkCurrentValue = __registry.openKey(__marqueeRootKeyName, registry.KeyAll)
def Enable():
"""
Turn on the Marquee screen saver.
"""
key = __registry.openKey(registry.keyNameMake(('HKEY_CURRENT_USER',
'Control Panel',
'Desktop',
))
)
key.valueSet('C:\\WINNT\\System32\\ssmarque.scr', 'SCRNSAVE.EXE')
key.valueSet('1', 'ScreenSaveActive')
class SavedMarqueeMessages(UserList.UserList):
savedMessagesKeyName = registry.keyNameMake(('HKEY_CURRENT_USER',
'Control Panel',
'Screen Saver.Marquee'))
savedMessagesValueName = 'QuickMarquee'
def __init__(self):
UserList.UserList.__init__(self)
self.__registry = registry.Registry()
self.rkOtherValues = self.__registry.openKey(self.savedMessagesKeyName)
valueLines = self.rkOtherValues.valueQuery(self.savedMessagesValueName)[0]
if valueLines:
self.data = self.data + string.split(valueLines, '\n')
currentVal = rkCurrentValue.valueQuery(CurrentValueName)[0]
self.append(currentVal)
def store(self):
"""
Store our current value in the registry.
"""
storeVal = string.join(self, '\n')
self.rkOtherValues.valueSet(storeVal, self.savedMessagesValueName)
def append(self, newvalue):
"""
Append only if the value isn't already here.
"""
if newvalue not in self.data:
UserList.UserList.append(self, newvalue)
self.sort()
if __name__ == '__main__':
print 'Current value of message: "%s"' % \
rkCurrentValue.valueQuery(CurrentValueName)[0]
print 'Other values available: '
for msg in SavedMarqueeMessages(__registry):
print '\t%s' % msg
|