Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pythonturtle/helppages.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ def page_list(parent=None):
["Level 4", resource_filename("help4.png")],
]

pages = [
HelpPage(parent=parent,
bitmap=wx.Bitmap(bitmap_file),
caption=caption)
return [
HelpPage(parent=parent, bitmap=wx.Bitmap(bitmap_file), caption=caption)
for [caption, bitmap_file] in help_images_list
]

return pages
Comment on lines -74 to -81

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function page_list refactored with the following changes:

2 changes: 1 addition & 1 deletion pythonturtle/misc/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __ior__(self, other):
return self

def __repr__(self):
return "Vector(" + tuple.__repr__(self) + ")"
return f"Vector({tuple.__repr__(self)})"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Vector.__repr__ refactored with the following changes:


def norm(self):
"""
Expand Down
7 changes: 1 addition & 6 deletions pythonturtle/shelltoprocess/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def log(output):
sys.stdout.flush()

def push(self, command):
more = self.runsource(command, self.filename)
return more
return self.runsource(command, self.filename)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Console.push refactored with the following changes:


def showsyntaxerror(self, filename=None):
ex_type, value, sys.last_traceback = sys.exc_info()
Expand Down Expand Up @@ -130,10 +129,6 @@ def interact(self, banner=None):
more = 0
while True:
try:
if more:
pass # prompt = sys.ps2
else:
pass # prompt = sys.ps1
Comment on lines -133 to -136

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Console.interact refactored with the following changes:

This removes the following comments ( why? ):

# prompt = sys.ps1
# prompt = sys.ps2

try:
line = self.raw_input() # prompt)
except EOFError:
Expand Down
125 changes: 33 additions & 92 deletions pythonturtle/shelltoprocess/forkedpyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, parent=None, id=-1, title='PyShell',
if size == wx.DefaultSize:
self.SetSize((750, 525))

intro = 'PyShell %s - The Flakiest Python Shell' % VERSION
intro = f'PyShell {VERSION} - The Flakiest Python Shell'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ShellFrame.__init__ refactored with the following changes:

self.SetStatusText(intro.replace('\n', ', '))
self.shell = Shell(parent=self, id=-1, introText=intro,
locals=locals, InterpClass=InterpClass,
Expand Down Expand Up @@ -443,7 +443,7 @@ def setLocalShell(self):
def execStartupScript(self, startupScript):
"""Execute the user's PYTHONSTARTUP script if they have one."""
if startupScript and os.path.isfile(startupScript):
text = 'Startup script executed: ' + startupScript
text = f'Startup script executed: {startupScript}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.execStartupScript refactored with the following changes:

self.push('print %r; execfile(%r)' % (text, startupScript))
self.interp.startupScript = startupScript
else:
Expand Down Expand Up @@ -483,9 +483,7 @@ def OnChar(self, event):
# currpos = self.GetCurrentPos()
# stoppos = self.promptPosEnd
# Return (Enter) needs to be ignored in this handler.
if key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
pass
else:
if key not in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.OnChar refactored with the following changes:

# Allow the normal event handling to take place.
event.Skip()
"""
Expand Down Expand Up @@ -600,11 +598,9 @@ def OnKeyDown(self, event):
if not self.waiting_for_process:
self.processLine()

# Complete Text (from already typed words)
elif shiftDown and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
pass # self.OnShowCompHistory()

# Ctrl+Return (Ctrl+Enter) is used to insert a line break.
Comment on lines -603 to -607

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.OnKeyDown refactored with the following changes:

This removes the following comments ( why? ):

# Ctrl+Return (Ctrl+Enter) is used to insert a line break.
# Paste from the clipboard, run commands.
# Only allow these keys after the latest prompt.
# Complete Text (from already typed words)
# Don't modify a selection with text prior to the prompt.
# Cut to the clipboard.
# Insert the next command from the history buffer.
# Don't toggle between insert mode and overwrite mode.
# Clear the current command
# Copy to the clipboard, including prompts.
# Paste from the clipboard.
# Home needs to be aware of the prompt.
# Search up the history for the text in front of the cursor.
# Don't backspace over the latest non-continuation prompt.
# Clear the current, unexecuted command.
# The following handlers modify text, so we need to see if
# there is a selection that includes text prior to the prompt.
# Don't allow line transposition.
# Copy to the clipboard.
# Replace with the previous command from the history buffer.
# Basic navigation keys should work anywhere.
# Default font size.
# Increase font size.
# Replace with the next command from the history buffer.
# Decrease font size.
# Protect the readonly portion of the shell.
# Let Ctrl-Alt-* get handled normally.
#
# Don't allow line deletion.
# manually invoke AutoComplete and Calltips
# Copy to the clipboard, including prefixed prompts.
# Insert the previous command from the history buffer.

elif controlDown and key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
if self.CallTipActive():
self.CallTipCancel()
Expand All @@ -613,54 +609,42 @@ def OnKeyDown(self, event):
else:
self.insertLineBreak()

# Let Ctrl-Alt-* get handled normally.
elif controlDown and altDown:
event.Skip()

# Clear the current, unexecuted command.
elif key == wx.WXK_ESCAPE:
if self.CallTipActive():
event.Skip()
else:
self.clearCommand()

# Clear the current command
elif key == wx.WXK_BACK and controlDown and shiftDown:
self.clearCommand()

# Increase font size.
elif controlDown and key in (ord(']'), wx.WXK_NUMPAD_ADD):
dispatcher.send(signal='FontIncrease')

# Decrease font size.
elif controlDown and key in (ord('['), wx.WXK_NUMPAD_SUBTRACT):
dispatcher.send(signal='FontDecrease')

# Default font size.
elif controlDown and key in (ord('='), wx.WXK_NUMPAD_DIVIDE):
dispatcher.send(signal='FontDefault')

# Cut to the clipboard.
elif (controlDown and key in (ord('X'), ord('x'))) \
or (shiftDown and key == wx.WXK_DELETE):
self.Cut()

# Copy to the clipboard.
elif controlDown and not shiftDown \
and key in (ord('C'), ord('c'), wx.WXK_INSERT):
self.Copy()

# Copy to the clipboard, including prompts.
elif controlDown and shiftDown \
and key in (ord('C'), ord('c'), wx.WXK_INSERT):
self.CopyWithPrompts()

# Copy to the clipboard, including prefixed prompts.
elif altDown and not controlDown \
and key in (ord('C'), ord('c'), wx.WXK_INSERT):
elif altDown and key in (ord('C'), ord('c'), wx.WXK_INSERT):
self.CopyWithPromptsPrefixed()

# Home needs to be aware of the prompt.
elif key == wx.WXK_HOME:
home = self.promptPosEnd
if currpos > home:
Expand All @@ -671,50 +655,36 @@ def OnKeyDown(self, event):
else:
event.Skip()

#
# The following handlers modify text, so we need to see if
# there is a selection that includes text prior to the prompt.
#
# Don't modify a selection with text prior to the prompt.
elif selecting and key not in NAVKEYS and not self.CanEdit():
pass

# Paste from the clipboard.
elif (controlDown and not shiftDown and key in (ord('V'), ord('v'))) \
or (shiftDown and not controlDown and key == wx.WXK_INSERT):
self.Paste()

# manually invoke AutoComplete and Calltips
elif controlDown and key == wx.WXK_SPACE:
pass # self.OnCallTipAutoCompleteManually(shiftDown)

# Paste from the clipboard, run commands.
elif controlDown and shiftDown and key in (ord('V'), ord('v')):
self.PasteAndRun()

# Replace with the previous command from the history buffer.
elif (controlDown and key == wx.WXK_UP) \
or (altDown and key in (ord('P'), ord('p'))):
self.OnHistoryReplace(step=+1)

# Replace with the next command from the history buffer.
elif (controlDown and key == wx.WXK_DOWN) \
or (altDown and key in (ord('N'), ord('n'))):
self.OnHistoryReplace(step=-1)

# Insert the previous command from the history buffer.
elif (shiftDown and key == wx.WXK_UP) and self.CanEdit():
self.OnHistoryInsert(step=+1)

# Insert the next command from the history buffer.
elif (shiftDown and key == wx.WXK_DOWN) and self.CanEdit():
self.OnHistoryInsert(step=-1)

# Search up the history for the text in front of the cursor.
elif key == wx.WXK_F8:
self.OnHistorySearch()

# Don't backspace over the latest non-continuation prompt.
elif key == wx.WXK_BACK:
if selecting and self.CanEdit():
event.Skip()
Expand All @@ -734,28 +704,22 @@ def OnKeyDown(self, event):
else:
event.Skip()

# Only allow these keys after the latest prompt.
elif key in (wx.WXK_TAB, wx.WXK_DELETE):
if self.CanEdit():
event.Skip()

# Don't toggle between insert mode and overwrite mode.
elif key == wx.WXK_INSERT:
pass

# Don't allow line deletion.
elif controlDown and key in (ord('L'), ord('l')):
pass

# Don't allow line transposition.
elif controlDown and key in (ord('T'), ord('t')):
pass

# Basic navigation keys should work anywhere.
elif key in NAVKEYS:
event.Skip()

# Protect the readonly portion of the shell.
elif not self.CanEdit():
if key not in [wx.WXK_CONTROL, wx.WXK_ALT, wx.WXK_SHIFT]:
self.GotoPos(self.GetLength())
Expand All @@ -777,11 +741,7 @@ def OnShowCompHistory(self):
newlist = re.split(r'[ \.\[\]=}(\)\,0-9"]', joined)

# length > 1 (mix out "trash")
thlist = []
for i in newlist:
if len(i) > 1:
thlist.append(i)

thlist = [i for i in newlist if len(i) > 1]
Comment on lines -780 to +744

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.OnShowCompHistory refactored with the following changes:

# unique (no duplicate words
# oneliner from german python forum => unique list
unlist = [thlist[i] for i in range(len(thlist))
Expand Down Expand Up @@ -916,19 +876,15 @@ def processLine(self):
else:
self.push(command)
wx.CallLater(1, self.EnsureCaretVisible)
# Or replace the current command with the other command.
elif self.getCommand(rstrip=False):
command = self.getMultilineCommand()
self.clearCommand()
self.write(command)
else:
# If the line contains a command (even an invalid one).
if self.getCommand(rstrip=False):
command = self.getMultilineCommand()
self.clearCommand()
self.write(command)
# Otherwise, put the cursor back where we started.
else:
self.SetCurrentPos(thepos)
self.SetAnchor(thepos)
self.SetCurrentPos(thepos)
self.SetAnchor(thepos)

self.GotoPos(self.GetLength())
self.GotoPos(self.GetLength())
Comment on lines -919 to +887

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.processLine refactored with the following changes:

This removes the following comments ( why? ):

# If the line contains a command (even an invalid one).
# Otherwise, put the cursor back where we started.
# Or replace the current command with the other command.


def getMultilineCommand(self, rstrip=True):
"""Extract a multi-line command from the editor.
Expand Down Expand Up @@ -1007,9 +963,8 @@ def push(self, command, silent=False):
self.addHistory(command.rstrip())
if self.process_shell:
self.waiting_for_process = True
else:
if not silent:
self.prompt()
elif not silent:
self.prompt()
Comment on lines -1010 to +967

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.push refactored with the following changes:


def addHistory(self, command):
"""Add command to the command history."""
Expand Down Expand Up @@ -1113,8 +1068,7 @@ def ask(self, prompt='Please enter your response:'):
'Input Dialog (Raw)', '')
try:
if dialog.ShowModal() == wx.ID_OK:
text = dialog.GetValue()
return text
return dialog.GetValue()
Comment on lines -1116 to +1071

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.ask refactored with the following changes:

