def _process_imports(self): lines = [] if self._script_type in (ScriptType.APP_CODE, ScriptType.WIDGET): if self._import_tk: self.add_import_line('tkinter', 'tk') if self._import_ttk: self.add_import_line('tkinter.ttk', 'ttk', priority=2) sorted_imports = sorted( self._extra_imports.items(), key=lambda x: (x[1][1], x[0]) ) for module_name, (as_name, _) in sorted_imports: line = f'import {module_name}' if as_name is not None: line = line + f' as {as_name}' lines.append(line) # Do not include code imports if using UI file. if self._script_type != ScriptType.APP_WITH_UI: skeys = sorted(self._code_imports.keys()) for mname in skeys: names = sorted(self._code_imports[mname]) for group in grouper(names, 4): bag = [] for cname in group: if cname is not None: bag.append(cname) clist = None if len(bag) > 1: clist = '({})'.format(', '.join(bag)) else: clist = ''.join(bag) line = f'from {mname} import {clist}' lines.append(line) return lines
def _process_imports(self): lines = [] s = 'import tkinter as tk' lines.append(s) if self._import_ttk: s = 'import tkinter.ttk as ttk' lines.append(s) skeys = sorted(self._code_imports.keys()) for mname in skeys: names = sorted(self._code_imports[mname]) for group in grouper(names, 4): bag = [] for cname in group: if cname is not None: bag.append(cname) clist = None if len(bag) > 1: clist = '({0})'.format(', '.join(bag)) else: clist = ''.join(bag) line = 'from {0} import {1}'.format(mname, clist) lines.append(line) return lines