-#class VideomodeHotplug:
-# def __init__(self, hw):
-# self.hw = hw
-# self.hw.on_hotplug.append(self.hotplug)
-#
-# def hotplug(self, what):
-# print "hotplug detected on port '%s'" % (what)
-# ...
-#
-#hotplug = None
-#
-#def startHotplug(self):
-# global hotplug
-# hotplug = VideomodeHotplug()
-# hotplug.start()
-#
-#def stopHotplug(self):
-# global hotplug
-# hotplug.stop()
-#
-#
-#def autostart(reason, session = None, **kwargs):
-# if session is not None:
-# global my_global_session
-# my_global_session = session
-# return
-#
-# if reason == 0:
-# startHotplug()
-# elif reason == 1:
-# stopHotplug()
+class VideomodeHotplug:
+ def __init__(self, hw):
+ self.hw = hw
+
+ def start(self):
+ self.hw.on_hotplug.append(self.hotplug)
+
+ def stop(self):
+ self.hw.on_hotplug.remove(self.hotplug)
+
+ def hotplug(self, what):
+ print "hotplug detected on port '%s'" % (what)
+ port = config.av.videoport.value
+ mode = config.av.videomode[port].value
+ rate = config.av.videorate[mode].value
+
+ if not self.hw.isModeAvailable(port, mode, rate):
+ print "mode %s/%s/%s went away!" % (port, mode, rate)
+ modelist = self.hw.getModeList(port)
+ if not len(modelist):
+ print "sorry, no other mode is available (unplug?). Doing nothing."
+ return
+ mode = modelist[0][0]
+ rate = modelist[0][1]
+ print "setting %s/%s/%s" % (port, mode, rate)
+ self.hw.setMode(port, mode, rate)
+
+hotplug = None
+
+def startHotplug():
+ global hotplug, video_hw
+ hotplug = VideomodeHotplug(video_hw)
+ hotplug.start()
+
+def stopHotplug():
+ global hotplug
+ hotplug.stop()
+
+
+def autostart(reason, session = None, **kwargs):
+ if session is not None:
+ global my_global_session
+ my_global_session = session
+ return
+
+ if reason == 0:
+ startHotplug()
+ elif reason == 1:
+ stopHotplug()