Conditions | 3 |
Total Lines | 79 |
Code Lines | 49 |
Lines | 59 |
Ratio | 74.68 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import PySimpleGUI as gui |
||
56 | def parsing(self): |
||
57 | """Parameters for parsing directory trees""" |
||
58 | with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
||
59 | layout = [ |
||
60 | [gui.Text('Directory Paths utility', size=(30, 1), font=("Helvetica", 25), text_color='blue')], |
||
61 | # Source |
||
62 | [ |
||
63 | gui.Text('Source Folder', size=(15, 1), auto_size_text=False), |
||
64 | gui.InputText('Source'), |
||
65 | gui.FolderBrowse() |
||
66 | ], |
||
67 | |||
68 | # Parallel / Sequential |
||
69 | [ |
||
70 | gui.Text('Parallel or Sequential Processing. Larger directory trees are typically parsed faster ' |
||
71 | 'using parallel processing.') |
||
72 | ], |
||
73 | [ |
||
74 | gui.Radio('Parallel Processing', "RADIO1"), |
||
75 | gui.Radio('Sequential Processing', "RADIO1", default=True) |
||
76 | ], |
||
77 | [_line()], |
||
78 | |||
79 | # Files and non-empty-folders |
||
80 | [gui.Text('Return files or folders, returning folders is useful for creating inventories.')], |
||
81 | [ |
||
82 | gui.Radio('Return Files', "RADIO2", default=True), |
||
83 | gui.Radio('Return Non-Empty Directories', "RADIO2") |
||
84 | ], |
||
85 | [_line()], |
||
86 | |||
87 | # max_level |
||
88 | [gui.Text('Max Depth.... Max number of sub directory depths to traverse (starting directory is 0)')], |
||
89 | [gui.InputCombo(list(reversed(range(0, 13))), size=(20, 3))], |
||
90 | [_line()], |
||
91 | |||
92 | # Relative and absolute |
||
93 | [ |
||
94 | gui.Text( |
||
95 | 'Relative or Absolute Paths. Relative paths are saved relative to the starting directory. ' |
||
96 | 'Absolute paths are saved as full paths.') |
||
97 | ], |
||
98 | [gui.Radio('Relative Paths', "RADIO3", default=True), |
||
99 | gui.Radio('Absolute Paths', "RADIO3")], |
||
100 | [_line()], |
||
101 | |||
102 | # Topdown and output |
||
103 | [gui.Checkbox('Topdown Parse', default=True), |
||
104 | gui.Checkbox('Live output results')], |
||
105 | [_line()], |
||
106 | |||
107 | # Save results to file |
||
108 | [gui.Checkbox('Save Results to File', default=False)], |
||
109 | [gui.Submit(), gui.Cancel()] |
||
110 | ] |
||
111 | |||
112 | (button, (values)) = form.LayoutAndShow(layout) |
||
113 | |||
114 | # gui.MsgBox(self.title, 'Parameters set', 'The results of the form are... ', |
||
115 | # 'The button clicked was "{}"'.format(button), 'The values are', values, auto_close=True) |
||
116 | |||
117 | self.params['parse'] = { |
||
118 | 'directory': values[0], |
||
119 | 'parallelize': values[1], |
||
120 | 'sequential': values[2], |
||
121 | 'yield_files': values[3], |
||
122 | 'non_empty_folders': values[4], |
||
123 | 'max_level': int(values[5]), |
||
124 | '_relative': values[6], |
||
125 | 'full_paths': values[7], |
||
126 | 'topdown': values[8], |
||
127 | 'console_stream': values[9], |
||
128 | 'save_file': values[10], |
||
129 | } |
||
130 | |||
131 | if self.params['parse']['save_file']: |
||
132 | self._saving() |
||
133 | |||
134 | return self.params |
||
135 | |||
245 |