Skip to main content

Helps shorten the amount of code you write

Project description

ShrtCde (ShortCode)

A small python library for lazy devs. This shortens the amount of code you have to write for your program with the help of functions.

LICENSE

This project uses the Apache-2.0 license. For more info, check LICENSE.

INSTALLATION

pip install ShrtCde

or

pip3 install ShrtCde

EXAMPLE (IO MODULE)

An example for the IO module.

from ShrtCde.IO import *

# Feel free to mess around with the function values!

path = input("Enter file path (write): ")
data = input("Enter data to write: ")
encoding = input("Enter encoding of data: (default: utf-8)")
encoding = encoding if encoding != "" else "utf8"

split = " "
data = list(data.split(sep=split))

append = input("Append data? y/n: ")
if append == 'y': fwrite(path, data, 'a', encoding)
else: fwrite(path, data, 'w', encoding)

print('\n\n')

path = input("Enter file path (read): ")
encoding = input("Enter encoding of data: (default: utf-8)")
encoding = encoding if encoding != "" else "utf8"

if not fexists(path):
    print("File was not found. Exiting program...")
    input()
    quit()

mode = input("Enter read mode:\n-r to read whole file as string\n-rl to read first line as string\n-rls ro read whole file as list\n: ")
data = fread(path, mode, encoding)
print(data, f"\n\n TYPE: {str(type(data))}")
input()

EXAMPLE (UI MODULE)

An example for the UI module.

from tkinter import filedialog
from ShrtCde.UI import *

# Feel free to mess around with the function values!

img_path = filedialog.askopenfilename(title="OPEN PNG")

___example___ = lambda:showinfo("EXAMPLE", "EXAMPLE")

root = GetRoot(title="EXAMPLE", size="900x900", minsize="200x200", maxsize="1200x1200", color="Yellow", image=img_path)
toplevel1 = GetRoot(title="EXAMPLE", size="300x300", resize='x', mktoplevel=root)
toplevel2 = GetRoot(title="EXAMPLE", size="300x300", resize='y', mktoplevel=root)
toplevel3 = GetRoot(title="EXAMPLE", size="300x300", resize='xy', mktoplevel=root)
GetMenu(root, {"func" : ___example___, "cascade" : {"func" : ___example___, 0:0, ("QUIT", "ctrl+q") : lambda:root.quit()}})

GetLabel(root, text="label", width=20, height=2, font=GetFont(family="Terminal", size=30, weight="bold"), border=5, relief="groove", fg="green", bg="red", highlight="blue", highlightsize=5).pack()

GetLabel(toplevel1, text="example label", width=40).pack()
a,b=GetLabel(toplevel1, image=img_path, imagewidth=200, imageheight=200, width=300, height=200)
print("line20: ", b.name, type(b))
a.pack()

a,b=GetLabel(root, image=img_path, width=300, height=200)
print("line24: ", b.name, type(b))
a.pack()
GetButton(root, function=___example___, text="button", width=20, height=2, font=GetFont(family="SimSun", size=30, weight="bold"), border=5, relief="groove", fg="green", bg="red", activefg="brown", activebg="pink").pack()

GetLabel(toplevel2, text="example button", width=40).pack()
a,b=GetButton(toplevel2, function=___example___, imagewidth=200, imageheight=200, image=img_path, width=300, height=200, activefg="green", activebg="yellow")
print("line30: ", b.name, type(b))
a.pack()

a,b=GetButton(root, function=___example___, image=img_path, width=300, height=200, activefg="blue", activebg="red")
print("line34: ", b.name, type(b))
a.pack()
text=GetText(root, text="EXAMPLE", width=50, height=20, font=GetFont(family="Consolas", size=20, weight="bold"), border=5, relief="raised", insertwidth=10, insertfg="red", fg="blue", bg="green", activehighlight="white", highlight="black", highlightsize=5)
text.bind("<KeyRelease>", lambda x: print("line37: ", text.get('0.0', 'end')))
text.pack()

entry,entryvar=GetEntry(toplevel3, default="EXAMPLE", width=15, font=GetFont(family="Times New Roman"), border=10, relief="sunken", insertwidth=20, insertfg="blue", fg="green", bg="red", highlight="yellow", activehighlight="pink", highlightsize=20)
entry.bind("<KeyRelease>", lambda x: print("line41: ", entryvar.get()))
entry.pack()

def show():
    showinfo("EXAMPLE", "line45:  " + str(dropvar.get()) + "\t" + str(type(dropvar)))

# Try changing "vartype" below.
#If it's an int, GetDropdown will return an IntVar,
#if it's a float GetDropdown will return a DoubleVar,
#if it is the str "BOOL" GetDropdown will return a BooleanVar,
#if it's None, or any other str, GetDropdown will return a StringVar.
drop,dropvar=GetDropdown(toplevel3, [1, 2, 3, 4, 5, 6], vartype=None, function=show, width=20, height=2, font=GetFont(family="OCR-A-BT", size=40), border=5, relief='groove', fg="red", bg="black", activefg="blue", activebg="yellow", highlight="blue", highlightsize=10)
drop.pack()

root.bind("<Control-q>", lambda x: root.quit())
root.mainloop()

All examples will also be available in the GitHub repo.

GITHUB

https://github.com/Uralstech/ShrtCde

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ShrtCde-0.3.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ShrtCde-0.3.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file ShrtCde-0.3.2.tar.gz.

File metadata

  • Download URL: ShrtCde-0.3.2.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ShrtCde-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b9c286c16117ddf7620f992f0eea082cd9e1e2dfc4b9056d20556554b43217c0
MD5 4f269f494b7c9763cab17bd32e1208cc
BLAKE2b-256 35b09d3617c3de5913aa9a6f3778610e5e527ea00525d98fc78f1f68ed6abb9d

See more details on using hashes here.

File details

Details for the file ShrtCde-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: ShrtCde-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ShrtCde-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8370d3d4f731cc5fdfc89174906f562fb46a6b668f42721287c6c5a057e97351
MD5 671486ce0b6ada2af3f15929006f5a84
BLAKE2b-256 d88dc290c646cab1e14c31889e15baefa706e1acea00f870c6faadba4dd8102b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page