Skip to content

Commit

Permalink
Typo fix, some cruft and renames:
Browse files Browse the repository at this point in the history
bash/game/__init__.py: typo (914dba4)
Took the opportunity to throw in some local `flag` variable renames,
untested but should be fine - under #312. Track using
\bflags\b(?!=) and \bflags\s*=\s*(?!re) regexes.

Mopy/bash/windows.py: Delete unused GetStockIcon GetStockIconLocation
They were unused since dacfb39 -
under #173.
  • Loading branch information
Utumno committed May 30, 2019
1 parent 3a50c3b commit 6ff2eb6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 89 deletions.
5 changes: 2 additions & 3 deletions Mopy/bash/balt.py
Expand Up @@ -1441,7 +1441,7 @@ def __init__(self, parent, fnDndAllow, pos=defPos, size=defSize, style=0,

def OnDragging(self,x,y,dragResult):
# We're dragging, see if we need to scroll the list
index, flags = self.HitTest((x, y))
index, _hit_flags = self.HitTest((x, y))
if index == wx.NOT_FOUND: # Didn't drop it on an item
if self.GetItemCount() > 0:
if y <= self.GetItemRect(0).y:
Expand Down Expand Up @@ -1503,8 +1503,7 @@ def OnDropFiles(self, x, y, filenames):
def _OnDropList(self, x, y, indexes):
start = indexes[0]
stop = indexes[-1]

index, flags = self.HitTest((x, y))
index, _hit_flags = self.HitTest((x, y))
if index == wx.NOT_FOUND: # Didn't drop it on an item
if self.GetItemCount() > 0:
if y <= self.GetItemRect(0).y:
Expand Down
6 changes: 3 additions & 3 deletions Mopy/bash/bolt.py
Expand Up @@ -891,15 +891,15 @@ def clearRO(self):
try:
clearReadOnly(self)
except UnicodeError:
flags = stat.S_IWUSR|stat.S_IWOTH
stat_flags = stat.S_IWUSR|stat.S_IWOTH
chmod = os.chmod
for root_dir,dirs,files in _walk(self._s):
rootJoin = root_dir.join
for directory in dirs:
try: chmod(rootJoin(directory),flags)
try: chmod(rootJoin(directory),stat_flags)
except: pass
for filename in files:
try: chmod(rootJoin(filename),flags)
try: chmod(rootJoin(filename),stat_flags)
except: pass

def open(self,*args,**kwdargs):
Expand Down
12 changes: 6 additions & 6 deletions Mopy/bash/bosh/_saves.py
Expand Up @@ -642,7 +642,7 @@ def getMaster(modIndex):
objRefNullBases = 0
fids = self.fids
for record in self.records:
fid,type,flags,version,data = record
fid,type,rec_flgs,version,data = record
if fid ==0xFEFFFFFF: continue #--Ignore intentional(?) extra fid added by patch.
mod = fid >> 24
if type not in typeModHisto:
Expand All @@ -661,7 +661,7 @@ def getMaster(modIndex):
print type,hex(fid),id_created[fid].recType
knownTypes.add(type)
#--Obj ref parents
if type == 49 and mod == 255 and (flags & 2):
if type == 49 and mod == 255 and (rec_flgs & 2):
iref, = struct_unpack('I', data[4:8])
count,cumSize = objRefBases.get(iref,(0,0))
count += 1
Expand Down Expand Up @@ -730,8 +730,8 @@ def findBloating(self,progress=None):
progress(len(self.created),_(u'Scanning change records.'))
fids = self.fids
for record in self.records:
fid,recType,flags,version,data = record
if recType == 49 and fid >> 24 == 0xFF and (flags & 2):
fid,recType,rec_flgs,version,data = record
if recType == 49 and fid >> 24 == 0xFF and (rec_flgs & 2):
iref, = struct_unpack('I', data[4:8])
if iref >> 24 != 0xFF and fids[iref] == 0:
nullRefCount += 1
Expand Down Expand Up @@ -765,10 +765,10 @@ def removeBloating(self,uncreateKeys,removeNullRefs=True,progress=None):
fids = self.fids
kept = []
for record in self.records:
fid,recType,flags,version,data = record
fid,recType,rec_flgs,version,data = record
if fid in uncreated:
numUnCreChanged += 1
elif removeNullRefs and recType == 49 and fid >> 24 == 0xFF and (flags & 2):
elif removeNullRefs and recType == 49 and fid >> 24 == 0xFF and (rec_flgs & 2):
iref, = struct_unpack('I', data[4:8])
if iref >> 24 != 0xFF and fids[iref] == 0:
numUnNulled += 1
Expand Down
16 changes: 8 additions & 8 deletions Mopy/bash/env.py
Expand Up @@ -571,13 +571,13 @@ def _fileOperation(operation, source, target=None, allowUndo=True,
_source = source; _target = target
if __shell and shell is not None:
# flags
flags = shellcon.FOF_WANTMAPPINGHANDLE # enables mapping return value !
flags |= FOF_NOCONFIRMMKDIR # never ask user for creating dirs
flags |= (len(target) > 1) * shellcon.FOF_MULTIDESTFILES
if allowUndo: flags |= shellcon.FOF_ALLOWUNDO
if not confirm: flags |= shellcon.FOF_NOCONFIRMATION
if renameOnCollision: flags |= shellcon.FOF_RENAMEONCOLLISION
if silent: flags |= shellcon.FOF_SILENT
flgs = shellcon.FOF_WANTMAPPINGHANDLE # enables mapping return value !
flgs |= FOF_NOCONFIRMMKDIR # never ask user for creating dirs
flgs |= (len(target) > 1) * shellcon.FOF_MULTIDESTFILES
if allowUndo: flgs |= shellcon.FOF_ALLOWUNDO
if not confirm: flgs |= shellcon.FOF_NOCONFIRMATION
if renameOnCollision: flgs |= shellcon.FOF_RENAMEONCOLLISION
if silent: flgs |= shellcon.FOF_SILENT
# null terminated strings
source = u'\x00'.join(source) # nope: + u'\x00'
target = u'\x00'.join(target)
Expand All @@ -588,7 +588,7 @@ def _fileOperation(operation, source, target=None, allowUndo=True,
# aborted: True if any operations aborted, False otherwise
# mapping: maps the old and new names of the renamed files
result, aborted, mapping = shell.SHFileOperation(
(parent, operation, source, target, flags, None, None))
(parent, operation, source, target, flgs, None, None))
if result == 0:
if aborted: raise SkipError()
return dict(mapping)
Expand Down
2 changes: 1 addition & 1 deletion Mopy/bash/game/__init__.py
Expand Up @@ -136,7 +136,7 @@ class sd(object):
class sp(object):
sp_abbrev = u'' # Abbreviated name. If this is empty, it signals that
# this game does not support SkyProc patchers.
long_ame = u'' # Full name
long_name = u'' # Full name
install_dir = u'' # The directory, relative to the Data folder, into
# which SkyProc patchers will be installed.

Expand Down
16 changes: 8 additions & 8 deletions Mopy/bash/patcher/patchers/importers.py
Expand Up @@ -294,9 +294,9 @@ def importCellBlockData(cellBlock):
for attr in attrs:
tempCellData[fid][attr] = cellBlock.cell.__getattribute__(
attr)
for flag in flags:
for flg_ in flgs_:
tempCellData[fid + ('flags',)][
flag] = cellBlock.cell.flags.__getattr__(flag)
flg_] = cellBlock.cell.flags.__getattr__(flg_)
def checkMasterCellBlockData(cellBlock):
"""
Add attribute values from record(s) in master file(s).
Expand All @@ -312,11 +312,11 @@ def checkMasterCellBlockData(cellBlock):
master_attr = cellBlock.cell.__getattribute__(attr)
if tempCellData[fid][attr] != master_attr:
cellData[fid][attr] = tempCellData[fid][attr]
for flag in flags:
master_flag = cellBlock.cell.flags.__getattr__(flag)
if tempCellData[fid + ('flags',)][flag] != master_flag:
cellData[fid + ('flags',)][flag] = \
tempCellData[fid + ('flags',)][flag]
for flg_ in flgs_:
master_flag = cellBlock.cell.flags.__getattr__(flg_)
if tempCellData[fid + ('flags',)][flg_] != master_flag:
cellData[fid + ('flags',)][flg_] = \
tempCellData[fid + ('flags',)][flg_]
loadFactory = LoadFactory(False,MreRecord.type_class['CELL'],
MreRecord.type_class['WRLD'])
progress.setFull(len(self.srcs))
Expand All @@ -341,7 +341,7 @@ def checkMasterCellBlockData(cellBlock):
if not tags: continue
attrs = set(reduce(# adds tuples together, then takes the set
operator.concat, (self.recAttrs[bashKey] for bashKey in tags)))
flags = tuple(self.recFlags[bashKey] for bashKey in tags if
flgs_ = tuple(self.recFlags[bashKey] for bashKey in tags if
self.recFlags[bashKey] != u'')
if 'CELL' in srcFile.tops:
for cellBlock in srcFile.CELL.cellBlocks:
Expand Down
22 changes: 11 additions & 11 deletions Mopy/bash/patcher/patchers/multitweak_names.py
Expand Up @@ -101,17 +101,17 @@ def buildPatch(self,log,progress,patchFile):
for record in getattr(patchFile,self.key).records:
if not record.full: continue
if record.full[0] in u'+-=.()[]': continue
flags = record.flags
if flags.head or flags.hair: type_ = head
elif flags.rightRing or flags.leftRing: type_ = ring
elif flags.amulet: type_ = amulet
elif flags.upperBody and flags.lowerBody: type_ = robe
elif flags.upperBody: type_ = chest
elif flags.lowerBody: type_ = pants
elif flags.hand: type_ = gloves
elif flags.foot: type_ = shoes
elif flags.tail: type_ = tail
elif flags.shield: type_ = shield
rec_flgs = record.flags
if rec_flgs.head or rec_flgs.hair: type_ = head
elif rec_flgs.rightRing or rec_flgs.leftRing: type_ = ring
elif rec_flgs.amulet: type_ = amulet
elif rec_flgs.upperBody and rec_flgs.lowerBody: type_ = robe
elif rec_flgs.upperBody: type_ = chest
elif rec_flgs.lowerBody: type_ = pants
elif rec_flgs.hand: type_ = gloves
elif rec_flgs.foot: type_ = shoes
elif rec_flgs.tail: type_ = tail
elif rec_flgs.shield: type_ = shield
else: continue
if record.recType == 'ARMO':
type_ += 'LH'[record.flags.heavyArmor]
Expand Down
67 changes: 18 additions & 49 deletions Mopy/bash/windows.py
Expand Up @@ -248,38 +248,6 @@ class SHSTOCKICONINFO(Structure):
('szPath',c_wchar*MAX_PATH)]


try:
stockiconinfo = windll.shell32.SHGetStockIconInfo
stockiconinfo.argtypes = [c_uint,c_uint,POINTER(SHSTOCKICONINFO)]
stockiconinfo.restype = c_uint32
STOCK_ICON_AVAILABLE = True

def GetStockIcon(id_,flags=0):
flags = ~(~flags|SHGSI_ICONLOCATION)|SHGSI_ICON
info = SHSTOCKICONINFO()
info.cbSize = sizeof(info)
result = stockiconinfo(id_,flags,byref(info))
if result != 0:
raise Exception(result)
return info.hIcon

def GetStockIconLocation(id_,flags=0):
flags = ~(~flags|SHGSI_ICON)|SHGSI_ICONLOCATION
info = SHSTOCKICONINFO()
info.cbSize = sizeof(info)
result = stockiconinfo(id_,flags,byref(info))
if result != 0:
raise Exception(result)
return info.szPath,info.iIcon
except AttributeError:
STOCK_ICON_AVAILABLE = False

def GetStockIcon(id_,flags=0):
return None

def GetStockIconLocation(id_,flags=0):
return u'',0

#--Start a webpage with an anchor ---------------------------------------------
# Need to do this specially, because doing it via os.startfile, ShellExecute,
# etc drops off the anchor part of the url
Expand Down Expand Up @@ -498,19 +466,20 @@ def show(self, command_links=False, centered=True, can_cancel=False,
###############################
# Windows windll.user32 calls #
###############################
def __configure(self, c_links, centered, close, minimize, h_links, flags):
def __configure(self, c_links, centered, close, minimize, h_links,
additional_flags):
conf = TASKDIALOGCONFIG()

if c_links and len(getattr(self, '_buttons', [])) > 0:
flags |= USE_COMMAND_LINKS
additional_flags |= USE_COMMAND_LINKS
if centered:
flags |= POSITION_RELATIVE_TO_WINDOW
additional_flags |= POSITION_RELATIVE_TO_WINDOW
if close:
flags |= ALLOW_DIALOG_CANCELLATION
additional_flags |= ALLOW_DIALOG_CANCELLATION
if minimize:
flags |= CAN_BE_MINIMIZED
additional_flags |= CAN_BE_MINIMIZED
if h_links:
flags |= ENABLE_HYPERLINKS
additional_flags |= ENABLE_HYPERLINKS

conf.cbSize = sizeof(TASKDIALOGCONFIG)
conf.hwndParent = self._parent
Expand All @@ -530,13 +499,13 @@ def __configure(self, c_links, centered, close, minimize, h_links, flags):
conf.uFooterIcon.pszFooterIcon = self._footer_icon
else:
conf.uFooterIcon.hFooterIcon = self._footer_icon
flags |= USE_HICON_FOOTER
additional_flags |= USE_HICON_FOOTER
if self._main_icon is not None:
if self._main_is_stock:
conf.uMainIcon.pszMainIcon = self._main_icon
else:
conf.uMainIcon.hMainIcon = self._main_icon
flags |= USE_HICON_MAIN
additional_flags |= USE_HICON_MAIN

if '_buttons' in attributes:
custom_buttons = []
Expand Down Expand Up @@ -579,7 +548,7 @@ def __configure(self, c_links, centered, close, minimize, h_links, flags):
conf.pRadioButtons = c_array

if self._default_radio is None:
flags |= NO_DEFAULT_RADIO_BUTTON
additional_flags |= NO_DEFAULT_RADIO_BUTTON
else:
conf.nDefaultRadioButton = self._default_radio

Expand All @@ -589,24 +558,24 @@ def __configure(self, c_links, centered, close, minimize, h_links, flags):
conf.pszExpandedInformation = self._expander_data[2]

if self._expander_expanded:
flags |= EXPANDED_BY_DEFAULT
additional_flags |= EXPANDED_BY_DEFAULT
if self._expands_at_footer:
flags |= EXPAND_FOOTER_AREA
additional_flags |= EXPAND_FOOTER_AREA

if '_cbox_label' in attributes:
conf.pszVerificationText = self._cbox_label
if self._cbox_checked:
flags |= VERIFICATION_FLAG_CHECKED
additional_flags |= VERIFICATION_FLAG_CHECKED

if '_marquee_progress_bar' in attributes:
flags |= SHOW_MARQUEE_PROGRESS_BAR
flags |= CALLBACK_TIMER
additional_flags |= SHOW_MARQUEE_PROGRESS_BAR
additional_flags |= CALLBACK_TIMER

if '_progress_bar' in attributes:
flags |= SHOW_PROGRESS_BAR
flags |= CALLBACK_TIMER
additional_flags |= SHOW_PROGRESS_BAR
additional_flags |= CALLBACK_TIMER

conf.dwFlags = flags
conf.dwFlags = additional_flags
conf.pfCallback = PFTASKDIALOGCALLBACK(self.__callback)
return conf

Expand Down

0 comments on commit 6ff2eb6

Please sign in to comment.