CuraEngineBackend.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from UM.Backend.Backend import Backend, BackendState
  4. from UM.Application import Application
  5. from UM.Scene.SceneNode import SceneNode
  6. from UM.Preferences import Preferences
  7. from UM.Signal import Signal
  8. from UM.Logger import Logger
  9. from UM.Message import Message
  10. from UM.PluginRegistry import PluginRegistry
  11. from UM.Resources import Resources
  12. from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then.
  13. from UM.Platform import Platform
  14. from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
  15. from cura.Settings.ExtruderManager import ExtruderManager
  16. from . import ProcessSlicedLayersJob
  17. from . import StartSliceJob
  18. import os
  19. import sys
  20. from time import time
  21. from PyQt5.QtCore import QTimer
  22. import Arcus
  23. from UM.i18n import i18nCatalog
  24. catalog = i18nCatalog("cura")
  25. class CuraEngineBackend(Backend):
  26. ## Starts the back-end plug-in.
  27. #
  28. # This registers all the signal listeners and prepares for communication
  29. # with the back-end in general.
  30. def __init__(self):
  31. super().__init__()
  32. # Find out where the engine is located, and how it is called.
  33. # This depends on how Cura is packaged and which OS we are running on.
  34. executable_name = "CuraEngine"
  35. if Platform.isWindows():
  36. executable_name += ".exe"
  37. default_engine_location = executable_name
  38. if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", executable_name)):
  39. default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", executable_name)
  40. if hasattr(sys, "frozen"):
  41. default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), executable_name)
  42. if Platform.isLinux() and not default_engine_location:
  43. if not os.getenv("PATH"):
  44. raise OSError("There is something wrong with your Linux installation.")
  45. for pathdir in os.getenv("PATH").split(os.pathsep):
  46. execpath = os.path.join(pathdir, executable_name)
  47. if os.path.exists(execpath):
  48. default_engine_location = execpath
  49. break
  50. if not default_engine_location:
  51. raise EnvironmentError("Could not find CuraEngine")
  52. Logger.log("i", "Found CuraEngine at: %s" %(default_engine_location))
  53. default_engine_location = os.path.abspath(default_engine_location)
  54. Preferences.getInstance().addPreference("backend/location", default_engine_location)
  55. # Workaround to disable layer view processing if layer view is not active.
  56. self._layer_view_active = False
  57. Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
  58. self._onActiveViewChanged()
  59. self._stored_layer_data = []
  60. self._stored_optimized_layer_data = []
  61. self._scene = Application.getInstance().getController().getScene()
  62. self._scene.sceneChanged.connect(self._onSceneChanged)
  63. # Triggers for when to (re)start slicing:
  64. self._global_container_stack = None
  65. Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged)
  66. self._onGlobalStackChanged()
  67. self._active_extruder_stack = None
  68. ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderChanged)
  69. self._onActiveExtruderChanged()
  70. # Listeners for receiving messages from the back-end.
  71. self._message_handlers["cura.proto.Layer"] = self._onLayerMessage
  72. self._message_handlers["cura.proto.LayerOptimized"] = self._onOptimizedLayerMessage
  73. self._message_handlers["cura.proto.Progress"] = self._onProgressMessage
  74. self._message_handlers["cura.proto.GCodeLayer"] = self._onGCodeLayerMessage
  75. self._message_handlers["cura.proto.GCodePrefix"] = self._onGCodePrefixMessage
  76. self._message_handlers["cura.proto.PrintTimeMaterialEstimates"] = self._onPrintTimeMaterialEstimates
  77. self._message_handlers["cura.proto.SlicingFinished"] = self._onSlicingFinishedMessage
  78. self._start_slice_job = None
  79. self._slicing = False # Are we currently slicing?
  80. self._restart = False # Back-end is currently restarting?
  81. self._tool_active = False # If a tool is active, some tasks do not have to do anything
  82. self._always_restart = True # Always restart the engine when starting a new slice. Don't keep the process running. TODO: Fix engine statelessness.
  83. self._process_layers_job = None # The currently active job to process layers, or None if it is not processing layers.
  84. self._need_slicing = False
  85. self._backend_log_max_lines = 20000 # Maximum number of lines to buffer
  86. self._error_message = None # Pop-up message that shows errors.
  87. self.backendQuit.connect(self._onBackendQuit)
  88. self.backendConnected.connect(self._onBackendConnected)
  89. # When a tool operation is in progress, don't slice. So we need to listen for tool operations.
  90. Application.getInstance().getController().toolOperationStarted.connect(self._onToolOperationStarted)
  91. Application.getInstance().getController().toolOperationStopped.connect(self._onToolOperationStopped)
  92. self._slice_start_time = None
  93. Preferences.getInstance().addPreference("general/auto_slice", True)
  94. self._use_timer = False
  95. self._change_timer = None
  96. self.determineAutoSlicing()
  97. Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
  98. ## Terminate the engine process.
  99. #
  100. # This function should terminate the engine process.
  101. # Called when closing the application.
  102. def close(self):
  103. # Terminate CuraEngine if it is still running at this point
  104. self._terminate()
  105. ## Get the command that is used to call the engine.
  106. # This is useful for debugging and used to actually start the engine.
  107. # \return list of commands and args / parameters.
  108. def getEngineCommand(self):
  109. json_path = Resources.getPath(Resources.DefinitionContainers, "fdmprinter.def.json")
  110. return [Preferences.getInstance().getValue("backend/location"), "connect", "127.0.0.1:{0}".format(self._port), "-j", json_path, ""]
  111. ## Emitted when we get a message containing print duration and material amount.
  112. # This also implies the slicing has finished.
  113. # \param time The amount of time the print will take.
  114. # \param material_amount The amount of material the print will use.
  115. printDurationMessage = Signal()
  116. ## Emitted when the slicing process starts.
  117. slicingStarted = Signal()
  118. ## Emitted when the slicing process is aborted forcefully.
  119. slicingCancelled = Signal()
  120. def stopSlicing(self):
  121. self.backendStateChange.emit(BackendState.NotStarted)
  122. if self._slicing: # We were already slicing. Stop the old job.
  123. self._terminate()
  124. self._createSocket()
  125. if self._process_layers_job: # We were processing layers. Stop that, the layers are going to change soon.
  126. self._process_layers_job.abort()
  127. self._process_layers_job = None
  128. if self._error_message:
  129. self._error_message.hide()
  130. ## Perform a slice of the scene.
  131. def slice(self):
  132. Logger.log("d", "Starting slice job...")
  133. self._slice_start_time = time()
  134. if not self._need_slicing:
  135. Logger.log("w", "Do not need to slice, optimizable or programming error.")
  136. return
  137. self.printDurationMessage.emit(0, [0])
  138. self._stored_layer_data = []
  139. self._stored_optimized_layer_data = []
  140. if self._process is None:
  141. Logger.log("d", "Creating socket and start the engine...")
  142. self._createSocket()
  143. self.stopSlicing()
  144. self.processingProgress.emit(0.0)
  145. self.backendStateChange.emit(BackendState.NotStarted)
  146. self._scene.gcode_list = []
  147. self._slicing = True
  148. self.slicingStarted.emit()
  149. slice_message = self._socket.createMessage("cura.proto.Slice")
  150. Logger.log("d", "Really starting slice job")
  151. self._start_slice_job = StartSliceJob.StartSliceJob(slice_message)
  152. self._start_slice_job.start()
  153. self._start_slice_job.finished.connect(self._onStartSliceCompleted)
  154. ## Terminate the engine process.
  155. # Start the engine process by calling _createSocket()
  156. def _terminate(self):
  157. self._slicing = False
  158. self._stored_layer_data = []
  159. self._stored_optimized_layer_data = []
  160. if self._start_slice_job is not None:
  161. self._start_slice_job.cancel()
  162. self.slicingCancelled.emit()
  163. self.processingProgress.emit(0)
  164. Logger.log("d", "Attempting to kill the engine process")
  165. if Application.getInstance().getCommandLineOption("external-backend", False):
  166. return
  167. if self._process is not None:
  168. Logger.log("d", "Killing engine process")
  169. try:
  170. self._process.terminate()
  171. Logger.log("d", "Engine process is killed. Received return code %s", self._process.wait())
  172. self._process = None
  173. except Exception as e: # terminating a process that is already terminating causes an exception, silently ignore this.
  174. Logger.log("d", "Exception occurred while trying to kill the engine %s", str(e))
  175. ## Event handler to call when the job to initiate the slicing process is
  176. # completed.
  177. #
  178. # When the start slice job is successfully completed, it will be happily
  179. # slicing. This function handles any errors that may occur during the
  180. # bootstrapping of a slice job.
  181. #
  182. # \param job The start slice job that was just finished.
  183. def _onStartSliceCompleted(self, job):
  184. if self._error_message:
  185. self._error_message.hide()
  186. # Note that cancelled slice jobs can still call this method.
  187. if self._start_slice_job is job:
  188. self._start_slice_job = None
  189. if job.isCancelled() or job.getError() or job.getResult() == StartSliceJob.StartJobResult.Error:
  190. return
  191. if job.getResult() == StartSliceJob.StartJobResult.MaterialIncompatible:
  192. if Application.getInstance().getPlatformActivity:
  193. self._error_message = Message(catalog.i18nc("@info:status",
  194. "The selected material is incompatible with the selected machine or configuration."))
  195. self._error_message.show()
  196. self.backendStateChange.emit(BackendState.Error)
  197. else:
  198. self.backendStateChange.emit(BackendState.NotStarted)
  199. return
  200. if job.getResult() == StartSliceJob.StartJobResult.SettingError:
  201. if Application.getInstance().getPlatformActivity:
  202. extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  203. error_keys = []
  204. for extruder in extruders:
  205. error_keys.extend(extruder.getErrorKeys())
  206. if not extruders:
  207. error_keys = self._global_container_stack.getErrorKeys()
  208. error_labels = set()
  209. definition_container = self._global_container_stack.getBottom()
  210. for key in error_keys:
  211. error_labels.add(definition_container.findDefinitions(key = key)[0].label)
  212. error_labels = ", ".join(error_labels)
  213. self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice with the current settings. The following settings have errors: {0}".format(error_labels)))
  214. self._error_message.show()
  215. self.backendStateChange.emit(BackendState.Error)
  216. else:
  217. self.backendStateChange.emit(BackendState.NotStarted)
  218. return
  219. if job.getResult() == StartSliceJob.StartJobResult.BuildPlateError:
  220. if Application.getInstance().getPlatformActivity:
  221. self._error_message = Message(catalog.i18nc("@info:status", "Unable to slice because the prime tower or prime position(s) are invalid."))
  222. self._error_message.show()
  223. self.backendStateChange.emit(BackendState.Error)
  224. else:
  225. self.backendStateChange.emit(BackendState.NotStarted)
  226. if job.getResult() == StartSliceJob.StartJobResult.NothingToSlice:
  227. if Application.getInstance().getPlatformActivity:
  228. self._error_message = Message(catalog.i18nc("@info:status", "Nothing to slice because none of the models fit the build volume. Please scale or rotate models to fit."))
  229. self._error_message.show()
  230. self.backendStateChange.emit(BackendState.Error)
  231. else:
  232. self.backendStateChange.emit(BackendState.NotStarted)
  233. return
  234. # Preparation completed, send it to the backend.
  235. self._socket.sendMessage(job.getSliceMessage())
  236. # Notify the user that it's now up to the backend to do it's job
  237. self.backendStateChange.emit(BackendState.Processing)
  238. Logger.log("d", "Sending slice message took %s seconds", time() - self._slice_start_time )
  239. ## Determine enable or disable auto slicing. Return True for enable timer and False otherwise.
  240. # It disables when
  241. # - preference auto slice is off
  242. # - decorator isBlockSlicing is found (used in g-code reader)
  243. def determineAutoSlicing(self):
  244. enable_timer = True
  245. if not Preferences.getInstance().getValue("general/auto_slice"):
  246. enable_timer = False
  247. for node in DepthFirstIterator(self._scene.getRoot()):
  248. if node.callDecoration("isBlockSlicing"):
  249. enable_timer = False
  250. self.backendStateChange.emit(BackendState.Disabled)
  251. gcode_list = node.callDecoration("getGCodeList")
  252. if gcode_list is not None:
  253. self._scene.gcode_list = gcode_list
  254. if self._use_timer == enable_timer:
  255. return
  256. if enable_timer:
  257. self.backendStateChange.emit(BackendState.NotStarted)
  258. self.enableTimer()
  259. return True
  260. else:
  261. self.disableTimer()
  262. return False
  263. ## Listener for when the scene has changed.
  264. #
  265. # This should start a slice if the scene is now ready to slice.
  266. #
  267. # \param source The scene node that was changed.
  268. def _onSceneChanged(self, source):
  269. if self._tool_active:
  270. return
  271. if type(source) is not SceneNode:
  272. return
  273. if source is self._scene.getRoot():
  274. return
  275. self.determineAutoSlicing()
  276. if source.getMeshData() is None:
  277. return
  278. if source.getMeshData().getVertices() is None:
  279. return
  280. self.needSlicing()
  281. self.stopSlicing()
  282. self._onChanged()
  283. ## Called when an error occurs in the socket connection towards the engine.
  284. #
  285. # \param error The exception that occurred.
  286. def _onSocketError(self, error):
  287. if Application.getInstance().isShuttingDown():
  288. return
  289. super()._onSocketError(error)
  290. if error.getErrorCode() == Arcus.ErrorCode.Debug:
  291. return
  292. self._terminate()
  293. self._createSocket()
  294. if error.getErrorCode() not in [Arcus.ErrorCode.BindFailedError, Arcus.ErrorCode.ConnectionResetError, Arcus.ErrorCode.Debug]:
  295. Logger.log("w", "A socket error caused the connection to be reset")
  296. ## Remove old layer data (if any)
  297. ## TODO: now copied from ProcessSlicedLayersJob. Find my a home.
  298. def _clearLayerData(self):
  299. for node in DepthFirstIterator(self._scene.getRoot()):
  300. if node.callDecoration("getLayerData"):
  301. node.getParent().removeChild(node)
  302. break
  303. ## Convenient function: set need_slicing, emit state and clear layer data
  304. def needSlicing(self):
  305. self._need_slicing = True # For now only for debugging purposes
  306. self.processingProgress.emit(0.0)
  307. self.backendStateChange.emit(BackendState.NotStarted)
  308. if not self._use_timer:
  309. # With manually having to slice, we want to clear the old invalid layer data.
  310. self._clearLayerData()
  311. ## A setting has changed, so check if we must reslice.
  312. #
  313. # \param instance The setting instance that has changed.
  314. # \param property The property of the setting instance that has changed.
  315. def _onSettingChanged(self, instance, property):
  316. if property == "value": # Only reslice if the value has changed.
  317. self.needSlicing()
  318. self._onChanged()
  319. ## Called when a sliced layer data message is received from the engine.
  320. #
  321. # \param message The protobuf message containing sliced layer data.
  322. def _onLayerMessage(self, message):
  323. self._stored_layer_data.append(message)
  324. ## Called when an optimized sliced layer data message is received from the engine.
  325. #
  326. # \param message The protobuf message containing sliced layer data.
  327. def _onOptimizedLayerMessage(self, message):
  328. self._stored_optimized_layer_data.append(message)
  329. ## Called when a progress message is received from the engine.
  330. #
  331. # \param message The protobuf message containing the slicing progress.
  332. def _onProgressMessage(self, message):
  333. self.processingProgress.emit(message.amount)
  334. self.backendStateChange.emit(BackendState.Processing)
  335. ## Called when the engine sends a message that slicing is finished.
  336. #
  337. # \param message The protobuf message signalling that slicing is finished.
  338. def _onSlicingFinishedMessage(self, message):
  339. self.backendStateChange.emit(BackendState.Done)
  340. self.processingProgress.emit(1.0)
  341. self._slicing = False
  342. self._need_slicing = False
  343. Logger.log("d", "Slicing took %s seconds", time() - self._slice_start_time )
  344. if self._layer_view_active and (self._process_layers_job is None or not self._process_layers_job.isRunning()):
  345. self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_optimized_layer_data)
  346. self._process_layers_job.finished.connect(self._onProcessLayersFinished)
  347. self._process_layers_job.start()
  348. self._stored_optimized_layer_data = []
  349. ## Called when a g-code message is received from the engine.
  350. #
  351. # \param message The protobuf message containing g-code, encoded as UTF-8.
  352. def _onGCodeLayerMessage(self, message):
  353. self._scene.gcode_list.append(message.data.decode("utf-8", "replace"))
  354. ## Called when a g-code prefix message is received from the engine.
  355. #
  356. # \param message The protobuf message containing the g-code prefix,
  357. # encoded as UTF-8.
  358. def _onGCodePrefixMessage(self, message):
  359. self._scene.gcode_list.insert(0, message.data.decode("utf-8", "replace"))
  360. ## Called when a print time message is received from the engine.
  361. #
  362. # \param message The protobuff message containing the print time and
  363. # material amount per extruder
  364. def _onPrintTimeMaterialEstimates(self, message):
  365. material_amounts = []
  366. for index in range(message.repeatedMessageCount("materialEstimates")):
  367. material_amounts.append(message.getRepeatedMessage("materialEstimates", index).material_amount)
  368. self.printDurationMessage.emit(message.time, material_amounts)
  369. ## Creates a new socket connection.
  370. def _createSocket(self):
  371. super()._createSocket(os.path.abspath(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "Cura.proto")))
  372. ## Manually triggers a reslice
  373. def forceSlice(self):
  374. if self._use_timer:
  375. self._change_timer.start()
  376. else:
  377. self.slice()
  378. ## Called when anything has changed to the stuff that needs to be sliced.
  379. #
  380. # This indicates that we should probably re-slice soon.
  381. def _onChanged(self, *args, **kwargs):
  382. self.needSlicing()
  383. if self._use_timer:
  384. self._change_timer.start()
  385. ## Called when the back-end connects to the front-end.
  386. def _onBackendConnected(self):
  387. if self._restart:
  388. self._restart = False
  389. self._onChanged()
  390. ## Called when the user starts using some tool.
  391. #
  392. # When the user starts using a tool, we should pause slicing to prevent
  393. # continuously slicing while the user is dragging some tool handle.
  394. #
  395. # \param tool The tool that the user is using.
  396. def _onToolOperationStarted(self, tool):
  397. self._tool_active = True # Do not react on scene change
  398. self.disableTimer()
  399. ## Called when the user stops using some tool.
  400. #
  401. # This indicates that we can safely start slicing again.
  402. #
  403. # \param tool The tool that the user was using.
  404. def _onToolOperationStopped(self, tool):
  405. self._tool_active = False # React on scene change again
  406. self.determineAutoSlicing()
  407. ## Called when the user changes the active view mode.
  408. def _onActiveViewChanged(self):
  409. if Application.getInstance().getController().getActiveView():
  410. view = Application.getInstance().getController().getActiveView()
  411. if view.getPluginId() == "LayerView": # If switching to layer view, we should process the layers if that hasn't been done yet.
  412. self._layer_view_active = True
  413. # There is data and we're not slicing at the moment
  414. # if we are slicing, there is no need to re-calculate the data as it will be invalid in a moment.
  415. if self._stored_optimized_layer_data and not self._slicing:
  416. self._process_layers_job = ProcessSlicedLayersJob.ProcessSlicedLayersJob(self._stored_optimized_layer_data)
  417. self._process_layers_job.finished.connect(self._onProcessLayersFinished)
  418. self._process_layers_job.start()
  419. self._stored_optimized_layer_data = []
  420. else:
  421. self._layer_view_active = False
  422. ## Called when the back-end self-terminates.
  423. #
  424. # We should reset our state and start listening for new connections.
  425. def _onBackendQuit(self):
  426. if not self._restart:
  427. if self._process:
  428. Logger.log("d", "Backend quit with return code %s. Resetting process and socket.", self._process.wait())
  429. self._process = None
  430. ## Called when the global container stack changes
  431. def _onGlobalStackChanged(self):
  432. if self._global_container_stack:
  433. self._global_container_stack.propertyChanged.disconnect(self._onSettingChanged)
  434. self._global_container_stack.containersChanged.disconnect(self._onChanged)
  435. extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  436. if extruders:
  437. for extruder in extruders:
  438. extruder.propertyChanged.disconnect(self._onSettingChanged)
  439. self._global_container_stack = Application.getInstance().getGlobalContainerStack()
  440. if self._global_container_stack:
  441. self._global_container_stack.propertyChanged.connect(self._onSettingChanged) # Note: Only starts slicing when the value changed.
  442. self._global_container_stack.containersChanged.connect(self._onChanged)
  443. extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  444. if extruders:
  445. for extruder in extruders:
  446. extruder.propertyChanged.connect(self._onSettingChanged)
  447. self._onActiveExtruderChanged()
  448. self._onChanged()
  449. def _onActiveExtruderChanged(self):
  450. if self._global_container_stack:
  451. # Connect all extruders of the active machine. This might cause a few connects that have already happend,
  452. # but that shouldn't cause issues as only new / unique connections are added.
  453. extruders = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  454. if extruders:
  455. for extruder in extruders:
  456. extruder.propertyChanged.connect(self._onSettingChanged)
  457. if self._active_extruder_stack:
  458. self._active_extruder_stack.containersChanged.disconnect(self._onChanged)
  459. self._active_extruder_stack = ExtruderManager.getInstance().getActiveExtruderStack()
  460. if self._active_extruder_stack:
  461. self._active_extruder_stack.containersChanged.connect(self._onChanged)
  462. def _onProcessLayersFinished(self, job):
  463. self._process_layers_job = None
  464. def enableTimer(self):
  465. self.disableTimer() # disable any existing timer
  466. self._use_timer = True
  467. # When you update a setting and other settings get changed through inheritance, many propertyChanged signals are fired.
  468. # This timer will group them up, and only slice for the last setting changed signal.
  469. # TODO: Properly group propertyChanged signals by whether they are triggered by the same user interaction.
  470. self._change_timer = QTimer()
  471. self._change_timer.setInterval(500)
  472. self._change_timer.setSingleShot(True)
  473. self._change_timer.timeout.connect(self.slice)
  474. ## Disable timer.
  475. # This means that slicing will not be triggered automatically
  476. def disableTimer(self):
  477. if self._change_timer is not None:
  478. self._change_timer.timeout.disconnect()
  479. self._change_timer = None
  480. self._use_timer = False
  481. def _onPreferencesChanged(self, preference):
  482. if preference != "general/auto_slice":
  483. return
  484. auto_slice = self.determineAutoSlicing()
  485. if auto_slice:
  486. self._change_timer.start()