mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
Add buttons to PluginWindow
This commit is contained in:
parent
13a9d128fe
commit
b47a2815dc
1 changed files with 65 additions and 79 deletions
|
|
@ -67,12 +67,20 @@ class Plugin:
|
||||||
def installed(self):
|
def installed(self):
|
||||||
return os.path.isfile(self.install_path)
|
return os.path.isfile(self.install_path)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def enabled(self):
|
||||||
|
try:
|
||||||
|
return ba.app.config["Plugins"][self.entry_point]["enabled"]
|
||||||
|
except KeyError:
|
||||||
|
return False
|
||||||
|
|
||||||
async def install(self):
|
async def install(self):
|
||||||
response = await send_network_request(self.download_url)
|
response = await send_network_request(self.download_url)
|
||||||
with open(response.text, "w") as fout:
|
with open(self.install_path, "wb") as fout:
|
||||||
fout.write(self.install_path)
|
fout.write(response.read())
|
||||||
|
self.enable()
|
||||||
|
|
||||||
def remove(self):
|
def uninstall(self):
|
||||||
os.remove(self.install_path)
|
os.remove(self.install_path)
|
||||||
|
|
||||||
def _set_status(self, to_enable=True):
|
def _set_status(self, to_enable=True):
|
||||||
|
|
@ -92,9 +100,8 @@ class Plugin:
|
||||||
class PluginWindow(ba.Window):
|
class PluginWindow(ba.Window):
|
||||||
def __init__(self, plugin, origin_widget):
|
def __init__(self, plugin, origin_widget):
|
||||||
uiscale = ba.app.ui.uiscale
|
uiscale = ba.app.ui.uiscale
|
||||||
# b_color = (0.6, 0.53, 0.63)
|
b_color = (0.6, 0.53, 0.63)
|
||||||
# b_text_color = (0.75, 0.7, 0.8)
|
b_text_color = (0.75, 0.7, 0.8)
|
||||||
# self.manager_window = manager_window
|
|
||||||
s = 1.1 if uiscale is ba.UIScale.SMALL else 1.27 if ba.UIScale.MEDIUM else 1.57
|
s = 1.1 if uiscale is ba.UIScale.SMALL else 1.27 if ba.UIScale.MEDIUM else 1.57
|
||||||
width = 360 * s
|
width = 360 * s
|
||||||
height = 100 + 100 * s
|
height = 100 + 100 * s
|
||||||
|
|
@ -112,29 +119,6 @@ class PluginWindow(ba.Window):
|
||||||
if uiscale is ba.UIScale.MEDIUM else 1.0),
|
if uiscale is ba.UIScale.MEDIUM else 1.0),
|
||||||
scale_origin_stack_offset=scale_origin)
|
scale_origin_stack_offset=scale_origin)
|
||||||
pos = height * 0.8
|
pos = height * 0.8
|
||||||
# self.mod_type = mod_type = mod.get_mod_type()
|
|
||||||
# if mod_type == 'up-to-date':
|
|
||||||
# status_text = 'Status: Installed'
|
|
||||||
# button_text = 'Delete Mod'
|
|
||||||
# on_button_press = self._delete
|
|
||||||
# elif mod_type == 'outdated':
|
|
||||||
# status_text = 'Status: Installed (update available)'
|
|
||||||
# button_text = 'Update Mod'
|
|
||||||
# on_button_press = self._install
|
|
||||||
# elif mod_type == 'unknown version':
|
|
||||||
# status_text = 'Status: Unknown version installed'
|
|
||||||
# button_text = 'Reset Mod'
|
|
||||||
# on_button_press = self._install
|
|
||||||
# elif mod_type == 'not installed':
|
|
||||||
# status_text = 'Status: Not Installed'
|
|
||||||
# button_text = 'Install Mod'
|
|
||||||
# on_button_press = self._install
|
|
||||||
# elif mod_type == 'local only':
|
|
||||||
# status_text = 'Status: Local Mod'
|
|
||||||
# button_text = 'Delete Mod'
|
|
||||||
# on_button_press = self._delete
|
|
||||||
|
|
||||||
# name =
|
|
||||||
ba.textwidget(parent=self._root_widget,
|
ba.textwidget(parent=self._root_widget,
|
||||||
position=(width * 0.49, pos), size=(0, 0),
|
position=(width * 0.49, pos), size=(0, 0),
|
||||||
h_align='center', v_align='center', text=plugin.name,
|
h_align='center', v_align='center', text=plugin.name,
|
||||||
|
|
@ -164,56 +148,58 @@ class PluginWindow(ba.Window):
|
||||||
text=plugin.info["description"],
|
text=plugin.info["description"],
|
||||||
scale=text_scale * 0.6, color=color,
|
scale=text_scale * 0.6, color=color,
|
||||||
maxwidth=width * 0.95)
|
maxwidth=width * 0.95)
|
||||||
# pos = height * 0.1
|
b3_color = (0.8, 0.15, 0.35)
|
||||||
# button_size = (80 * s, 40 * s)
|
# b3_color = (0.15, 0.80, 0.35)
|
||||||
# installed_plugin, enabled = mod.enabled()
|
pos = height * 0.1
|
||||||
# if installed_plugin:
|
button_size = (80 * s, 40 * s)
|
||||||
# if enabled:
|
if plugin.installed:
|
||||||
# b3_text = 'Disable'
|
if plugin.enabled:
|
||||||
# b3_activate_call = self._disable
|
button1_label = "Disable"
|
||||||
# b3_color = (0.8, 0.15, 0.35)
|
button1_action = plugin.disable
|
||||||
# else:
|
else:
|
||||||
# b3_text = 'Enable'
|
button1_label = "Enable"
|
||||||
# b3_activate_call = self._enable
|
button1_action = plugin.enable
|
||||||
# b3_color = (0.15, 0.80, 0.35)
|
button2_label = "Uninstall"
|
||||||
# button1 = ba.buttonwidget(parent=self._root_widget,
|
button2_action = plugin.uninstall
|
||||||
# position=(width * 0.1, pos),
|
else:
|
||||||
# size=button_size,
|
button1_label = "Install"
|
||||||
# on_activate_call=on_button_press,
|
loop = asyncio.get_event_loop()
|
||||||
# color=b_color, textcolor=b_text_color,
|
button1_action = ba.Call(loop.create_task, plugin.install())
|
||||||
# button_type='square', text_scale=1,
|
# button1_action = asyncio.run, plugin.install
|
||||||
# label=button_text)
|
button3_label = "OK"
|
||||||
# button2 = ba.buttonwidget(parent=self._root_widget,
|
button3_action = lambda: None
|
||||||
# position=(width * 0.7, pos),
|
|
||||||
# size=button_size,
|
button1 = ba.buttonwidget(parent=self._root_widget,
|
||||||
# on_activate_call=self._ok,
|
position=(width * 0.1, pos),
|
||||||
# autoselect=True, button_type='square',
|
size=button_size,
|
||||||
# text_scale=1, label='OK')
|
on_activate_call=button1_action,
|
||||||
# button3 = ba.buttonwidget(parent=self._root_widget,
|
color=b_color,
|
||||||
# position=(width * 0.4, pos),
|
textcolor=b_text_color,
|
||||||
# size=button_size,
|
button_type='square',
|
||||||
# on_activate_call=b3_activate_call,
|
text_scale=1,
|
||||||
# color=b3_color, textcolor=b_text_color,
|
label=button1_label)
|
||||||
# button_type='square', text_scale=1,
|
if plugin.installed:
|
||||||
# label=b3_text)
|
button2 = ba.buttonwidget(parent=self._root_widget,
|
||||||
# else:
|
position=(width * 0.4, pos),
|
||||||
# button1 = ba.buttonwidget(parent=self._root_widget,
|
size=button_size,
|
||||||
# position=(width * 0.2, pos),
|
on_activate_call=button2_action,
|
||||||
# size=button_size,
|
color=b3_color,
|
||||||
# on_activate_call=on_button_press,
|
textcolor=b_text_color,
|
||||||
# color=b_color, textcolor=b_text_color,
|
button_type='square',
|
||||||
# button_type='square', text_scale=1,
|
text_scale=1,
|
||||||
# label=button_text)
|
label=button2_label)
|
||||||
# button2 = ba.buttonwidget(parent=self._root_widget,
|
button3 = ba.buttonwidget(parent=self._root_widget,
|
||||||
# position=(width * 0.6, pos),
|
position=(width * 0.7, pos),
|
||||||
# size=button_size,
|
size=button_size,
|
||||||
# on_activate_call=self._ok,
|
on_activate_call=button3_action,
|
||||||
# autoselect=True, button_type='square',
|
autoselect=True,
|
||||||
# text_scale=1, label='OK')
|
button_type='square',
|
||||||
# ba.containerwidget(edit=self._root_widget,
|
text_scale=1,
|
||||||
# on_cancel_call=button2.activate)
|
label=button3_label)
|
||||||
# ba.containerwidget(edit=self._root_widget, selected_child=button2)
|
ba.containerwidget(edit=self._root_widget,
|
||||||
# ba.containerwidget(edit=self._root_widget, start_button=button2)
|
on_cancel_call=button3.activate)
|
||||||
|
ba.containerwidget(edit=self._root_widget, selected_child=button3)
|
||||||
|
ba.containerwidget(edit=self._root_widget, start_button=button3)
|
||||||
|
|
||||||
|
|
||||||
class PluginManager:
|
class PluginManager:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue