Fix some deprecated things and a bug or two

This commit is contained in:
Ryan Holmes
2017-07-02 23:08:02 -04:00
parent de5a734919
commit 7ae41b71b2
6 changed files with 35 additions and 32 deletions

View File

@@ -339,7 +339,7 @@ class Skill(HandledItem):
elif self.character.name == "All 0":
self.activeLevel = self.__level = 0
elif self.character.alphaClone:
return min(self.activeLevel, self.character.alphaClone.getSkillLevel(self)) or 0
return min(self.activeLevel or 0, self.character.alphaClone.getSkillLevel(self) or 0)
return self.activeLevel or 0

View File

@@ -91,10 +91,10 @@ class ChangeAffectingSkills(ContextMenu):
for i in range(-1, 6):
levelItem = self.addSkill(rootMenu if msw else grandSub, skill, i)
grandSub.AppendItem(levelItem)
grandSub.Append(levelItem)
if (not skill.learned and i == -1) or (skill.learned and skill.level == i):
levelItem.Check(True)
sub.AppendItem(skillItem)
sub.Append(skillItem)
return sub

View File

@@ -119,7 +119,7 @@ class MetaSwap(ContextMenu):
mitem = wx.MenuItem(rootMenu, id, item.name)
bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem)
self.moduleLookup[id] = item
m.AppendItem(mitem)
m.Append(mitem)
return m
def handleModule(self, event):

View File

@@ -206,18 +206,12 @@ class ItemStatsContainer(wx.Panel):
self.properties = ItemProperties(self.nbContainer, stuff, item, context)
self.nbContainer.AddPage(self.properties, "Properties")
self.nbContainer.Bind(wx.EVT_LEFT_DOWN, self.mouseHit)
self.SetSizer(mainSizer)
self.Layout()
def __del__(self):
pass
def mouseHit(self, event):
tab, _ = self.nbContainer.HitTest(event.Position)
if tab != -1:
self.nbContainer.SetSelection(tab)
class AutoListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ListRowHighlighter):
def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
@@ -463,7 +457,7 @@ class ItemParams(wx.Panel):
else:
attrIcon = self.imageList.Add(BitmapLoader.getBitmap("7_15", "icons"))
index = self.paramList.InsertImageStringItem(sys.maxsize, attrName, attrIcon)
index = self.paramList.InsertItem(sys.maxsize, attrName, attrIcon)
idNameMap[idCount] = attrName
self.paramList.SetItemData(index, idCount)
idCount += 1
@@ -482,11 +476,12 @@ class ItemParams(wx.Panel):
else:
valueUnitDefault = formatAmount(valueDefault, 3, 0, 0)
self.paramList.SetStringItem(index, 1, valueUnit)
self.paramList.SetItem(index, 1, valueUnit)
if self.stuff is not None:
self.paramList.SetStringItem(index, 2, valueUnitDefault)
self.paramList.SortItems(lambda id1, id2: cmp(idNameMap[id1], idNameMap[id2]))
self.paramList.SetItem(index, 2, valueUnitDefault)
# @todo: pheonix, this lamda used cmp() which no longer exists in py3. Probably a better way to do this in the
# long run, take a look
self.paramList.SortItems(lambda id1, id2: (idNameMap[id1]>idNameMap[id2])-(idNameMap[id1]<idNameMap[id2]))
self.paramList.RefreshRows()
self.totalAttrsLabel.SetLabel("%d attributes. " % idCount)
self.Layout()
@@ -553,7 +548,7 @@ class ItemCompare(wx.Panel):
self.sortReverse = False
self.item = item
self.items = sorted(items,
key=lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else None)
key=lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else 0)
self.attrs = {}
# get a dict of attrName: attrInfo of all unique attributes across all items
@@ -632,7 +627,7 @@ class ItemCompare(wx.Panel):
def processPrices(self, prices):
for i, price in enumerate(prices):
self.paramList.SetStringItem(i, len(self.attrs) + 1, formatAmount(price.value, 3, 3, 9, currency=True))
self.paramList.SetItem(i, len(self.attrs) + 1, formatAmount(price.value, 3, 3, 9, currency=True))
def PopulateList(self, sort=None):
@@ -682,10 +677,10 @@ class ItemCompare(wx.Panel):
else:
valueUnit = formatAmount(value, 3, 0, 0)
self.paramList.SetStringItem(i, x + 1, valueUnit)
self.paramList.SetItem(i, x + 1, valueUnit)
# Add prices
self.paramList.SetStringItem(i, len(self.attrs) + 1, formatAmount(item.price.price, 3, 3, 9, currency=True))
self.paramList.SetItem(i, len(self.attrs) + 1, formatAmount(item.price.price, 3, 3, 9, currency=True))
self.paramList.RefreshRows()
self.Layout()
@@ -746,7 +741,7 @@ class ItemRequirements(wx.Panel):
self.SetSizer(mainSizer)
self.root = self.reqTree.AddRoot("WINRARZOR")
self.reqTree.SetPyData(self.root, None)
self.reqTree.SetItemData(self.root, None)
self.imageList = wx.ImageList(16, 16)
self.reqTree.SetImageList(self.imageList)
@@ -878,11 +873,11 @@ class ItemEffects(wx.Panel):
else:
effectRunTime = ""
self.effectList.SetStringItem(index, 1, activeByDefault)
self.effectList.SetStringItem(index, 2, effectTypeText)
self.effectList.SetItem(index, 1, activeByDefault)
self.effectList.SetItem(index, 2, effectTypeText)
if config.debug:
self.effectList.SetStringItem(index, 3, effectRunTime)
self.effectList.SetStringItem(index, 4, str(effects[name].ID))
self.effectList.SetItem(index, 3, effectRunTime)
self.effectList.SetItem(index, 4, str(effects[name].ID))
self.effectList.RefreshRows()
self.Layout()
@@ -1060,7 +1055,7 @@ class ItemAffectedBy(wx.Panel):
# sheri was here
del self.treeItems[:]
root = self.affectedBy.AddRoot("WINPWNZ0R")
self.affectedBy.SetPyData(root, None)
self.affectedBy.SetItemData(root, None)
self.imageList = wx.ImageList(16, 16)
self.affectedBy.SetImageList(self.imageList)
@@ -1308,7 +1303,7 @@ class ItemAffectedBy(wx.Panel):
# this is the Module node, the attribute will be attached to this
child = self.affectedBy.AppendItem(parent, displayStr, itemIcon)
self.affectedBy.SetPyData(child, afflictors.pop())
self.affectedBy.SetItemData(child, afflictors.pop())
if counter > 0:
attributes = []
@@ -1362,7 +1357,7 @@ class ItemAffectedBy(wx.Panel):
saved = "%s %s %.2f %s" % (attrName, attrModifier, attrAmount, penalized)
treeitem = self.affectedBy.AppendItem(child, display, attrIcon)
self.affectedBy.SetPyData(treeitem, saved)
self.affectedBy.SetItemData(treeitem, saved)
self.treeItems.append(treeitem)
@@ -1447,13 +1442,13 @@ class ItemProperties(wx.Panel):
valueUnit = str(value)
self.paramList.SetStringItem(index, 1, valueUnit)
self.paramList.SetItem(index, 1, valueUnit)
except:
# TODO: Add logging to this.
# We couldn't get a property for some reason. Skip it for now.
continue
self.paramList.SortItems(lambda id1, id2: cmp(idNameMap[id1], idNameMap[id2]))
self.paramList.SortItems(lambda id1, id2: (idNameMap[id1]>idNameMap[id2])-(idNameMap[id1]<idNameMap[id2]))
self.paramList.RefreshRows()
self.totalAttrsLabel.SetLabel("%d attributes. " % idCount)
self.Layout()

