2022-02-06 19:34:48 +00:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
# Application imports
|
2023-01-17 04:47:28 +00:00
|
|
|
from mixins import CommonWidgetGeneratorMixin
|
|
|
|
from mixins import CommonActionsMixin
|
|
|
|
|
|
|
|
|
2022-02-06 19:34:48 +00:00
|
|
|
|
|
|
|
|
2022-02-07 06:29:25 +00:00
|
|
|
class RemoveFromTo(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin):
|
2022-02-06 19:34:48 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(RemoveFromTo, self).__init__()
|
2023-02-21 22:27:44 +00:00
|
|
|
self._name = "Remove From / To"
|
2022-02-06 19:34:48 +00:00
|
|
|
|
2022-02-08 01:55:47 +00:00
|
|
|
self.entry_from = Gtk.Entry()
|
|
|
|
self.entry_to = Gtk.Entry()
|
|
|
|
self.spin_button_from = self._create_spinbutton_widget()
|
|
|
|
self.spin_button_to = self._create_spinbutton_widget()
|
2022-02-06 19:34:48 +00:00
|
|
|
|
|
|
|
self.entry_from.set_hexpand(True)
|
|
|
|
self.entry_to.set_hexpand(True)
|
2022-02-08 01:55:47 +00:00
|
|
|
self.spin_button_from.set_hexpand(True)
|
|
|
|
self.spin_button_to.set_hexpand(True)
|
|
|
|
self.spin_button_from.set_sensitive(True)
|
|
|
|
self.spin_button_to.set_sensitive(True)
|
|
|
|
self.entry_from.set_placeholder_text("Start...")
|
|
|
|
self.entry_to.set_placeholder_text("End...")
|
2022-02-06 19:34:48 +00:00
|
|
|
|
2022-02-08 01:55:47 +00:00
|
|
|
data = ["Using Sub String", "Using Index"]
|
|
|
|
self.store, self.combo_box = self._create_combobox_widget(data)
|
2022-02-06 19:34:48 +00:00
|
|
|
|
2022-02-08 01:55:47 +00:00
|
|
|
self.add_widgets([self.entry_from, \
|
|
|
|
self.entry_to, \
|
|
|
|
self.spin_button_from, \
|
|
|
|
self.spin_button_to, \
|
|
|
|
self.combo_box])
|
2022-02-06 19:34:48 +00:00
|
|
|
self.set_spacing(20)
|
|
|
|
self.show_all()
|
|
|
|
|
2022-02-08 01:55:47 +00:00
|
|
|
self.spin_button_from.hide()
|
|
|
|
self.spin_button_to.hide()
|
|
|
|
|
2022-02-06 19:34:48 +00:00
|
|
|
|
|
|
|
def run(self):
|
2022-02-08 01:55:47 +00:00
|
|
|
new_collection = []
|
|
|
|
itr = self.combo_box.get_active_iter()
|
|
|
|
type = self.store.get(itr, 0)[0]
|
2023-01-17 04:47:28 +00:00
|
|
|
to_changes = event_system.emit_and_await("get-to")
|
2022-02-08 01:55:47 +00:00
|
|
|
|
|
|
|
if type == "Using Sub String":
|
|
|
|
fsub = self.entry_from.get_text()
|
|
|
|
tsub = self.entry_to.get_text()
|
2022-02-06 19:34:48 +00:00
|
|
|
|
|
|
|
print(f"From: {fsub}\nTo: {tsub}")
|
2023-01-17 04:47:28 +00:00
|
|
|
for name in to_changes:
|
2023-02-21 22:27:44 +00:00
|
|
|
try:
|
|
|
|
startIndex = name.index(f"{fsub}") + 1
|
|
|
|
endIndex = name.index(f"{tsub}")
|
|
|
|
toRemove = name[startIndex:endIndex]
|
|
|
|
new_collection.append(name.replace(toRemove, ''))
|
|
|
|
except Exception as e:
|
|
|
|
new_collection.append(name)
|
2022-02-08 01:55:47 +00:00
|
|
|
if type == "Using Index":
|
|
|
|
fsub = self.spin_button_from.get_value_as_int()
|
|
|
|
tsub = self.spin_button_to.get_value_as_int()
|
|
|
|
|
|
|
|
print(f"From: {fsub}\nTo: {tsub}")
|
2023-01-17 04:47:28 +00:00
|
|
|
for name in to_changes:
|
2022-02-08 01:55:47 +00:00
|
|
|
toRemove = name[fsub:tsub]
|
|
|
|
new_collection.append(name.replace(toRemove, ''))
|
2022-02-06 19:34:48 +00:00
|
|
|
|
2023-01-17 04:47:28 +00:00
|
|
|
event_system.emit("set-to", (new_collection,))
|
|
|
|
event_system.emit("update-to")
|
2022-02-08 01:55:47 +00:00
|
|
|
|
|
|
|
def _combo_box_changed(self, widget, eve=None):
|
|
|
|
itr = widget.get_active_iter()
|
|
|
|
type = self.store.get(itr, 0)[0]
|
|
|
|
|
|
|
|
if type == "Using Sub String":
|
|
|
|
self.entry_from.show()
|
|
|
|
self.entry_to.show()
|
|
|
|
self.spin_button_from.hide()
|
|
|
|
self.spin_button_to.hide()
|
|
|
|
else:
|
|
|
|
self.entry_from.hide()
|
|
|
|
self.entry_to.hide()
|
|
|
|
self.spin_button_from.show()
|
|
|
|
self.spin_button_to.show()
|