7 from tkinter
import ttk
13 class CryWindowBase(tk
.Frame
):
16 super().__init
__(root
)
19 self
.layout(self
.root
)
21 def center_window(self
):
22 self
.root
.update_idletasks()
23 width
= self
.root
.winfo_width()
24 height
= self
.root
.winfo_height()
25 x
= (self
.root
.winfo_screenwidth() // 2) - (width
// 2)
26 y
= (self
.root
.winfo_screenheight() // 2) - (height
// 2)
27 self
.root
.geometry('+{}+{}'.format(x
, y
))
33 class CryWindowPlugin(CryWindowBase
):
34 def __init__(self
, plugin_file
):
36 self
.plugin_file
= plugin_file
38 def layout(self
, root
):
41 root
.title("Register CRYENGINE plugin")
42 root
.minsize(width
=windowWidth
, height
=windowHeight
)
43 root
.resizable(width
=False, height
=False)
46 iconfile
= "editor_icon16.ico"
47 if not hasattr(sys
, "frozen"):
48 iconfile
= os
.path
.join(os
.path
.dirname(__file__
), iconfile
)
50 iconfile
= os
.path
.join(sys
.prefix
, iconfile
)
51 root
.iconbitmap(iconfile
)
54 top
.pack(side
='top', fill
='both', expand
=True, padx
=5, pady
=5)
56 self
.combo
= ttk
.Combobox(top
, values
=self
.keys
, state
='readonly')
57 self
.combo
.pack(fill
='x', expand
=True, side
='right', padx
=2)
59 bottom
= tk
.Frame(root
)
60 bottom
.pack(side
='bottom', fill
='both', expand
=True, padx
=5, pady
=5)
62 self
.cancel
= tk
.Button(bottom
, text
='Cancel',
63 width
=10, command
=self
.close
)
64 self
.cancel
.pack(side
='right', padx
=2)
66 self
.ok
= tk
.Button(bottom
, text
='OK', width
=10,
67 command
=self
.command_ok
)
68 self
.ok
.pack(side
='right', padx
=2)
71 class CryWindowAddPlugin(CryWindowPlugin
):
72 def __init__(self
, plugin_file
):
73 engine_registry
= cryregistry
.load_engines()
74 self
.installed_engines
= {}
75 for it
in engine_registry
:
76 engine
= engine_registry
[it
]
77 engine_info
= engine
['info']
78 if 'name' in engine_info
:
79 self
.installed_engines
[engine_info
['name']] = engine
81 self
.installed_engines
[engine
['uri']] = engine
83 self
.keys
= sorted(self
.installed_engines
.keys())
85 super().__init
__(plugin_file
)
86 self
.root
.title("Register CRYENGINE plugins")
89 key
= self
.keys
[self
.combo
.current()]
90 engine
= self
.installed_engines
[key
]
91 engine_id
= engine
.get('info', {}).get('id')
93 return cryselect
.add_plugins(engine_id
, [self
.plugin_file
])
96 class CryWindowRemovePlugin(CryWindowPlugin
):
97 def __init__(self
, plugin_file
):
98 engine_registry
= cryregistry
.load_engines()
99 self
.installed_engines
= {}
100 for it
in engine_registry
:
101 engine
= engine_registry
[it
]
102 engine_info
= engine
['info']
103 engine_plugins
= engine
.get('plugins', [])
105 for it
in engine_plugins
:
106 if engine_plugins
[it
].get('uri') == plugin_file
:
107 if 'name' in engine_info
:
108 self
.installed_engines
[engine_info
.get(
111 self
.installed_engines
[engine
.get('uri')] = engine
114 self
.keys
= sorted(self
.installed_engines
.keys())
116 super().__init
__(plugin_file
)
117 self
.root
.title("Unregister CRYENGINE plugin")
119 def command_ok(self
):
120 key
= self
.keys
[self
.combo
.current()]
121 engine
= self
.installed_engines
[key
]
122 engine_id
= engine
.get('info', {}).get('id')
124 return cryselect
.remove_plugins(engine_id
, [self
.plugin_file
])