Пример #1
0
    def ValuesUpdated(self, event=None):
        """
        Event that is fired when resists values change. Iterates through all
        resist edit fields. If blank, sets it to 0.0. If it is not a proper
        decimal value, sets text color to red and refuses to save changes until
        issue is resolved
        """
        if self.block:
            return

        editObj = None

        try:
            p = self.entityEditor.getActiveEntity()

            for type_ in self.DAMAGE_TYPES:
                editObj = getattr(self, "%sEdit" % type_)

                if editObj.GetValue() == "":
                    # if we are blank, overwrite with 0
                    editObj.ChangeValue("0.0")
                    editObj.SetInsertionPointEnd()

                value = float(editObj.GetValue())

                # assertion, because they're easy
                assert 0 <= value <= 100

                # if everything checks out, set resist attribute
                setattr(p, "%sAmount" % type_, value / 100)
                editObj.SetForegroundColour(self.colorReset)

            self.stNotice.SetLabel("")
            self.totSizer.Layout()

            if event is not None:
                event.Skip()

            TargetResists.getInstance().saveChanges(p)

        except ValueError:
            editObj.SetForegroundColour(wx.RED)
            msg = "Incorrect Formatting (decimals only)"
            pyfalog.warning(msg)
            self.stNotice.SetLabel(msg)
        except AssertionError:
            editObj.SetForegroundColour(wx.RED)
            msg = "Incorrect Range (must be 0-100)"
            pyfalog.warning(msg)
            self.stNotice.SetLabel(msg)
        finally:  # Refresh for color changes to take effect immediately
            self.Refresh()
Пример #2
0
    def ValuesUpdated(self, event=None):
        """
        Event that is fired when resists values change. Iterates through all
        resist edit fields. If blank, sets it to 0.0. If it is not a proper
        decimal value, sets text color to red and refuses to save changes until
        issue is resolved
        """
        if self.block:
            return

        editObj = None

        try:
            p = self.entityEditor.getActiveEntity()

            for type_ in self.DAMAGE_TYPES:
                editObj = getattr(self, "%sEdit" % type_)

                if editObj.GetValue() == "":
                    # if we are blank, overwrite with 0
                    editObj.ChangeValue("0.0")
                    editObj.SetInsertionPointEnd()

                value = float(editObj.GetValue())

                # assertion, because they're easy
                assert 0 <= value <= 100

                # if everything checks out, set resist attribute
                setattr(p, "%sAmount" % type_, value / 100)
                editObj.SetForegroundColour(self.colorReset)

            self.stNotice.SetLabel("")
            self.totSizer.Layout()

            if event is not None:
                event.Skip()

            TargetResists.getInstance().saveChanges(p)

        except ValueError:
            editObj.SetForegroundColour(wx.RED)
            msg = "Incorrect Formatting (decimals only)"
            pyfalog.warning(msg)
            self.stNotice.SetLabel(msg)
        except AssertionError:
            editObj.SetForegroundColour(wx.RED)
            msg = "Incorrect Range (must be 0-100)"
            pyfalog.warning(msg)
            self.stNotice.SetLabel(msg)
        finally:  # Refresh for color changes to take effect immediately
            self.Refresh()
Пример #3
0
    def display(self, srcContext, selection):
        if self.mainFrame.getActiveFit() is None or srcContext != "firepowerViewFull":
            return False

        sTR = svc_TargetResists.getInstance()
        self.patterns = sTR.getTargetResistsList()
        self.patterns.sort(key=lambda p: (p.name in ["None"], p.name))

        return len(self.patterns) > 0
Пример #4
0
    def display(self, srcContext, selection):
        if self.mainFrame.getActiveFit() is None or srcContext != "firepowerViewFull":
            return False

        sTR = svc_TargetResists.getInstance()
        self.patterns = sTR.getTargetResistsList()
        self.patterns.sort(key=lambda p: (p.name in ["None"], p.name))

        return len(self.patterns) > 0
