added name attrib and try catch guard, cleaned up configs

This commit is contained in:
itdominator 2023-02-21 16:27:44 -06:00
parent 3e0b79551a
commit aa0d738ced
12 changed files with 153 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

28
user_config/bin/bulkr Executable file
View File

@ -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 "$@";

View File

@ -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