Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Bulky - Rename multiple files at once.
![build](https://github.com/linuxmint/bulky/actions/workflows/build.yml/badge.svg)

![image](https://user-images.githubusercontent.com/1138515/119273676-dcc8c100-bc03-11eb-95dd-841a831285cc.png)
![bulky_1](https://github.com/user-attachments/assets/d8ba440b-5223-4387-904d-62beffec6711)


Bulky is used to rename files and directories.

Expand Down
57 changes: 43 additions & 14 deletions usr/lib/bulky/bulky.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import gettext
import gi
import locale
import magic
import os
import re
import setproctitle
import subprocess
import warnings
import sys
import functools
Expand Down Expand Up @@ -313,6 +311,19 @@ def __init__(self, application):
self.replace_regex_check.connect("toggled", self.on_widget_change)
self.replace_case_check.connect("toggled", self.on_widget_change)

self.replace_start_spin = self.builder.get_object("replace_start_spin")
self.replace_start_spin.connect("value-changed", self.on_widget_change)
self.replace_start_spin.set_range(0, 10000)
self.replace_start_spin.set_value(1)
self.replace_start_spin.set_increments(1, 10)

self.replace_inc_spin = self.builder.get_object("replace_inc_spin")
self.replace_inc_spin.connect("value-changed", self.on_widget_change)
self.replace_inc_spin.set_range(1, 1000)
self.replace_inc_spin.set_value(1)
self.replace_inc_spin.set_increments(1, 10)


# Set focus chain
# Not that this is deprecated (but not implemented differently) in Gtk3.
# If we move to GTK4, we'll just drop this line of code.
Expand All @@ -328,9 +339,9 @@ def __init__(self, application):
self.remove_from_check.connect("toggled", self.on_widget_change)
self.remove_to_check.connect("toggled", self.on_widget_change)
self.remove_from_spin.set_range(1, 100)
self.remove_from_spin.set_increments(1, 1)
self.remove_from_spin.set_increments(1, 10)
self.remove_to_spin.set_range(1, 100)
self.remove_to_spin.set_increments(1, 1)
self.remove_to_spin.set_increments(1, 10)

# Insert widgets
self.insert_entry = self.builder.get_object("insert_entry")
Expand All @@ -342,7 +353,20 @@ def __init__(self, application):
self.insert_reverse_check.connect("toggled", self.on_widget_change)
self.overwrite_check.connect("toggled", self.on_widget_change)
self.insert_spin.set_range(1, 100)
self.insert_spin.set_increments(1, 1)
self.insert_spin.set_increments(1, 10)

self.insert_start_spin = self.builder.get_object("insert_start_spin")
self.insert_start_spin.connect("value-changed", self.on_widget_change)
self.insert_start_spin.set_range(0, 10000)
self.insert_start_spin.set_value(1)
self.insert_start_spin.set_increments(1, 10)

self.insert_inc_spin = self.builder.get_object("insert_inc_spin")
self.insert_inc_spin.connect("value-changed", self.on_widget_change)
self.insert_inc_spin.set_range(1, 1000)
self.insert_inc_spin.set_value(1)
self.insert_inc_spin.set_increments(1, 10)


# Case widgets
self.radio_titlecase = self.builder.get_object("radio_titlecase")
Expand All @@ -358,7 +382,7 @@ def __init__(self, application):
self.radio_accents.connect("toggled", self.on_widget_change)

# Tooltips
variables_tooltip = _("Use %n, %0n, %00n, %000n to enumerate.")
variables_tooltip = _("Use %n, %0n, %00n, %000n, etc. to enumerate.")
self.replace_entry.set_tooltip_text(variables_tooltip)
self.insert_entry.set_tooltip_text(variables_tooltip)

Expand Down Expand Up @@ -673,8 +697,12 @@ def replace_text(self, index, string):
case = self.replace_case_check.get_active()
regex = self.replace_regex_check.get_active()
find = self.find_entry.get_text()
if not find: #ignore empty search string
return string
inc = self.replace_inc_spin.get_value_as_int()
start= self.replace_start_spin.get_value_as_int()
replace = self.replace_entry.get_text()
replace = self.inject(index, replace)
replace = self.inject((index-1)*inc + start, replace)
try:
if regex:
if case:
Expand Down Expand Up @@ -710,8 +738,9 @@ def remove_text(self, index, string):

def insert_text(self, index, string):
text = self.insert_entry.get_text()
text = self.inject(index, text)
length = len(string) - 1
inc = self.insert_inc_spin.get_value_as_int()
start= self.insert_start_spin.get_value_as_int()
text = self.inject((index-1)*inc + start, text)
from_index = self.insert_spin.get_value_as_int() - 1
a = len(string)
b = len(text)
Expand Down Expand Up @@ -740,11 +769,11 @@ def change_case(self, index, string):
return unidecode.unidecode(string)

def inject(self, index, string):
string = string.replace('%n', "{:01d}".format(index))
string = string.replace('%0n', "{:02d}".format(index))
string = string.replace('%00n', "{:03d}".format(index))
string = string.replace('%000n', "{:04d}".format(index))
return string
def repl(match):
zeros = match.group(1)
width = len(zeros) + 1
return f"{index:0{width}d}"
return re.sub(r'%([0]*)n', repl, string)

'''
TODO
Expand Down
127 changes: 121 additions & 6 deletions usr/share/bulky/bulky.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="main_menu">
Expand All @@ -10,7 +10,7 @@
<property name="can-focus">False</property>
<property name="border-width">0</property>
<property name="default-width">600</property>
<property name="default-height">400</property>
<property name="default-height">500</property>
<property name="icon-name">bulky</property>
<child>
<object class="GtkBox">
Expand Down Expand Up @@ -395,10 +395,67 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Start number:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkSpinButton" id="replace_start_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Increment:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="replace_inc_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
Expand Down Expand Up @@ -449,6 +506,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -503,10 +561,67 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkSpinButton" id="insert_start_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Increment:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="insert_inc_spin">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Start number:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<placeholder/>
Expand Down