diff --git a/2022-02-05-145453_3840x1080_scrot.png b/2022-02-05-145453_3840x1080_scrot.png deleted file mode 100644 index 222b588..0000000 Binary files a/2022-02-05-145453_3840x1080_scrot.png and /dev/null differ diff --git a/src/core/controller.py b/src/core/controller.py index 448adeb..37f0ab6 100644 --- a/src/core/controller.py +++ b/src/core/controller.py @@ -68,7 +68,7 @@ class Controller(Gtk.Box, CommonWidgetGeneratorMixin): file_choser.add_filter(file_filter) label = Gtk.Label(label="Bulk Action Type: ") - data = ["Insert", "Replace", "Remove", "Remove From / To", "Case", "Time"] + data = ["Insert", "Replace", "Remove", "Remove From / To", "Move Substring", "Case", "Time"] self.store, self.combo_box = self._create_combobox_widget(data) add_button = Gtk.Button(label="Add Action") diff --git a/src/core/widgets/__init__.py b/src/core/widgets/__init__.py index 9c73bb7..b3912f8 100644 --- a/src/core/widgets/__init__.py +++ b/src/core/widgets/__init__.py @@ -4,3 +4,4 @@ from .time import Time from .replace import Replace from .remove import Remove from .remove_from_to import RemoveFromTo +from .move_substring import MoveSubstring diff --git a/src/core/widgets/case.py b/src/core/widgets/case.py index 07cc61f..06873e5 100644 --- a/src/core/widgets/case.py +++ b/src/core/widgets/case.py @@ -15,6 +15,7 @@ from mixins import CommonActionsMixin class Case(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(Case, self).__init__() + self._name = "Case" data = ["Title Case", "UPPER", "lower", "InVert CaSe --> iNvERT cAsE"] self.store, self.combo_box = self._create_combobox_widget(data) diff --git a/src/core/widgets/insert.py b/src/core/widgets/insert.py index 1f2f297..1b940b0 100644 --- a/src/core/widgets/insert.py +++ b/src/core/widgets/insert.py @@ -16,6 +16,7 @@ from mixins import CommonActionsMixin class Insert(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(Insert, self).__init__() + self._name = "Insert" self.insert_entry = Gtk.Entry() self.insert_entry.set_hexpand(True) diff --git a/src/core/widgets/move_substring.py b/src/core/widgets/move_substring.py new file mode 100644 index 0000000..38754cc --- /dev/null +++ b/src/core/widgets/move_substring.py @@ -0,0 +1,100 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports +from mixins import CommonWidgetGeneratorMixin +from mixins import CommonActionsMixin + + + + +class MoveSubstring(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): + def __init__(self): + super(MoveSubstring, self).__init__() + self._name = "Move Substring" + + 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() + self.spin_button_insert_index = self._create_spinbutton_widget() + + self.entry_from.set_hexpand(True) + self.entry_to.set_hexpand(True) + 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.spin_button_insert_index.set_sensitive(True) + + self.entry_from.set_placeholder_text("Substring Start...") + self.entry_to.set_placeholder_text("Substring End...") + + data = ["Using Sub String", "Using Index"] + self.store, self.combo_box = self._create_combobox_widget(data) + + self.add_widgets([self.entry_from, \ + self.entry_to, \ + self.spin_button_from, \ + self.spin_button_to, \ + self.spin_button_insert_index, \ + self.combo_box]) + self.set_spacing(20) + self.show_all() + + self.spin_button_from.hide() + self.spin_button_to.hide() + + + def run(self): + new_collection = [] + itr = self.combo_box.get_active_iter() + type = self.store.get(itr, 0)[0] + to_changes = event_system.emit_and_await("get-to") + insert_index = self.spin_button_insert_index.get_value_as_int() + + if type == "Using Sub String": + fsub = self.entry_from.get_text() + tsub = self.entry_to.get_text() + + print(f"From: {fsub}\nTo: {tsub}\Move To index: {insert_index}") + for name in to_changes: + try: + startIndex = name.index(f"{fsub}") + endIndex = name.index(f"{tsub}") + 1 + toMove = name[startIndex:endIndex] + str1 = name.replace(toMove, '') + new_collection.append(str1[:insert_index] + toMove + str1[insert_index:]) + except Exception as e: + new_collection.append(name) + 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}") + for name in to_changes: + toMove = name[fsub:tsub] + str1 = name.replace(toMove, '') + new_collection.append(str1[:insert_index] + toMove + str1[insert_index:]) + + event_system.emit("set-to", (new_collection,)) + event_system.emit("update-to") + + 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() diff --git a/src/core/widgets/remove.py b/src/core/widgets/remove.py index 8955309..956608b 100644 --- a/src/core/widgets/remove.py +++ b/src/core/widgets/remove.py @@ -15,6 +15,7 @@ from mixins import CommonActionsMixin class Remove(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(Remove, self).__init__() + self._name = "Remove" self.entry_from = Gtk.Entry() diff --git a/src/core/widgets/remove_from_to.py b/src/core/widgets/remove_from_to.py index d53c3e5..6aaf2f9 100644 --- a/src/core/widgets/remove_from_to.py +++ b/src/core/widgets/remove_from_to.py @@ -15,6 +15,7 @@ from mixins import CommonActionsMixin class RemoveFromTo(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(RemoveFromTo, self).__init__() + self._name = "Remove From / To" self.entry_from = Gtk.Entry() self.entry_to = Gtk.Entry() @@ -57,10 +58,13 @@ class RemoveFromTo(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): print(f"From: {fsub}\nTo: {tsub}") for name in to_changes: - startIndex = name.index(fsub) + 1 - endIndex = name.index(tsub) - toRemove = name[startIndex:endIndex] - new_collection.append(name.replace(toRemove, '')) + 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) if type == "Using Index": fsub = self.spin_button_from.get_value_as_int() tsub = self.spin_button_to.get_value_as_int() diff --git a/src/core/widgets/replace.py b/src/core/widgets/replace.py index c7377fe..7a31d07 100644 --- a/src/core/widgets/replace.py +++ b/src/core/widgets/replace.py @@ -15,6 +15,7 @@ from mixins import CommonActionsMixin class Replace(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(Replace, self).__init__() + self._name = "Replace" self.entry_from = Gtk.Entry() self.entry_to = Gtk.Entry() diff --git a/src/core/widgets/time.py b/src/core/widgets/time.py index 53049c6..fd399af 100644 --- a/src/core/widgets/time.py +++ b/src/core/widgets/time.py @@ -16,6 +16,7 @@ from mixins import CommonActionsMixin class Time(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin): def __init__(self): super(Time, self).__init__() + self._name = "Time" label = Gtk.Label(label="Time: ") self.insert_entry = Gtk.Entry() diff --git a/user_config/bin/bulkr b/user_config/bin/bulkr new file mode 100755 index 0000000..4530868 --- /dev/null +++ b/user_config/bin/bulkr @@ -0,0 +1,28 @@ +#!/bin/bash + +# . CONFIG.sh + +# set -o xtrace ## To debug scripts +# set -o errexit ## To exit on error +# set -o errunset ## To exit if a variable is referenced but not set + + +function main() { + call_path=`pwd` + path="" + + if [[ ! "${1::1}" == /* ]]; then + path="${call_path}/${1}" + else + path="${1}" + fi + + if [ ! -d "${path}" ]; then + echo "BulkR: Path given not a directory..." + exit 1 + fi + + cd "/opt/" + python ./bulkr.zip "${path}" +} +main "$@"; diff --git a/user_config/usr/applications/bulkr.desktop b/user_config/usr/applications/bulkr.desktop new file mode 100755 index 0000000..8ef7029 --- /dev/null +++ b/user_config/usr/applications/bulkr.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=BulkR +GenericName=Bulk Renamer +Comment=Bulk file renaming utility. +Exec=python /bin/bulkr %f +Icon=/usr/share/bulkr/bulkr.png +Type=Application +StartupNotify=true +Categories=System;FileTools;Utility;Core;GTK;FileManager; +Terminal=false