Files
BulkR/src/core/widgets/replace.py

47 lines
1.2 KiB
Python
Raw Normal View History

2022-02-06 13:34:48 -06:00
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
2023-01-16 22:47:28 -06:00
from mixins import CommonWidgetGeneratorMixin
from mixins import CommonActionsMixin
2022-02-06 13:34:48 -06:00
2022-02-07 00:29:25 -06:00
class Replace(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin):
2022-02-06 13:34:48 -06:00
def __init__(self):
super(Replace, self).__init__()
self._name = "Replace"
2022-02-06 13:34:48 -06:00
2022-02-07 19:55:47 -06:00
self.entry_from = Gtk.Entry()
self.entry_to = Gtk.Entry()
2022-02-06 13:34:48 -06:00
self.entry_from.set_hexpand(True)
self.entry_to.set_hexpand(True)
2022-02-07 00:29:25 -06:00
self.entry_from.set_placeholder_text("Replace From...")
self.entry_to.set_placeholder_text("Replace To...")
2022-02-06 13:34:48 -06:00
2022-02-07 00:29:25 -06:00
self.add_widgets([self.entry_from, self.entry_to])
2022-02-06 13:34:48 -06:00
self.set_spacing(20)
self.show_all()
def run(self):
2023-01-16 22:47:28 -06:00
fsub = self.entry_from.get_text()
tsub = self.entry_to.get_text()
to_changes = event_system.emit_and_await("get-to")
2022-02-06 13:34:48 -06:00
if fsub and tsub:
new_collection = []
print(f"From: {fsub}\nTo: {tsub}")
2023-01-16 22:47:28 -06:00
for name in to_changes:
2022-02-06 13:34:48 -06:00
new_collection.append(name.replace(fsub, tsub))
2023-01-16 22:47:28 -06:00
event_system.emit("set-to", (new_collection,))
event_system.emit("update-to")