chiark / gitweb /
RC1
[cura.git] / Cura / util / printerConnection / printerConnectionManager.py
1 """
2 The printer connection manager keeps track of all the possible printer connections that can be made.
3 It sorts them by priority and gives easy access to the first available connection type.
4
5 This is used by the print/save button to give access to the first available print connection.
6 As well as listing all printers under the right mouse button.
7 """
8 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
9
10 from Cura.util import profile
11 from Cura.util import version
12 from Cura.util.printerConnection import dummyConnection
13 from Cura.util.printerConnection import serialConnection
14 from Cura.util.printerConnection import doodle3dConnect
15
16 class PrinterConnectionManager(object):
17         """
18         The printer connection manager has one of each printer connection groups. Sorted on priority.
19         It can retrieve the first available connection as well as all available connections.
20         """
21         def __init__(self):
22                 self._groupList = []
23                 if version.isDevVersion():
24                         self._groupList.append(dummyConnection.dummyConnectionGroup())
25                 self._groupList.append(serialConnection.serialConnectionGroup())
26                 self._groupList.append(doodle3dConnect.doodle3dConnectionGroup())
27
28                 #Sort the connections by highest priority first.
29                 self._groupList.sort(reverse=True)
30
31         #Return the highest priority available connection.
32         def getAvailableGroup(self):
33                 if profile.getMachineSetting('gcode_flavor') == 'UltiGCode':
34                         return None
35                 for g in self._groupList:
36                         if len(g.getAvailableConnections()) > 0:
37                                 return g
38                 return None
39
40         #Return all available connections.
41         def getAvailableConnections(self):
42                 ret = []
43                 for e in self._groupList:
44                         ret += e.getAvailableConnections()
45                 return ret