Пример #5
0
    def importPatterns(self, event):
        "Event fired when import from clipboard button is clicked"

        text = fromClipboard()
        if text:
            sTR = TargetResists.getInstance()
            try:
                sTR.importPatterns(text)
                self.stNotice.SetLabel("Patterns successfully imported from clipboard")
            except ImportError as e:
                self.stNotice.SetLabel(str(e))
            except Exception:
                self.stNotice.SetLabel("Could not import from clipboard: unknown errors")
            finally:
                self.entityEditor.refreshEntityList()
        else:
            self.stNotice.SetLabel("Could not import from clipboard")
Пример #6
0
    def display(self, srcContext, selection):
        if not self.settings.get('targetResists'):
            return False

        if srcContext == "firepowerViewFull":
            if self.mainFrame.getActiveFit() is None:
                return False
        elif srcContext in ("graphTargetFitsResists", "graphTargetResists"):
            pass
        else:
            return False

        sTR = svc_TargetResists.getInstance()
        self.patterns = sTR.getTargetResistsList()
        self.patterns.sort(key=lambda p: (p.name in ["None"], p.name))

        return len(self.patterns) > 0
Пример #7
0
    def importPatterns(self, event):
        """Event fired when import from clipboard button is clicked"""

        text = fromClipboard()
        if text:
            sTR = TargetResists.getInstance()
            try:
                sTR.importPatterns(text)
                self.stNotice.SetLabel("Patterns successfully imported from clipboard")
            except ImportError as e:
                pyfalog.error(e)
                self.stNotice.SetLabel(str(e))
            except Exception as e:
                msg = "Could not import from clipboard:"
                pyfalog.warning(msg)
                pyfalog.error(e)
                self.stNotice.SetLabel(msg)
            finally:
                self.entityEditor.refreshEntityList()
        else:
            self.stNotice.SetLabel("Could not import from clipboard")
Пример #8
0
 def getEntitiesFromContext(self):
     sTR = TargetResists.getInstance()
     choices = sorted(sTR.getTargetResistsList(), key=lambda p: p.name)
     return choices
Пример #9
0
 def exportPatterns(self, event):
     """Event fired when export to clipboard button is clicked"""
     sTR = TargetResists.getInstance()
     toClipboard(sTR.exportPatterns())
     self.stNotice.SetLabel("Patterns exported to clipboard")
Пример #10
0
 def DoDelete(self, entity):
     sTR = TargetResists.getInstance()
     sTR.deletePattern(entity)
Пример #11
0
 def DoCopy(self, entity, name):
     sTR = TargetResists.getInstance()
     copy = sTR.copyPattern(entity)
     sTR.renamePattern(copy, name)
     return copy
Пример #12
0
 def DoCopy(self, entity, name):
     sTR = TargetResists.getInstance()
     copy = sTR.copyPattern(entity)
     sTR.renamePattern(copy, name)
     return copy
Пример #13
0
 def getEntitiesFromContext(self):
     sTR = TargetResists.getInstance()
     choices = sorted(sTR.getTargetResistsList(), key=lambda p: p.name)
     return choices
Пример #14
0
 def exportPatterns(self, event):
     "Event fired when export to clipboard button is clicked"
     sTR = TargetResists.getInstance()
     toClipboard(sTR.exportPatterns())
     self.stNotice.SetLabel("Patterns exported to clipboard")
Пример #15
0
 def DoNew(self, name):
     sTR = TargetResists.getInstance()
     return sTR.newPattern(name)
Пример #16
0
 def DoRename(self, entity, name):
     sTR = TargetResists.getInstance()
     sTR.renamePattern(entity, name)
Пример #17
0
 def DoNew(self, name):
     sTR = TargetResists.getInstance()
     return sTR.newPattern(name)
Пример #18
0
 def DoDelete(self, entity):
     sTR = TargetResists.getInstance()
     sTR.deletePattern(entity)
Пример #19
0
 def DoRename(self, entity, name):
     sTR = TargetResists.getInstance()
     sTR.renamePattern(entity, name)