Changed enum values to lowerCamelCase

CURA-1339
This commit is contained in:
Jaime van Kessel 2016-04-18 14:43:04 +02:00
parent 96e821cc3d
commit fb52d39936
3 changed files with 17 additions and 16 deletions

View file

@ -26,7 +26,7 @@ class PrinterOutputDevice(OutputDevice, QObject):
self._head_x = 0 self._head_x = 0
self._head_y = 0 self._head_y = 0
self._head_z = 0 self._head_z = 0
self._connection_state = ConnectionState.CLOSED self._connection_state = ConnectionState.closed
def requestWrite(self, node, file_name = None, filter_by_machine = False): def requestWrite(self, node, file_name = None, filter_by_machine = False):
raise NotImplementedError("requestWrite needs to be implemented") raise NotImplementedError("requestWrite needs to be implemented")
@ -301,8 +301,9 @@ class PrinterOutputDevice(OutputDevice, QObject):
self._progress = progress self._progress = progress
self.progressChanged.emit() self.progressChanged.emit()
## The current processing state of the backend. ## The current processing state of the backend.
class ConnectionState(IntEnum): class ConnectionState(IntEnum):
CLOSED = 0 closed = 0
CONNECTING = 1 connecting = 1
CONNECTED = 2 connected = 2

View file

@ -134,7 +134,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
## Start a print based on a g-code. ## Start a print based on a g-code.
# \param gcode_list List with gcode (strings). # \param gcode_list List with gcode (strings).
def printGCode(self, gcode_list): def printGCode(self, gcode_list):
if self._progress or self._connection_state != ConnectionState.CONNECTED: if self._progress or self._connection_state != ConnectionState.connected:
Logger.log("d", "Printer is busy or not connected, aborting print") Logger.log("d", "Printer is busy or not connected, aborting print")
self.writeError.emit(self) self.writeError.emit(self)
return return
@ -169,7 +169,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
def _updateFirmware(self): def _updateFirmware(self):
self.setProgress(0, 100) self.setProgress(0, 100)
if self._connection_state != ConnectionState.CLOSED: if self._connection_state != ConnectionState.closed:
self.close() self.close()
hex_file = intelHex.readHex(self._firmware_file_name) hex_file = intelHex.readHex(self._firmware_file_name)
@ -225,14 +225,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._poll_endstop = False self._poll_endstop = False
def _pollEndStop(self): def _pollEndStop(self):
while self._connection_state == ConnectionState.CONNECTED and self._poll_endstop: while self._connection_state == ConnectionState.connected and self._poll_endstop:
self.sendCommand("M119") self.sendCommand("M119")
time.sleep(0.5) time.sleep(0.5)
## Private connect function run by thread. Can be started by calling connect. ## Private connect function run by thread. Can be started by calling connect.
def _connect(self): def _connect(self):
Logger.log("d", "Attempting to connect to %s", self._serial_port) Logger.log("d", "Attempting to connect to %s", self._serial_port)
self.setConnectionState(ConnectionState.CONNECTING) self.setConnectionState(ConnectionState.connecting)
programmer = stk500v2.Stk500v2() programmer = stk500v2.Stk500v2()
try: try:
programmer.connect(self._serial_port) # Connect with the serial, if this succeeds, it's an arduino based usb device. programmer.connect(self._serial_port) # Connect with the serial, if this succeeds, it's an arduino based usb device.
@ -265,7 +265,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
line = self._readline() line = self._readline()
if line is None: if line is None:
# Something went wrong with reading, could be that close was called. # Something went wrong with reading, could be that close was called.
self.setConnectionState(ConnectionState.CLOSED) self.setConnectionState(ConnectionState.closed)
return return
if b"T:" in line: if b"T:" in line:
@ -273,7 +273,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
sucesfull_responses += 1 sucesfull_responses += 1
if sucesfull_responses >= self._required_responses_auto_baud: if sucesfull_responses >= self._required_responses_auto_baud:
self._serial.timeout = 2 # Reset serial timeout self._serial.timeout = 2 # Reset serial timeout
self.setConnectionState(ConnectionState.CONNECTED) self.setConnectionState(ConnectionState.connected)
self._listen_thread.start() # Start listening self._listen_thread.start() # Start listening
Logger.log("i", "Established printer connection on port %s" % self._serial_port) Logger.log("i", "Established printer connection on port %s" % self._serial_port)
return return
@ -282,7 +282,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
Logger.log("e", "Baud rate detection for %s failed", self._serial_port) Logger.log("e", "Baud rate detection for %s failed", self._serial_port)
self.close() # Unable to connect, wrap up. self.close() # Unable to connect, wrap up.
self.setConnectionState(ConnectionState.CLOSED) self.setConnectionState(ConnectionState.closed)
## Set the baud rate of the serial. This can cause exceptions, but we simply want to ignore those. ## Set the baud rate of the serial. This can cause exceptions, but we simply want to ignore those.
def setBaudRate(self, baud_rate): def setBaudRate(self, baud_rate):
@ -305,7 +305,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._connect_thread = threading.Thread(target = self._connect) self._connect_thread = threading.Thread(target = self._connect)
self._connect_thread.daemon = True self._connect_thread.daemon = True
self.setConnectionState(ConnectionState.CLOSED) self.setConnectionState(ConnectionState.closed)
if self._serial is not None: if self._serial is not None:
try: try:
self._listen_thread.join() self._listen_thread.join()
@ -365,7 +365,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
def sendCommand(self, cmd): def sendCommand(self, cmd):
if self._progress: if self._progress:
self._command_queue.put(cmd) self._command_queue.put(cmd)
elif self._connection_state == ConnectionState.CONNECTED: elif self._connection_state == ConnectionState.connected:
self._sendCommand(cmd) self._sendCommand(cmd)
## Set the error state with a message. ## Set the error state with a message.
@ -396,7 +396,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port) Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port)
temperature_request_timeout = time.time() temperature_request_timeout = time.time()
ok_timeout = time.time() ok_timeout = time.time()
while self._connection_state == ConnectionState.CONNECTED: while self._connection_state == ConnectionState.connected:
line = self._readline() line = self._readline()
if line is None: if line is None:
break # None is only returned when something went wrong. Stop listening break # None is only returned when something went wrong. Stop listening