View File

@@ -197,6 +197,10 @@ EVT_FLOATSPIN = wx.PyEventBinder(wxEVT_FLOATSPIN, 1)
""" with the keyboard. """
def _cmp(self, a, b):
return (a>b)-(a<b)
# ---------------------------------------------------------------------------- #
# Class FloatSpinEvent
# ---------------------------------------------------------------------------- #
@@ -1417,7 +1421,7 @@ class FixedPoint(object):
if (other == None):
return 1
xn, yn, p = _norm(self, other)
return cmp(xn, yn)
return _cmp(xn, yn)
def __hash__(self):
# caution! == values must have equal hashes, and a FixedPoint
@@ -1596,7 +1600,7 @@ def _mkFP(n, p, FixedPoint=FixedPoint):
def _roundquotient(x, y):
assert y > 0
n, leftover = divmod(x, y)
c = cmp(leftover << 1, y)
c = _cmp(leftover << 1, y)
# c < 0 <-> leftover < y/2, etc
if c > 0 or (c == 0 and (n & 1) == 1):
n = n + 1

View File

@@ -722,6 +722,9 @@ class Element(object):
_fmt = "%s:%s".__mod__
def _cmp(self, a, b):
return (a>b)-(a<b)
class Row(object):
# A Row is a single database record associated with a Rowset.
# The fields in the record are accessed as attributes by their respective
@@ -743,10 +746,11 @@ class Row(object):
def __eq__(self, other):
return self.__cmp__(other) == 0
def __cmp__(self, other):
if type(other) != type(self):
raise TypeError("Incompatible comparison type")
return cmp(self._cols, other._cols) or cmp(self._row, other._row)
return _cmp(self._cols, other._cols) or _cmp(self._row, other._row)
def __hasattr__(self, this):
if this in self._cols: