Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of toktokkie. 

5 

6toktokkie is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11toktokkie is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with toktokkie. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20import os 

21from typing import Type 

22from puffotter.os import listdir 

23from toktokkie.utils.iconizing.procedures.Procedure import Procedure 

24from toktokkie.utils.iconizing.procedures.NoopProcedure import NoopProcedure 

25from toktokkie.utils.iconizing.procedures.GnomeProcedure import GnomeProcedure 

26from toktokkie.metadata.base.Metadata import Metadata 

27 

28 

29class Iconizer: 

30 """ 

31 Class that handles iconizing directories 

32 """ 

33 

34 all_procedures = [ 

35 GnomeProcedure 

36 ] 

37 """ 

38 All implemented procedures 

39 """ 

40 

41 def __init__( 

42 self, 

43 metadata: Metadata, 

44 procedure: Procedure 

45 ): 

46 """ 

47 Initializes the iconizer 

48 :param metadata: The metadata for the directory to iconize 

49 :param procedure: The procedure to use for iconizing. 

50 """ 

51 self.metadata = metadata 

52 self.procedure = procedure 

53 

54 def iconize(self): 

55 """ 

56 Iconizes the directory 

57 :return: None 

58 """ 

59 main_path = self.metadata.directory_path 

60 main_icon = self.metadata.get_icon_file("main") 

61 self.procedure.iconize(main_path, main_icon) 

62 

63 for child, child_path in listdir(main_path, no_files=True): 

64 icon = self.metadata.get_icon_file(child) 

65 if icon is not None and os.path.isfile(icon): 

66 self.procedure.iconize(child_path, icon) 

67 else: 

68 self.procedure.iconize(child_path, main_icon) 

69 

70 @staticmethod 

71 def default_procedure() -> Type[Procedure]: 

72 """ 

73 Checks all available procedures for eligibility 

74 :return: The eligible procedure or None if none were found 

75 """ 

76 for procedure in Iconizer.all_procedures: 

77 if procedure.is_applicable(): 

78 return procedure 

79 return NoopProcedure