def on_add_item(self): # removebtn = self.sender() # item = self.itemmap[removebtn] # sisi.send("remove item", channel=self.charid, item=item) itemname = self.itemlist.currentText() item = self.itemmap[itemname] sisi.send("add item", channel="wardrobe", item=item)
def change_value(self, newval): '''This changes the value of the dial to the specified number.''' oldval = self.value # limit the value change newval = max(newval, self.minimum) newval = min(newval, self.maximum) if oldval == newval: return oldval # update the animations statechange = newval - oldval for animname, animdata in self.animations.items(): animval = self.update_animation_value(animname, dialchange=statechange) # check if the new value is different from the current state oldstate = editor.state[animname] newstate = round(animval) # round to int if oldstate != newstate: # sisi.disconnect(self.on__state_changed, signal="state changed", # channel="editor") self.ignore_state_change = True sisi.send(signal="set state", channel="editor", sender=self, data={ "field": animname, "value": newstate }) self.ignore_state_change = False # sisi.connect(self.on__state_changed, signal="state changed", # channel="editor") # update the view sisi.send(signal="update dial state", sender=self, data=newstate) return newval
def main(): # set up logging logging.basicConfig(level=logging.WARNING) log.info("") log.info("") log.info("Paperdoll editor") log.info("") log.info("cwd %s", os.getcwd()) # initialize signalling sisi.add_signals("doll drawn", "draw doll", "export doll", "set state", "set style", "state changed", "update dial state") sisi.add_channels("editor") # create editor model model.editor = model.MPaperdollEditor() # create Qt GUI view.version = __version__ view.app = view.Application(sys.argv) view.gui = view.VEditorWindow(model.editor) # display the gui log.info("Show main window") view.gui.resizeToScreen(width=0.8, height=0.8) view.gui.centerOnScreen() view.gui.show() # define initial state and draw the doll for dial in model.editor.dials.values(): dial.change_value(dial.value + 1) dial.change_value(dial.value - 1) sisi.send(signal="draw doll") # print_state() # show GUI with Qt sys.exit(view.app.exec_())
def attempt_redraw(self): '''Start a redraw if changeid is the id of the last state change.''' # the delay for the first change is up, so we update the changecount self.changecount -= 1 # has the time delay for all changes passed? if self.changecount is 0: sisi.send(signal="draw doll")
def on_exportsvg_triggered(self): # ask user where we should save the svg file path, filetypefilter = QtWidgets.QFileDialog.getSaveFileName(self, "Export paperdoll SVG file", "./paperdoll.svg", "SVG Files (*.svg)") if path: # ask model to save the doll to disk sisi.send(signal="export doll", data={"path": path})
def on__set_state(self, data): animname = data["field"] new = data["value"] old = self.state[animname] #TODO limit change # ignore if operation doesn't change anything if old == new: return # update internal state self.state[animname] = new # inform the world about state change data = {"field": animname, "old": old, "new": new} sisi.send(signal="state changed", channel="editor", data=data)
def on__state_changed(self, sender, data): if self.ignore_state_change is True: return animname = data["field"] if animname not in self.animations: return newstate = data["new"] oldstate = data["old"] # update the internal animation value self.update_animation_value(animname, animchange=newstate - oldstate) # calculate new value of slider based on change in animation value # and send it to the view sisi.send(signal="update dial state", sender=self, data=self.value)
def on_objectlist_clicked(self, idx): model = self.objectlist.model() # fetch all SVG element ids whose visibility should be changed elemids = model.elemids(idx) visibility = None for elemid in elemids: elem = self.svgdoc.idmap[elemid] if elem.style is None: elem.style = svglib.Style("display:inline") # set visibility if visibility is None: # toggle visibility if elem.style.visible is True: elem.style.visible = False else: elem.style.visible = True visibility = elem.style.visible else: elem.style.visible = visibility data = {"elemid": elem.elemid, "style": elem.style} sisi.send(signal="set style", data=data) sisi.send(signal="draw doll")
def main(): initialize() log.info("") log.info("") log.info("Paperdoll editor") log.info("") log.info("cwd %s", os.getcwd()) # create Qt GUI view.version = __version__ view.app = view.Application(sys.argv) view.gui = view.VEditorWindow(model.editor) # display the gui log.info("Show main window") view.gui.resizeToScreen(width=0.8, height=0.8) view.gui.centerOnScreen() view.gui.show() # define initial state and draw the doll char = model.MCharacter("drawn character") sisi.send(signal="change character", char=char) char.inventory.add_item(model.editor.wardrobe["uniform_jacket"]) char.inventory.add_item(model.editor.wardrobe["uniform_shirt"]) char.inventory.add_item(model.editor.wardrobe["uniform_skirt"]) char.inventory.add_item(model.editor.wardrobe["uniform_socks"]) char.inventory.add_item(model.editor.wardrobe["uniform_shoes"]) char.inventory.add_item(model.editor.wardrobe["basic_bra"]) char.inventory.add_item(model.editor.wardrobe["basic_panties"]) # for item in model.editor.wardrobe: # # TODO: do not add all items # char.inventory.add_item(item) for dial in model.editor.dials.values(): dial.change_value(dial.value + 1) dial.change_value(dial.value - 1) sisi.send(signal="draw doll") # print_state() # show GUI with Qt sys.exit(view.app.exec_())
def on_objectlist_clicked(self, idx): model = self.objectlist.model() item = model.itemFromIndex(idx) # elemid = model.elemidmap[item.index()] elemid = item.text() elem = self.svgdoc.idmap[elemid] if elem.style is None: elem.style = svglib.Style("display:inline") # toggle visibility if elem.style.visible is True: elem.style.visible = False else: elem.style.visible = True data = {"elemid": elem.elemid, "style": elem.style} sisi.send(signal="set style", data=data) # set visibility of subelements #TODO replace this hack by implementing style propagation if isinstance(elem, svglib.SvgGroup): for subelem in elem.iterate(): if subelem.style is not None: subelem.style.visible = elem.style.visible data = {"elemid": subelem.elemid, "style": subelem.style} sisi.send(signal="set style", data=data) sisi.send(signal="draw doll")
def _direct_redraw(self): # print("direct redraw") sisi.send(signal="draw doll")
def on_remove_item(self): removebtn = self.sender() item = self.itemmap[removebtn] sisi.send("remove item", channel=self.charid, item=item)
def on__draw_doll(self): sisi.send(signal="doll drawn", data=self.draw())