BulkR/src/core/widgets/case.py

52 lines
1.5 KiB
Python
Raw Normal View History

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 Case(Gtk.Box, CommonWidgetGeneratorMixin, CommonActionsMixin):
2022-02-06 19:34:48 +00:00
def __init__(self):
super(Case, self).__init__()
self._name = "Case"
2022-02-06 19:34:48 +00:00
data = ["Title Case", "UPPER", "lower", "InVert CaSe --> iNvERT cAsE"]
self.store, self.combo_box = self._create_combobox_widget(data)
2022-02-07 06:29:25 +00:00
self.combo_box.set_hexpand(True)
2022-02-06 19:34:48 +00:00
2022-02-07 06:29:25 +00:00
self.add_widgets([self.combo_box])
2022-02-06 19:34:48 +00:00
self.set_spacing(20)
self.show_all()
def run(self):
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-06 19:34:48 +00:00
print(f"Changing Case...")
if type == "Title Case":
2023-01-17 04:47:28 +00:00
for name in to_changes:
2022-02-06 19:34:48 +00:00
new_collection.append(name.title())
if type == "UPPER":
2023-01-17 04:47:28 +00:00
for name in to_changes:
2022-02-06 19:34:48 +00:00
new_collection.append(name.upper())
if type == "lower":
2023-01-17 04:47:28 +00:00
for name in to_changes:
2022-02-06 19:34:48 +00:00
new_collection.append(name.lower())
if type == "InVert CaSe --> iNvERT cAsE":
2023-01-17 04:47:28 +00:00
for name in to_changes:
2022-02-06 19:34:48 +00:00
new_collection.append(name.swapcase())
2023-01-17 04:47:28 +00:00
event_system.emit("set-to", (new_collection,))
event_system.emit("update-to")