Exemplo n.º 1
0
    def swapItems(self, x, y, srcIdx):
        """Swap two modules in fitting window"""
        mstate = wx.GetMouseState()
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.activeFitID)

        dstRow, _ = self.HitTest((x, y))

        if dstRow != -1 and dstRow not in self.blanks:
            mod1 = fit.modules[srcIdx]
            mod2 = self.mods[dstRow]

            if not isinstance(mod2, Module):
                return

            # can't swap modules to different racks
            if mod1.slot != mod2.slot:
                return

            fitID = self.mainFrame.getActiveFit()
            if getattr(mod2, "modPosition") is not None:
                if mstate.CmdDown() and mod2.isEmpty:
                    self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
                        fitID=fitID, srcPosition=srcIdx, dstPosition=mod2.modPosition))
                elif not mstate.CmdDown():
                    self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
                        fitID=fitID, position1=srcIdx, position2=mod2.modPosition))
            else:
                pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
Exemplo n.º 2
0
    def swapItems(self, x, y, srcIdx):
        """Swap two modules in fitting window"""
        sFit = Fit.getInstance()
        fit = sFit.getFit(self.activeFitID)

        dstRow, _ = self.HitTest((x, y))

        if dstRow != -1 and dstRow not in self.blanks:
            try:
                mod1 = fit.modules[srcIdx]
                mod2 = self.mods[dstRow]
            except IndexError:
                return
            if not isinstance(mod2, Module):
                return
            # can't swap modules to different racks
            if mod1.slot != mod2.slot:
                return
            if mod2 not in fit.modules:
                pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
                return
            mod2Position = fit.modules.index(mod2)
            mstate = wx.GetMouseState()
            if mstate.GetModifiers() == wx.MOD_CONTROL | wx.MOD_ALT:
                self.mainFrame.command.Submit(cmd.GuiFillWithClonedLocalModulesCommand(
                    fitID=self.activeFitID, position=srcIdx))
            elif mstate.GetModifiers() == wx.MOD_CONTROL and mod2.isEmpty:
                self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
                    fitID=self.activeFitID, srcPosition=srcIdx, dstPosition=mod2Position))
            elif mstate.GetModifiers() == wx.MOD_NONE:
                self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
                    fitID=self.activeFitID, position1=srcIdx, position2=mod2Position))