本文整理汇总了Python中UM.Qt.ListModel.ListModel.appendItem方法的典型用法代码示例。如果您正苦于以下问题:Python ListModel.appendItem方法的具体用法?Python ListModel.appendItem怎么用?Python ListModel.appendItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Qt.ListModel.ListModel
的用法示例。
在下文中一共展示了ListModel.appendItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createActionsModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
def createActionsModel(self, options):
model = ListModel()
model.addRoleName(self.NameRole,"text")
for option in options:
model.appendItem({"text": str(option)})
if len(options) != 0:
return model
return None
示例2: _createPagesModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
def _createPagesModel(self, steps):
model = ListModel()
model.addRoleName(self.NameRole,"page")
model.addRoleName(self.NameRole,"title")
for step in steps:
_page = step.get("page")
_title = step.get("title")
model.appendItem({"title": str(_title), "page": str(_page)})
return model
示例3: createOptionsModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
def createOptionsModel(self, options):
if not options:
return None
model = ListModel()
model.addRoleName(Qt.UserRole + 1, "value")
model.addRoleName(Qt.UserRole + 2, "name")
for value, name in options.items():
model.appendItem({"value": str(value), "name": str(name)})
return model
示例4: createActionsModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
def createActionsModel(self, actions):
model = ListModel()
model.addRoleName(self.IDRole, "action_id")
model.addRoleName(self.TextRole,"name")
model.addRoleName(self.IconRole, "icon")
model.addRoleName(self.DescriptionRole, "description")
for action in actions:
model.appendItem(action)
return model
示例5: createOptionsModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
def createOptionsModel(self, options):
model = ListModel()
model.addRoleName(self.NameRole,"text")
for option in options:
model.appendItem({"text": str(option)})
return model
示例6: USBPrinterOutputDeviceManager
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
#.........这里部分代码省略.........
"ultimaker_original_plus" : "MarlinUltimaker-UMOP-{baudrate}.hex",
"ultimaker2" : "MarlinUltimaker2.hex",
"ultimaker2_go" : "MarlinUltimaker2go.hex",
"ultimaker2plus" : "MarlinUltimaker2plus.hex",
"ultimaker2_extended" : "MarlinUltimaker2extended.hex",
"ultimaker2_extended_plus" : "MarlinUltimaker2extended-plus.hex",
}
machine_with_heated_bed = {"ultimaker_original" : "MarlinUltimaker-HBK-{baudrate}.hex",
}
##TODO: Add check for multiple extruders
hex_file = None
if machine_id in machine_without_extras.keys(): # The machine needs to be defined here!
if machine_id in machine_with_heated_bed.keys() and machine_has_heated_bed:
Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_id)
hex_file = machine_with_heated_bed[machine_id] # Return firmware with heated bed enabled
else:
Logger.log("d", "Choosing basic firmware for machine %s.", machine_id)
hex_file = machine_without_extras[machine_id] # Return "basic" firmware
else:
Logger.log("e", "There is no firmware for machine %s.", machine_id)
if hex_file:
return hex_file.format(baudrate=baudrate)
else:
Logger.log("e", "Could not find any firmware for machine %s.", machine_id)
raise FileNotFoundError()
## Helper to identify serial ports (and scan for them)
def _addRemovePorts(self, serial_ports):
# First, find and add all new or changed keys
for serial_port in list(serial_ports):
if serial_port not in self._serial_port_list:
self.addUSBOutputDeviceSignal.emit(serial_port) # Hack to ensure its created in main thread
continue
self._serial_port_list = list(serial_ports)
devices_to_remove = []
for port, device in self._usb_output_devices.items():
if port not in self._serial_port_list:
device.close()
devices_to_remove.append(port)
for port in devices_to_remove:
del self._usb_output_devices[port]
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
def addOutputDevice(self, serial_port):
device = USBPrinterOutputDevice.USBPrinterOutputDevice(serial_port)
device.connectionStateChanged.connect(self._onConnectionStateChanged)
device.connect()
device.progressChanged.connect(self.progressChanged)
self._usb_output_devices[serial_port] = device
## 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):
try:
if self._usb_output_devices[serial_port].connectionState == ConnectionState.connected:
self.getOutputDeviceManager().addOutputDevice(self._usb_output_devices[serial_port])
else:
self.getOutputDeviceManager().removeOutputDevice(serial_port)
self.connectionStateChanged.emit()
except KeyError:
pass # no output device by this device_id found in connection list.
@pyqtProperty(QObject , notify = connectionStateChanged)
def connectedPrinterList(self):
self._usb_output_devices_model = ListModel()
self._usb_output_devices_model.addRoleName(Qt.UserRole + 1, "name")
self._usb_output_devices_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._usb_output_devices:
if self._usb_output_devices[connection].connectionState == ConnectionState.connected:
self._usb_output_devices_model.appendItem({"name": connection, "printer": self._usb_output_devices[connection]})
return self._usb_output_devices_model
## Create a list of serial ports on the system.
# \param only_list_usb If true, only usb ports are listed
def getSerialPortList(self, only_list_usb = False):
base_list = []
if platform.system() == "Windows":
import winreg #@UnresolvedImport
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i = 0
while True:
values = winreg.EnumValue(key, i)
if not only_list_usb or "USBSER" in values[0]:
base_list += [values[1]]
i += 1
except Exception as e:
pass
else:
if only_list_usb:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*")
base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list
else:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*")
return list(base_list)
_instance = None
示例7: USBPrinterOutputDeviceManager
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
#.........这里部分代码省略.........
# NOTE: The keyword used here is the id of the machine. You can find the id of your machine in the *.json file, eg.
# https://github.com/Ultimaker/Cura/blob/master/resources/machines/ultimaker_original.json#L2
# The *.hex files are stored at a seperate repository:
# https://github.com/Ultimaker/cura-binary-data/tree/master/cura/resources/firmware
machine_without_extras = {"bq_witbox" : "MarlinWitbox.hex",
"bq_hephestos_2" : "MarlinHephestos2.hex",
"ultimaker_original" : "MarlinUltimaker-{baudrate}.hex",
"ultimaker_original_plus" : "MarlinUltimaker-UMOP-{baudrate}.hex",
"ultimaker_original_dual" : "MarlinUltimaker-{baudrate}-dual.hex",
"ultimaker2" : "MarlinUltimaker2.hex",
"ultimaker2_go" : "MarlinUltimaker2go.hex",
"ultimaker2_plus" : "MarlinUltimaker2plus.hex",
"ultimaker2_extended" : "MarlinUltimaker2extended.hex",
"ultimaker2_extended_plus" : "MarlinUltimaker2extended-plus.hex",
}
machine_with_heated_bed = {"ultimaker_original" : "MarlinUltimaker-HBK-{baudrate}.hex",
"ultimaker_original_dual" : "MarlinUltimaker-HBK-{baudrate}-dual.hex",
}
##TODO: Add check for multiple extruders
hex_file = None
if machine_id in machine_without_extras.keys(): # The machine needs to be defined here!
if machine_id in machine_with_heated_bed.keys() and machine_has_heated_bed:
Logger.log("d", "Choosing firmware with heated bed enabled for machine %s.", machine_id)
hex_file = machine_with_heated_bed[machine_id] # Return firmware with heated bed enabled
else:
Logger.log("d", "Choosing basic firmware for machine %s.", machine_id)
hex_file = machine_without_extras[machine_id] # Return "basic" firmware
else:
Logger.log("w", "There is no firmware for machine %s.", machine_id)
if hex_file:
return Resources.getPath(CuraApplication.ResourceTypes.Firmware, hex_file.format(baudrate=baudrate))
else:
Logger.log("w", "Could not find any firmware for machine %s.", machine_id)
return ""
## Helper to identify serial ports (and scan for them)
def _addRemovePorts(self, serial_ports):
# First, find and add all new or changed keys
for serial_port in list(serial_ports):
if serial_port not in self._serial_port_list:
self.addUSBOutputDeviceSignal.emit(serial_port) # Hack to ensure its created in main thread
continue
self._serial_port_list = list(serial_ports)
devices_to_remove = []
for port, device in self._usb_output_devices.items():
if port not in self._serial_port_list:
device.close()
devices_to_remove.append(port)
for port in devices_to_remove:
del self._usb_output_devices[port]
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
def addOutputDevice(self, serial_port):
device = USBPrinterOutputDevice.USBPrinterOutputDevice(serial_port)
device.connectionStateChanged.connect(self._onConnectionStateChanged)
device.connect()
device.progressChanged.connect(self.progressChanged)
device.firmwareUpdateChange.connect(self.firmwareUpdateChange)
self._usb_output_devices[serial_port] = device
## 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):
success = True
try:
if self._usb_output_devices[serial_port].connectionState == ConnectionState.connected:
self.getOutputDeviceManager().addOutputDevice(self._usb_output_devices[serial_port])
else:
success = success and self.getOutputDeviceManager().removeOutputDevice(serial_port)
if success:
self.connectionStateChanged.emit()
except KeyError:
Logger.log("w", "Connection state of %s changed, but it was not found in the list")
@pyqtProperty(QObject , notify = connectionStateChanged)
def connectedPrinterList(self):
self._usb_output_devices_model = ListModel()
self._usb_output_devices_model.addRoleName(Qt.UserRole + 1, "name")
self._usb_output_devices_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._usb_output_devices:
if self._usb_output_devices[connection].connectionState == ConnectionState.connected:
self._usb_output_devices_model.appendItem({"name": connection, "printer": self._usb_output_devices[connection]})
return self._usb_output_devices_model
## Create a list of serial ports on the system.
# \param only_list_usb If true, only usb ports are listed
def getSerialPortList(self, only_list_usb = False):
base_list = []
for port in serial.tools.list_ports.comports():
if not isinstance(port, tuple):
port = (port.device, port.description, port.hwid)
if only_list_usb and not port[2].startswith("USB"):
continue
base_list += [port[0]]
return list(base_list)
_instance = None # type: "USBPrinterOutputDeviceManager"
示例8: USBPrinterManager
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
#.........这里部分代码省略.........
machine_instance = Application.getInstance().getMachineManager().getActiveMachineInstance()
machine_type = machine_instance.getMachineDefinition().getId()
baudrate = 250000
if sys.platform.startswith("linux"):
baudrate = 115200
if machine_type == "ultimaker_original":
firmware_name = "MarlinUltimaker"
if machine_instance.getMachineSettingValue("machine_heated_bed"): #Has heated bed upgrade kit?
firmware_name += "-HBK"
firmware_name += "-%d" % (baudrate)
return firmware_name + ".hex"
elif machine_type == "ultimaker_original_plus":
firmware_name = "MarlinUltimaker-UMOP-%d" % (baudrate)
return firmware_name + ".hex"
elif machine_type == "bq_witbox":
return "MarlinWitbox.hex"
elif machine_type == "ultimaker2_go":
return "MarlinUltimaker2go.hex"
elif machine_type == "ultimaker2_extended":
return "MarlinUltimaker2extended.hex"
elif machine_type == "ultimaker2":
return "MarlinUltimaker2.hex"
elif machine_type == "ultimaker2plus":
return "MarlinUltimaker2plus.hex"
elif machine_type == "ultimaker2_extended_plus":
return "MarlinUltimaker2extended-plus.hex"
else:
Logger.log("e", "I don't know of any firmware for machine %s.", machine_type)
raise FileNotFoundError()
##TODO: Add check for multiple extruders
def _addRemovePorts(self, serial_ports):
# First, find and add all new or changed keys
for serial_port in list(serial_ports):
if serial_port not in self._serial_port_list:
self.addConnectionSignal.emit(serial_port) #Hack to ensure its created in main thread
continue
self._serial_port_list = list(serial_ports)
connections_to_remove = []
for port, connection in self._printer_connections.items():
if port not in self._serial_port_list:
connection.close()
connections_to_remove.append(port)
for port in connections_to_remove:
del self._printer_connections[port]
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
def addConnection(self, serial_port):
connection = PrinterConnection.PrinterConnection(serial_port)
connection.connect()
connection.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
connection.progressChanged.connect(self.progressChanged)
self._printer_connections[serial_port] = connection
def _onPrinterConnectionStateChanged(self, serial_port):
if self._printer_connections[serial_port].isConnected():
self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port])
else:
self.getOutputDeviceManager().removeOutputDevice(serial_port)
self.printerConnectionStateChanged.emit()
@pyqtProperty(QObject , notify = printerConnectionStateChanged)
def connectedPrinterList(self):
self._printer_connections_model = ListModel()
self._printer_connections_model.addRoleName(Qt.UserRole + 1,"name")
self._printer_connections_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._printer_connections:
if self._printer_connections[connection].isConnected():
self._printer_connections_model.appendItem({"name":connection, "printer": self._printer_connections[connection]})
return self._printer_connections_model
## Create a list of serial ports on the system.
# \param only_list_usb If true, only usb ports are listed
def getSerialPortList(self, only_list_usb = False):
base_list = []
if platform.system() == "Windows":
import winreg
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i = 0
while True:
values = winreg.EnumValue(key, i)
if not only_list_usb or "USBSER" in values[0]:
base_list += [values[1]]
i += 1
except Exception as e:
pass
else:
if only_list_usb:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*")
base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list
else:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*")
return list(base_list)
_instance = None
示例9: Doodle3D
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
#.........这里部分代码省略.........
elif machine_type == "ultimaker_original_plus":
firmware_name = "MarlinUltimaker-UMOP-%d" % (baudrate)
elif machine_type == "Witbox":
return "MarlinWitbox.hex"
elif machine_type == "ultimaker2go":
return "MarlinUltimaker2go.hex"
elif machine_type == "ultimaker2extended":
return "MarlinUltimaker2extended.hex"
elif machine_type == "ultimaker2":
return "MarlinUltimaker2.hex"
# TODO: Add check for multiple extruders
if firmware_name != "":
firmware_name += ".hex"
return firmware_name
def _addRemovePorts(self, serial_ports):
# First, find and add all new or changed keys
if serial_ports == None:
return False
for boxIP, boxIDENT in serial_ports.items():
if boxIP not in self._serial_port_list:
self.addConnectionSignal.emit(boxIP,boxIDENT)
continue
self._serial_port_list = serial_ports
# Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
def addConnection(self, serial_port, wifiboxid):
connection = PrinterConnection.PrinterConnection(serial_port, wifiboxid)
connection.connect()
connection.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
self._printer_connections[serial_port] = connection
def _onPrinterConnectionStateChanged(self, serial_port):
if self._printer_connections[serial_port].isConnected():
self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port])
else:
self.getOutputDeviceManager().removeOutputDevice(serial_port)
self.printerConnectionStateChanged.emit()
@pyqtProperty(QObject, notify=printerConnectionStateChanged)
def connectedPrinterList(self):
self._printer_connections_model = ListModel()
self._printer_connections_model.addRoleName(Qt.UserRole + 1, "name")
self._printer_connections_model.addRoleName(Qt.UserRole + 2, "printer")
for connection in self._printer_connections:
if self._printer_connections[connection].isConnected():
self._printer_connections_model.appendItem({"name": connection, "printer": self._printer_connections[connection]})
return self._printer_connections_model
# Create a list of serial ports on the system.
def getSerialPortList(self):
base_list = {}
# Get response from api/list.php and retrieve local ip
# from each individual boxes found on the local network
boxesListResponse = self.get("connect.doodle3d.com", "/api/list.php")
if (boxesListResponse == False):
return
boxes = boxesListResponse['data']
for index in range(len(boxes)):
box = boxes[index]
# Check if the boxes are alive
try:
self.get(box['localip'], "/d3dapi/network/alive")
except: # Run this exception for the boxes that aren't alive (anymore)
if box['localip'] in self._printer_connections:
self._printer_connections[box['localip']]._is_connected = False
self._printer_connections[box['localip']].close()
del self._printer_connections[box['localip']]
self.getOutputDeviceManager().removeOutputDevice(box['localip'])
else:
pass
else: # Boxes that are alive will be formed together into the base_list
base_list[box['localip']] = box['wifiboxid']
return base_list
# Takes Domain and Path and returns decoded JSON response back
def get(self, domain, path):
try:
#print('get: ', domain, path)
connect = http.client.HTTPConnection(domain)
connect.request("GET", path)
response = connect.getresponse()
#print(' response: ', response.status, response.reason)
jsonresponse = response.read()
#print(' ', jsonresponse)
return json.loads(jsonresponse.decode())
except Exception as e:
pass
return False
_instance = None
示例10: TestListModel
# 需要导入模块: from UM.Qt.ListModel import ListModel [as 别名]
# 或者: from UM.Qt.ListModel.ListModel import appendItem [as 别名]
class TestListModel(TestCase):
list_model = None # type: ListModel
test_data = [{"name": "yay", "data": 12}, {"name": "omg", "data": 13}, {"name":"zomg", "data": 14}]
NameRole = Qt.UserRole + 1
DataRole = Qt.UserRole + 2
def setUp(self):
self.list_model = ListModel()
self.list_model.addRoleName(self.NameRole, "name")
self.list_model.addRoleName(self.DataRole, "data")
self.list_model.setItems(deepcopy(self.test_data))
def test_getItem(self):
assert self.list_model.getItem(0) == {"name": "yay", "data": 12}
assert self.list_model.getItem(9001) == {}
def test_items(self):
assert self.list_model.items == self.test_data
def test_insertItem(self):
self.list_model.insertItem(0, {"name": "zomg!", "data": "yay"})
assert self.list_model.getItem(0) == {"name": "zomg!", "data": "yay"}
# Check if the previously first item is now the second one.
assert self.list_model.getItem(1) == {"name": "yay", "data": 12}
def test_removeItem(self):
self.list_model.removeItem(1)
print(self.list_model._items)
assert self.list_model.getItem(1) == {"name":"zomg", "data": 14}
def test_clear(self):
assert self.list_model.count == 3
self.list_model.clear()
assert self.list_model.count == 0
def test_appendItem(self):
self.list_model.appendItem({"name":"!", "data": 9001})
assert self.list_model.count == 4
assert self.list_model.getItem(3) == {"name":"!", "data": 9001}
def test_setProperty(self):
self.list_model.setProperty(0, "name", "new_data")
assert self.list_model.getItem(0)["name"] == "new_data"
def test_find(self):
assert self.list_model.find("name", "omg") == 1
assert self.list_model.find("data", 13) == 1
assert self.list_model.find("name", "zomg") == 2
assert self.list_model.find("name", "UNKNOWN") == -1
def test_setItems(self):
self.list_model.setItems([{"name": "zomg!", "data": "yay"}])
assert self.list_model.items == [{"name": "zomg!", "data": "yay"}]
def test_sort(self):
self.list_model.sort(lambda i: -i["data"])
assert self.list_model.getItem(0) == {"name":"zomg", "data": 14}
assert self.list_model.getItem(2) == {"name": "yay", "data": 12}