finally:
dialog.Destroy()
return ''
Expand Down Expand Up @@ -1163,12 +1117,12 @@ def autoCompleteShow(self, command, offset=0):
"""Display auto-completion popup list."""
self.AutoCompSetAutoHide(self.autoCompleteAutoHide)
self.AutoCompSetIgnoreCase(self.autoCompleteCaseInsensitive)
autocomp_list = self.interp.getAutoCompleteList(
if autocomp_list := self.interp.getAutoCompleteList(
command,
includeMagic=self.autoCompleteIncludeMagic,
includeSingle=self.autoCompleteIncludeSingle,
includeDouble=self.autoCompleteIncludeDouble)
if autocomp_list:
includeDouble=self.autoCompleteIncludeDouble,
):
Comment on lines -1166 to +1125

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.autoCompleteShow refactored with the following changes:

options = ' '.join(autocomp_list)
# offset = 0
self.AutoCompShow(offset, options)
Expand All @@ -1184,7 +1138,7 @@ def autoCallTipShow(self, command, insertcalltip=True, forceCallTip=False):
return
if argspec and insertcalltip and self.callTipInsert:
startpos = self.GetCurrentPos()
self.write(argspec + ')')
self.write(f'{argspec})')
Comment on lines -1187 to +1141

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.autoCallTipShow refactored with the following changes:

