Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alphanumeric chars to append node and increase special chars list #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Mentalist",
"type": "python",
"request": "launch",
"program": "pyinstaller_stub.py",
"console": "integratedTerminal"
}
]
}
72 changes: 69 additions & 3 deletions mentalist/view/adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import locale

from .base_words import BaseWordsNode, center_window
from .const import NUMBER_LIST, DATE_FORMATS, SPECIAL_CHARACTERS
from .const import NUMBER_LIST, DATE_FORMATS, SPECIAL_CHARACTERS, ALPHANUMERIC_CHARS
from .. import model


Expand All @@ -20,6 +20,7 @@ def __init__(self, controller, master=None, main=None, type_='Append', allow_rem
self.custom_num_window = None
self.entry_string = None
self.date_format = Tk.StringVar()
self.alphanum_format = Tk.StringVar()
self.special_dlg = None
self.chk_special = []

Expand All @@ -35,9 +36,9 @@ def add_upper_button(self):
mb.menu.add_cascade(label='Words', menu=m_words, underline=0)
m_words.add_command(label='Custom File...', command=partial(self.open_file_dlg, partial(self.controller.add_attr, label='File:', right_label_text='Calculating...', node_view=self, attr_class=model.FileAttr, controller=self.controller)))
m_words.add_command(label='Custom String...', command=partial(self.open_string_popup, 'String'))

self.add_file_menu(m_words, m_words)

# In addition to BaseFile's attributes, we have numbers, dates,
# and special characters
m_numbers = Tk.Menu(mb, tearoff=0)
Expand All @@ -55,6 +56,8 @@ def add_upper_button(self):

mb.menu.add_command(label="Special Characters...", command=self.open_special_dlg)

mb.menu.add_command(label="Alphanumeric Characters...", command=self.open_alphaNumeric_dlg)

# Area and zip codes from lookup tables
for code_type in ['Area', 'Zip']:
m_area_zip = Tk.Menu(mb, tearoff=0)
Expand Down Expand Up @@ -263,3 +266,66 @@ def on_ok_special_dlg(self, *args):
label = 'Special Characters: {}'.format(' '.join(checked_vals))
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings=checked_vals)
self.cancel_special()

def open_alphaNumeric_dlg(self):
'''Open a popup for selecting alphaNumeric characters
'''
self.alphaNumeric_dlg = Tk.Toplevel()
self.alphaNumeric_dlg.withdraw()
self.alphaNumeric_dlg.title('Select AlphaNumeric Characters')
self.alphaNumeric_dlg.resizable(width=False, height=False)
frame = Tk.Frame(self.alphaNumeric_dlg)
lb = Tk.Label(frame, text='Select AlphaNumeric Characters'.format(self.title))
lb.pack(fill='both', side='top')

box = Tk.Frame(frame)
drop_down = Tk.OptionMenu(frame, self.alphanum_format, *ALPHANUMERIC_CHARS)
drop_down.configure(width=max(map(len, ALPHANUMERIC_CHARS)) + 4)
self.alphanum_format.set('a-z')
drop_down.pack(side='top')

# lb1 = Tk.Label(box, text='Number: ')
# lb1.pack(side='left', padx=5)
# self.sp_case = Tk.Spinbox(box, width=12, from_=1, to=50)
# self.sp_case.pack(side='left')

box.pack(fill='both', side='top', padx=30, pady=20)

# Ok and Cancel buttons
btn_box = Tk.Frame(frame)
btn_cancel = Tk.Button(btn_box, text='Cancel', command=self.cancel_alphaNumeric)
btn_cancel.pack(side='right', padx=10, pady=20)
btn_ok = Tk.Button(btn_box, text='Ok', command=self.on_ok_alphaNumeric_dlg)
btn_ok.pack(side='left', padx=10, pady=20)
btn_box.pack()
frame.pack(fill='both', padx=60, pady=10)

center_window(self.alphaNumeric_dlg, self.main.master)
self.alphaNumeric_dlg.focus_set()

def cancel_alphaNumeric(self, *args):
if self.alphaNumeric_dlg:
self.alphaNumeric_dlg.destroy()
self.alphaNumeric_dlg = None

def on_ok_alphaNumeric_dlg(self, *args):
'''Ok was pressed, add the alphanumeric character attribute
'''
checked_vals = self.alphanum_format.get()
# amount = self.sp_case.get()

if len(checked_vals) > 0:
label = 'AlphaNumeric Characters: {}'.format(' '.join(checked_vals))
if checked_vals == "a-z":
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings="abcdefghijklmnopqrstuvwxyz")
elif checked_vals == "A-Z":
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
elif checked_vals == "a-zA-Z":
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
elif checked_vals == "a-zA-Z0-9":
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
elif checked_vals == "0-9":
self.controller.add_attr(label=label, node_view=self, attr_class=model.StringListAttr, strings="0123456789")
self.cancel_alphaNumeric()


4 changes: 3 additions & 1 deletion mentalist/view/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

DATE_FORMATS = ['mmddyy', 'ddmmyy', 'mmddyyyy', 'ddmmyyyy', 'mmyyyy', 'mmyy', 'mmdd']

SPECIAL_CHARACTERS = '''!@#$%^&*()-=_+`~[]{}\|/:;'"'''
SPECIAL_CHARACTERS = '''!@#$%^&*()-=_+~[]{}\|/:;'"`´?§€<>°'''

SPECIAL_TYPES = ['One at a time', 'All together']

ALPHANUMERIC_CHARS = ['a-z', 'A-Z', 'a-zA-Z', 'a-zA-Z0-9', '0-9']