Skip to content

Commit

Permalink
Merge pull request #164 from jeanslack/codechecking
Browse files Browse the repository at this point in the history
code checking
  • Loading branch information
jeanslack committed Dec 13, 2022
2 parents 0f2b926 + ece3c2f commit f58f085
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 70 deletions.
59 changes: 26 additions & 33 deletions videomass/vdms_dialogs/renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author: Gianluca Pernigotto <jeanlucperni@gmail.com>
Copyright: (c) 2022 Gianluca Pernigotto <jeanlucperni@gmail.com>
license: GPL3
Rev: Dec.09.2022
Rev: Dec.13.2022
Code checker: pylint, flake8
########################################################
Expand Down Expand Up @@ -39,7 +39,7 @@ class Renamer(wx.Dialog):
Usage example:
with Renamer(self,
nameprop=_('New Name'),
nameprop='New Name',
caption='My awesome title',
message='My message here',
mode=0,
Expand Down Expand Up @@ -76,18 +76,15 @@ def __init__(self,
"""
self.mode = mode
msg = _("# It will be replaced by increasing numbers starting with:")
if self.mode >= 1:
self.newname = []
else:
self.newname = None
width = 472
wx.Dialog.__init__(self, parent, -1, style=wx.DEFAULT_DIALOG_STYLE)
sizer_base = wx.BoxSizer(wx.VERTICAL)
sizer_base.Add((10, 10))
labhead = wx.StaticText(self, wx.ID_ANY, message)
sizer_base.Add(labhead, 0, wx.EXPAND | wx.ALL, 5)
self.entry = wx.TextCtrl(self, wx.ID_ANY,
nameprop,
size=(-1, -1)
size=(width, -1)
)
sizer_base.Add(self.entry, 0, wx.EXPAND | wx.ALL, 5)
boxsiz = wx.BoxSizer(wx.HORIZONTAL)
Expand All @@ -96,12 +93,14 @@ def __init__(self,
labnum = wx.StaticText(self, wx.ID_ANY, msg)
boxsiz.Add(labnum, 0, wx.ALL | wx.ALIGN_CENTER, 5)
self.prognum = wx.SpinCtrl(self, wx.ID_ANY,
value="1",
min=0, max=999999999,
# size=(102, -1),
style=wx.SP_ARROW_KEYS
)
value="1",
min=0, max=999999999,
# size=(102, -1),
style=wx.SP_ARROW_KEYS
)
boxsiz.Add(self.prognum, 0, wx.ALL | wx.ALIGN_CENTER, 5)
width = labnum.GetSize()[0] + self.prognum.GetSize()[0]
self.entry.SetSize(width, -1)

# confirm buttons:
gridexit = wx.BoxSizer(wx.HORIZONTAL)
Expand All @@ -112,7 +111,7 @@ def __init__(self,
sizer_base.Add(gridexit, 0, wx.ALL | wx.ALIGN_RIGHT | wx.RIGHT, 0)

self.SetTitle(caption)
self.SetMinSize((512, -1))
# self.SetMinSize((width, -1))
self.SetSizer(sizer_base)
sizer_base.Fit(self)
self.Layout()
Expand All @@ -128,56 +127,50 @@ def get_newname(self):
Set newname attribute.
Return `list(newname)` if mode >= 1,
Return `str(newname)` if mode == 0,
Return `None` otherwise
Return `None` if raise ValueError.
"""
string = self.entry.GetValue()
if self.mode >= 1:
startfrom = self.prognum.GetValue()
try:
lasthashchar = string.rindex('#')
except ValueError:
del self.newname[:]
return None

self.newname = [string for x in range(self.mode)]
for num, name in enumerate(self.newname):
newname = [string for x in range(self.mode)]
for num, name in enumerate(newname):
temp = list(name)
temp[lasthashchar] = str(startfrom+num)
self.newname[num] = re.sub('#','0', ''.join(temp))
newname[num] = re.sub('#','0', ''.join(temp))
else:
self.newname = string
newname = string

return self.newname
return newname
# ------------------------------------------------------------------#

def rename_file(self):
"""
Checks the consistency of the entered string
for one file renaming.
Checks for consistency of the entered string
in one file renaming.
"""
if self.entry.GetValue() == '' or self.entry.GetValue().isspace():
self.btn_ok.Disable()
self.newname = None
return None
return

self.btn_ok.Enable()
# ------------------------------------------------------------------#

def rename_batch(self):
"""
Checks the consistency of the entered string
for batch renaming.
Checks for consistency of the entered string
in batch renaming.
"""
string = self.entry.GetValue()
occur = re.findall(r'((\#)\#*)', string)
if len(occur) > 1: # if more '#' occurrences between sentence.
self.btn_ok.Disable()
del self.newname[:]
return None
if '#' not in string:

if '#' not in string or len(occur) > 1:
self.btn_ok.Disable()
del self.newname[:]
return None
return

self.btn_ok.Enable()
# ----------------------Event handler (callback)----------------------#
Expand Down
47 changes: 10 additions & 37 deletions videomass/vdms_panels/filedrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def fullpathname_sanitize(fullpathfilename):
noext = _("File without format extension: please give an "
"appropriate extension to the file name, example "
"'.mkv', '.avi', '.mp3', etc.")
invalid = r"\'\^\`\~\"\#\'\%\&\*\:\<\>\?\/\\\{\|\}"

check = bool(re.search(r"^(?:[^%s]{1,255}$)*$" % (invalid),
check = bool(re.search(r"^(?:[^\'\^\`\~\"\#\'\%\&\*\:\<\>\?\/\\\{\|\}])*$",
os.path.basename(fullpathfilename)))
if check is not True:
return f'{illegalchars} {illegal}'
Expand Down Expand Up @@ -86,9 +85,9 @@ def filename_sanitize(newname, outputnames):
illegal = '^` ~ " # \' % & * : < > ? / \\ { | }'
msg_invalid = _('Name has illegal characters like: {0}').format(illegal)
msg_inuse = _('Name already in use:')
invalid = r"\'\^\`\~\"\#\'\%\&\*\:\<\>\?\/\\\{\|\}"

check = bool(re.search(r"^(?:[^%s]{1,255}$)*$" % (invalid), newname))
check = bool(re.search(r"^(?:[^\'\^\`\~\"\#\'\%\&\*\:\<\>\?\/\\\{\|\}]"
r"{1,255}$)*$", newname))
if check is not True:
return f'{msg_invalid}'

Expand Down Expand Up @@ -255,7 +254,6 @@ def __init__(self, parent, iconplay):
self.data = self.parent.data_files # set items list data on parent
self.outputnames = self.parent.outputnames
self.file_dest = appdata['outputfile']
self.selected = None # tells if an imported file is selected or not
self.sortingstate = None # ascending or descending order

wx.Panel.__init__(self, parent=parent)
Expand Down Expand Up @@ -419,33 +417,21 @@ def on_play_select(self, event):
Playback the selected file
"""
if not self.selected:
self.parent.statusbar_msg(_('No file selected'), FileDnD.YELLOW,
FileDnD.BLACK)
index = self.flCtrl.GetFocusedItem()
item = self.flCtrl.GetItemText(index, 1)
if self.parent.checktimestamp:
tstamp = f'-vf "{self.parent.cmdtimestamp}"'
else:
self.parent.statusbar_msg(_('Add Files'), None)
index = self.flCtrl.GetFocusedItem()
item = self.flCtrl.GetItemText(index, 1)
if self.parent.checktimestamp:
tstamp = f'-vf "{self.parent.cmdtimestamp}"'
else:
tstamp = ""
io_tools.stream_play(item, self.parent.time_seq,
tstamp, self.parent.autoexit
)
tstamp = ""
io_tools.stream_play(item, self.parent.time_seq,
tstamp, self.parent.autoexit)
# ----------------------------------------------------------------------

def on_delete_selected(self, event):
"""
Delete a selected file or a bunch of selected files
"""
if not self.selected:
self.parent.statusbar_msg(_('No file selected'), FileDnD.YELLOW,
FileDnD.BLACK)
return

self.parent.statusbar_msg(_('Add Files'), None)
item, indexes = -1, []
while 1:
item = self.flCtrl.GetNextItem(item,
Expand Down Expand Up @@ -483,7 +469,6 @@ def delete_all(self, event, setstate=True):
del self.outputnames[:]
self.parent.filedropselected = None
self.reset_timeline()
self.selected = None
self.btn_play.Disable()
self.btn_remove.Disable()
self.btn_clear.Disable()
Expand All @@ -500,7 +485,6 @@ def on_select(self, event):
index = self.flCtrl.GetFocusedItem()
item = self.flCtrl.GetItemText(index, 1)
self.parent.filedropselected = item
self.selected = item
self.btn_play.Enable()
self.btn_remove.Enable()
self.parent.rename.Enable(True)
Expand All @@ -512,7 +496,6 @@ def on_deselect(self, event):
the control list
"""
self.parent.filedropselected = None
self.selected = None
self.btn_play.Disable()
self.btn_remove.Disable()
self.parent.rename.Enable(False)
Expand Down Expand Up @@ -543,11 +526,6 @@ def file_renaming(self):
Names consisting of only whitespaces or tabs or matching
same name as outputnames are rejected silently.
"""
if not self.selected:
self.parent.statusbar_msg(_('No file selected'), FileDnD.YELLOW,
FileDnD.BLACK)
return

row_id = self.flCtrl.GetFocusedItem() # Get the current row
oldname = self.flCtrl.GetItemText(row_id, 5) # Get current name
newname = ''
Expand Down Expand Up @@ -583,11 +561,6 @@ def batch_files_renaming(self):
"""
This method is responsible for batch file renaming.
"""
if not self.outputnames:
self.parent.statusbar_msg(_('No files to rename in list'),
FileDnD.YELLOW, FileDnD.BLACK)
return

title = _('Rename items')
msg = _('Rename the {0} items to:').format(len(self.outputnames))
with Renamer(self,
Expand Down

0 comments on commit f58f085

Please sign in to comment.