View file

@ -201,7 +201,7 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin,
## If one of the states of the connected devices change, we might need to add / remove them from the global list. ## If one of the states of the connected devices change, we might need to add / remove them from the global list.
def _onConnectionStateChanged(self, serial_port): def _onConnectionStateChanged(self, serial_port):
try: try:
if self._usb_output_devices[serial_port].connectionState == ConnectionState.CONNECTED: if self._usb_output_devices[serial_port].connectionState == ConnectionState.connected:
self.getOutputDeviceManager().addOutputDevice(self._usb_output_devices[serial_port]) self.getOutputDeviceManager().addOutputDevice(self._usb_output_devices[serial_port])
else: else:
self.getOutputDeviceManager().removeOutputDevice(serial_port) self.getOutputDeviceManager().removeOutputDevice(serial_port)
@ -216,7 +216,7 @@ class USBPrinterOutputDeviceManager(QObject, SignalEmitter, OutputDevicePlugin,
self._usb_output_devices_model.addRoleName(Qt.UserRole + 1, "name") self._usb_output_devices_model.addRoleName(Qt.UserRole + 1, "name")
self._usb_output_devices_model.addRoleName(Qt.UserRole + 2, "printer") self._usb_output_devices_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._usb_output_devices: for connection in self._usb_output_devices:
if self._usb_output_devices[connection].connectionState == ConnectionState.CONNECTED: if self._usb_output_devices[connection].connectionState == ConnectionState.connected:
self._usb_output_devices_model.appendItem({"name": connection, "printer": self._usb_output_devices[connection]}) self._usb_output_devices_model.appendItem({"name": connection, "printer": self._usb_output_devices[connection]})
return self._usb_output_devices_model return self._usb_output_devices_model