From ae9e0dc45914c7186fbec03fd05aeff9b95e63c1 Mon Sep 17 00:00:00 2001 From: Tom Manderson Date: Tue, 21 Apr 2015 15:15:06 +1000 Subject: [PATCH 1/3] Added acceptance of string anchors/sides for TkInter such as "w" and "top" --- problem_db/gui1.tut/analysis.py | 2 +- problem_db/gui2.tut/analysis.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/problem_db/gui1.tut/analysis.py b/problem_db/gui1.tut/analysis.py index 5db6a2d..4452839 100644 --- a/problem_db/gui1.tut/analysis.py +++ b/problem_db/gui1.tut/analysis.py @@ -72,7 +72,7 @@ def _analyse(self): 'You need to provide side as a keyword argument to ' 'pack (in {})'.format(pack.function_name) ) - elif pack.keywords['side'] != 'tk.LEFT': + elif pack.keywords['side'] in ['tk.LEFT',"TOP","top"]: self.add_error( 'You should be packing to the LEFT (got {} instead ' 'in {})'.format( diff --git a/problem_db/gui2.tut/analysis.py b/problem_db/gui2.tut/analysis.py index 6f43eb1..de4c2fa 100644 --- a/problem_db/gui2.tut/analysis.py +++ b/problem_db/gui2.tut/analysis.py @@ -72,7 +72,7 @@ def _analyse(self): 'You need to provide side as a keyword argument to ' 'pack (in {})'.format(pack.function_name) ) - elif pack.keywords['side'] != 'tk.TOP': + elif pack.keywords['side'] not in ['tk.TOP','TOP','top']: self.add_error( 'You appear to be using the wrong value for side ' '(in {})'.format(pack.function_name) @@ -83,7 +83,7 @@ def _analyse(self): 'You need to make sure that the buttons appear on top ' 'of each other on the left of the frame' ) - elif pack.keywords['anchor'] != 'tk.W': + elif pack.keywords['anchor'] not in ['tk.W','w',"W"]: self.add_error( 'You appear to be using the wrong value for anchor ' '(in {})'.format(pack.function_name) From 86fd47f3501f8f0600e60d27cbd6a657028c24f2 Mon Sep 17 00:00:00 2001 From: Tom Manderson Date: Tue, 21 Apr 2015 18:50:39 +1000 Subject: [PATCH 2/3] Revert acceptance of string anchors/sides for TkInter This reverts commit ae9e0dc45914c7186fbec03fd05aeff9b95e63c1. --- problem_db/gui1.tut/analysis.py | 2 +- problem_db/gui2.tut/analysis.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/problem_db/gui1.tut/analysis.py b/problem_db/gui1.tut/analysis.py index 4452839..5db6a2d 100644 --- a/problem_db/gui1.tut/analysis.py +++ b/problem_db/gui1.tut/analysis.py @@ -72,7 +72,7 @@ def _analyse(self): 'You need to provide side as a keyword argument to ' 'pack (in {})'.format(pack.function_name) ) - elif pack.keywords['side'] in ['tk.LEFT',"TOP","top"]: + elif pack.keywords['side'] != 'tk.LEFT': self.add_error( 'You should be packing to the LEFT (got {} instead ' 'in {})'.format( diff --git a/problem_db/gui2.tut/analysis.py b/problem_db/gui2.tut/analysis.py index de4c2fa..6f43eb1 100644 --- a/problem_db/gui2.tut/analysis.py +++ b/problem_db/gui2.tut/analysis.py @@ -72,7 +72,7 @@ def _analyse(self): 'You need to provide side as a keyword argument to ' 'pack (in {})'.format(pack.function_name) ) - elif pack.keywords['side'] not in ['tk.TOP','TOP','top']: + elif pack.keywords['side'] != 'tk.TOP': self.add_error( 'You appear to be using the wrong value for side ' '(in {})'.format(pack.function_name) @@ -83,7 +83,7 @@ def _analyse(self): 'You need to make sure that the buttons appear on top ' 'of each other on the left of the frame' ) - elif pack.keywords['anchor'] not in ['tk.W','w',"W"]: + elif pack.keywords['anchor'] != 'tk.W': self.add_error( 'You appear to be using the wrong value for anchor ' '(in {})'.format(pack.function_name) From 0fa529a630aaba46766b7a5747031194f21fd457 Mon Sep 17 00:00:00 2001 From: Tom Manderson Date: Tue, 21 Apr 2015 19:33:52 +1000 Subject: [PATCH 3/3] Added detailed error for valid but deprecated tkinter constants Now gives a more detailed error on "w" instead of tk.W, etc (anchors and sides) --- problem_db/gui1.tut/analysis.py | 17 ++++++++++++----- problem_db/gui2.tut/analysis.py | 32 +++++++++++++++++++++++--------- problem_db/gui3.tut/analysis.py | 18 +++++++++++++----- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/problem_db/gui1.tut/analysis.py b/problem_db/gui1.tut/analysis.py index 5db6a2d..fb27069 100644 --- a/problem_db/gui1.tut/analysis.py +++ b/problem_db/gui1.tut/analysis.py @@ -73,12 +73,19 @@ def _analyse(self): 'pack (in {})'.format(pack.function_name) ) elif pack.keywords['side'] != 'tk.LEFT': - self.add_error( - 'You should be packing to the LEFT (got {} instead ' - 'in {})'.format( - pack.keywords['side'], pack.function_name + if pack.keywords['side'].lower() == 'left': + self.error( + 'You appear to be using \'{}\' as your value for' + 'side. (in {}). Please use tk.LEFT'.format( + pack.keywords['side'], pack.function_name) + ) + else: + self.add_error( + 'You should be packing to the LEFT (got {} instead ' + 'in {})'.format( + pack.keywords['side'], pack.function_name + ) ) - ) elif len(pack.keywords) > 1: self.add_error( 'You only need to provide side as an argument to ' diff --git a/problem_db/gui2.tut/analysis.py b/problem_db/gui2.tut/analysis.py index 6f43eb1..88e093a 100644 --- a/problem_db/gui2.tut/analysis.py +++ b/problem_db/gui2.tut/analysis.py @@ -73,10 +73,17 @@ def _analyse(self): 'pack (in {})'.format(pack.function_name) ) elif pack.keywords['side'] != 'tk.TOP': - self.add_error( - 'You appear to be using the wrong value for side ' - '(in {})'.format(pack.function_name) - ) + if pack.keywords['side'].lower() == 'top': + self.error( + 'You appear to be using \'{}\' as your value for' + 'side. (in {}). Please use tk.TOP'.format( + pack.keywords['side'], pack.function_name) + ) + else: + self.add_error( + 'You appear to be using the wrong value for side ' + '(in {})'.format(pack.function_name) + ) if 'anchor' not in pack.keywords: self.add_error( @@ -84,10 +91,17 @@ def _analyse(self): 'of each other on the left of the frame' ) elif pack.keywords['anchor'] != 'tk.W': - self.add_error( - 'You appear to be using the wrong value for anchor ' - '(in {})'.format(pack.function_name) - ) + if pack.keywords['anchor'].lower() == "w": + self.error( + 'You appear to be using \'{}\' as your anchor' + 'value. (in {}). Please use tk.W'.format( + pack.keywords['anchor'], pack.function_name) + ) + else: + self.add_error( + 'You appear to be using the wrong value for anchor' + ' (in {})'.format(pack.function_name) + ) # first, make sure that they're packing twice if len(pack_calls) != 2: @@ -162,4 +176,4 @@ def _analyse(self): ) -ANALYSER = Analyser(CodeVisitor) \ No newline at end of file +ANALYSER = Analyser(CodeVisitor) diff --git a/problem_db/gui3.tut/analysis.py b/problem_db/gui3.tut/analysis.py index c152205..6579e7d 100644 --- a/problem_db/gui3.tut/analysis.py +++ b/problem_db/gui3.tut/analysis.py @@ -137,12 +137,20 @@ def _analyse(self): 'pack (in {})'.format(pack.function_name) ) elif pack.keywords['side'] != 'tk.{}'.format(side): - self.add_error( - 'You should be packing to the {} (got {} instead ' - 'in {})'.format( - side, pack.keywords['side'], pack.function_name + if pack.keywords['side'].lower() == side.lower(): + self.error( + 'You appear to be using \'{}\' as your value for' + 'side. (in {}). Please use tk.{}'.format( + pack.keywords['side'], pack.function_name, + side) + ) + else: + self.add_error( + 'You should be packing to the {} (got {} instead ' + 'in {})'.format( + side, pack.keywords['side'], pack.function_name + ) ) - ) if 'expand' not in pack.keywords: self.add_error(