endpos = self.GetCurrentPos()
self.SetSelection(endpos, startpos)
if tip:
Expand Down Expand Up @@ -1255,49 +1209,36 @@ def writeErr(self, text):

def redirectStdin(self, redirect=True):
"""If redirect is true then sys.stdin will come from the shell."""
if redirect:
sys.stdin = self.reader
else:
sys.stdin = self.stdin
sys.stdin = self.reader if redirect else self.stdin
Comment on lines -1258 to +1212

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.redirectStdin refactored with the following changes:


def redirectStdout(self, redirect=True):
"""If redirect is true then sys.stdout will go to the shell."""
if redirect:
sys.stdout = PseudoFileOut(self.writeOut)
else:
sys.stdout = self.stdout
sys.stdout = PseudoFileOut(self.writeOut) if redirect else self.stdout
Comment on lines -1265 to +1216

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.redirectStdout refactored with the following changes:


def redirectStderr(self, redirect=True):
"""If redirect is true then sys.stderr will go to the shell."""
if redirect:
sys.stderr = PseudoFileErr(self.writeErr)
else:
sys.stderr = self.stderr
sys.stderr = PseudoFileErr(self.writeErr) if redirect else self.stderr
Comment on lines -1272 to +1220

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.redirectStderr refactored with the following changes:


