chiark / gitweb /
c377627520e410d4bdf614be3146f6c67ded81c6
[cura.git] / Cura / util / printerConnection / printerConnectionManager.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 from Cura.util import version
4 from Cura.util.printerConnection import dummyConnection
5 from Cura.util.printerConnection import doodle3dConnect
6
7 class connectionEntry(object):
8         def __init__(self, name, priority, icon, connection):
9                 self.name = name
10                 self.priority = priority
11                 self.icon = icon
12                 self.connection = connection
13                 self.window = None
14
15         def __cmp__(self, other):
16                 return self.priority - other.priority
17
18         def __repr__(self):
19                 return self.name
20
21 class PrinterConnectionManager(object):
22         def __init__(self):
23                 self._connectionList = []
24                 if version.isDevVersion():
25                         self._connectionList.append(connectionEntry('Dummy', -1, 5, dummyConnection.dummyConnection()))
26                 self._connectionList.append(connectionEntry('Doodle3D', 100, 27, doodle3dConnect.doodle3dConnect()))
27
28                 #Sort the connections by highest priority first.
29                 self._connectionList.sort(reverse=True)
30
31         #Return the highest priority available connection.
32         def getAvailableConnection(self):
33                 for e in self._connectionList:
34                         if e.connection.isAvailable():
35                                 return e
36                 return None