def CanCut(self):
"""Return true if text is selected and can be cut."""
if self.GetSelectionStart() != self.GetSelectionEnd() \
and self.GetSelectionStart() >= self.promptPosEnd \
and self.GetSelectionEnd() >= self.promptPosEnd:
return True
else:
return False
return (
self.GetSelectionStart() != self.GetSelectionEnd()
and self.GetSelectionStart() >= self.promptPosEnd
and self.GetSelectionEnd() >= self.promptPosEnd
)
Comment on lines -1279 to +1228

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.CanCut refactored with the following changes:


def CanPaste(self):
"""Return true if a paste should succeed."""
if self.CanEdit() and editwindow.EditWindow.CanPaste(self):
return True
else:
return False
return bool(self.CanEdit() and editwindow.EditWindow.CanPaste(self))
Comment on lines -1288 to +1232

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Shell.CanPaste refactored with the following changes:


def CanEdit(self):
"""Return true if editing should succeed."""
if self.GetSelectionStart() != self.GetSelectionEnd():
if self.GetSelectionStart() >= self.promptPosEnd \
and self.GetSelectionEnd() >= self.promptPosEnd:
return True
else:
return False
return (
self.GetSelectionStart() >= self.promptPosEnd
and self.GetSelectionEnd() >= self.promptPosEnd
)

else:
return self.GetCurrentPos() >= self.promptPosEnd

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def rmtree_glob(file_glob):
for item in glob(file_glob, recursive=True):
try:
os.remove(item)
print('%s removed ...' % item)
print(f'{item} removed ...')
except OSError:
try:
shutil.rmtree(item)
print('%s/ removed ...' % item)
print(f'{item}/ removed ...')
Comment on lines -95 to +99

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rmtree_glob refactored with the following changes:

except OSError as err:
print(err)

Expand Down