diff --git a/nitkarshchourasia/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py b/nitkarshchourasia/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py new file mode 100644 index 00000000000..6eddf2d6b85 --- /dev/null +++ b/nitkarshchourasia/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py @@ -0,0 +1,431 @@ +from tkinter import * + +# To install hupper, use: "pip install hupper" +# On CMD, or Terminal. +import hupper + + +# Python program to create a simple GUI +# calculator using Tkinter + +# Importing everything from tkinter module + +# globally declare the expression variable +# Global variables are those variables that can be accessed and used inside any function. +global expression, equation +expression = "" + + +def start_reloader(): + """Adding a live server for tkinter test GUI, which reloads the GUI when the code is changed.""" + reloader = hupper.start_reloader("p1.main") + + +# Function to update expression +# In the text entry box +def press(num): + """Function to update expression in the text entry box. + + Args: + num (int): The number to be input to the expression. + """ + # point out the global expression variable + global expression, equation + + # concatenation of string + expression = expression + str(num) + + # update the expression by using set method + equation.set(expression) + + +# Function to evaluate the final expression +def equalpress(): + """Function to evaluate the final expression.""" + # Try and except statement is used + # For handling the errors like zero + # division error etc. + + # Put that code inside the try block + # which may generate the error + + try: + global expression, equation + # eval function evaluate the expression + # and str function convert the result + # into string + + #! Is using eval() function, safe? + #! Isn't it a security risk?! + + total = str(eval(expression)) + equation.set(total) + + # Initialize the expression variable + # by empty string + + expression = "" + + # if error is generate then handle + # by the except block + + except: + equation.set(" Error ") + expression = "" + + +# Function to clear the contents +# of text entry box + + +def clear_func(): + """Function to clear the contents of text entry box.""" + global expression, equation + expression = "" + equation.set("") + + +def close_app(): + """Function to close the app.""" + global gui # Creating a global variable + return gui.destroy() + + +# Driver code +def main(): + """Driver code for the GUI calculator.""" + # create a GUI window + + global gui # Creating a global variable + gui = Tk() + global equation + equation = StringVar() + + # set the background colour of GUI window + gui.configure(background="grey") + + # set the title of GUI window + gui.title("Simple Calculator") + + # set the configuration of GUI window + gui.geometry("270x160") + + # StringVar() is the variable class + # we create an instance of this class + + # create the text entry box for + # showing the expression . + + expression_field = Entry(gui, textvariable=equation) + + # grid method is used for placing + # the widgets at respective positions + # In table like structure. + + expression_field.grid(columnspan=4, ipadx=70) + + # create a Buttons and place at a particular + # location inside the root windows. + # when user press the button, the command or + # function affiliated to that button is executed. + + # Embedding buttons to the GUI window. + # Button 1 = int(1) + button1 = Button( + gui, + text=" 1 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(1), + height=1, + width=7, + ) + button1.grid(row=2, column=0) + + # Button 2 = int(2) + button2 = Button( + gui, + text=" 2 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(2), + height=1, + width=7, + ) + button2.grid(row=2, column=1) + + # Button 3 = int(3) + button3 = Button( + gui, + text=" 3 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(3), + height=1, + width=7, + ) + button3.grid(row=2, column=2) + + # Button 4 = int(4) + button4 = Button( + text=" 4 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(4), + height=1, + width=7, + ) + button4.grid(row=3, column=0) + + # Button 5 = int(5) + button5 = Button( + text=" 5 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(5), + height=1, + width=7, + ) + button5.grid(row=3, column=1) + + # Button 6 = int(6) + button6 = Button( + text=" 6 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(6), + height=1, + width=7, + ) + button6.grid(row=3, column=2) + + # Button 7 = int(7) + button7 = Button( + text=" 7 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(7), + height=1, + width=7, + ) + button7.grid(row=4, column=0) + + # Button 8 = int(8) + button8 = Button( + text=" 8 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(8), + height=1, + width=7, + ) + button8.grid(row=4, column=1) + + # Button 9 = int(9) + button9 = Button( + text=" 9 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(9), + height=1, + width=7, + ) + button9.grid(row=4, column=2) + + # Button 0 = int(0) + button0 = Button( + text=" 0 ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press(0), + height=1, + width=7, + ) + button0.grid(row=5, column=0) + + # Embedding the operator buttons. + + # Button + = inputs "+" operator. + plus = Button( + gui, + text=" + ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press("+"), + height=1, + width=7, + ) + plus.grid(row=2, column=3) + + # Button - = inputs "-" operator. + minus = Button( + gui, + text=" - ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press("-"), + height=1, + width=7, + ) + minus.grid(row=3, column=3) + + # Button * = inputs "*" operator. + multiply = Button( + gui, + text=" * ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press("*"), + height=1, + width=7, + ) + multiply.grid(row=4, column=3) + + # Button / = inputs "/" operator. + divide = Button( + gui, + text=" / ", + fg="#FFFFFF", + bg="#000000", + command=lambda: press("/"), + height=1, + width=7, + ) + divide.grid(row=5, column=3) + + # Button = = inputs "=" operator. + equal = Button( + gui, + text=" = ", + fg="#FFFFFF", + bg="#000000", + command=equalpress, + height=1, + width=7, + ) + equal.grid(row=5, column=2) + + # Button Clear = clears the input field. + clear = Button( + gui, + text="Clear", + fg="#FFFFFF", + bg="#000000", + command=clear_func, + height=1, + width=7, + ) + clear.grid(row=5, column=1) # Why this is an in string, the column? + + # Button . = inputs "." decimal in calculations. + Decimal = Button( + gui, + text=".", + fg="#FFFFFF", + bg="#000000", + command=lambda: press("."), + height=1, + width=7, + ) + Decimal.grid(row=6, column=0) + + # gui.after(1000, lambda: gui.focus_force()) # What is this for? + # gui.after(1000, close_app) + + gui.mainloop() + + +class Metadata: + def __init__(self): + # Author Information + self.author_name = "Nitkarsh Chourasia" + self.author_email = "playnitkarsh@gmail.com" + self.gh_profile_url = "https://github.com/NitkarshChourasia" + self.gh_username = "NitkarshChourasia" + + # Project Information + self.project_name = "Simple Calculator" + self.project_description = ( + "A simple calculator app made using Python and Tkinter." + ) + self.project_creation_date = "30-09-2023" + self.project_version = "1.0.0" + + # Edits + self.original_author = "Nitkarsh Chourasia" + self.original_author_email = "playnitkarsh@gmail.com" + self.last_edit_date = "30-09-2023" + self.last_edit_author = "Nitkarsh Chourasia" + self.last_edit_author_email = "playnitkarsh@gmail.com" + self.last_edit_author_gh_profile_url = "https://github.com/NitkarshChourasia" + self.last_edit_author_gh_username = "NitkarshChourasia" + + def display_author_info(self): + """Display author information.""" + print(f"Author Name: {self.author_name}") + print(f"Author Email: {self.author_email}") + print(f"GitHub Profile URL: {self.gh_profile_url}") + print(f"GitHub Username: {self.gh_username}") + + def display_project_info(self): + """Display project information.""" + print(f"Project Name: {self.project_name}") + print(f"Project Description: {self.project_description}") + print(f"Project Creation Date: {self.project_creation_date}") + print(f"Project Version: {self.project_version}") + + def display_edit_info(self): + """Display edit information.""" + print(f"Original Author: {self.original_author}") + print(f"Original Author Email: {self.original_author_email}") + print(f"Last Edit Date: {self.last_edit_date}") + print(f"Last Edit Author: {self.last_edit_author}") + print(f"Last Edit Author Email: {self.last_edit_author_email}") + print( + f"Last Edit Author GitHub Profile URL: {self.last_edit_author_gh_profile_url}" + ) + print(f"Last Edit Author GitHub Username: {self.last_edit_author_gh_username}") + + def open_github_profile(self) -> None: + """Open the author's GitHub profile in a new tab.""" + import webbrowser + + return webbrowser.open_new_tab(self.gh_profile_url) + + +if __name__ == "__main__": + # start_reloader() + main() + + # # Example usage: + # metadata = Metadata() + + # # Display author information + # metadata.display_author_info() + + # # Display project information + # metadata.display_project_info() + + # # Display edit information + # metadata.display_edit_info() + +# TODO: More features to add: +# Responsive design is not there. +# The program is not OOP based, there is lots and lots of repetitions. +# Bigger fonts. +# Adjustable everything. +# Default size, launch, but customizable. +# Adding history. +# Being able to continuosly operate on a number. +# What is the error here, see to it. +# To add Author Metadata. + +# TODO: More features will be added, soon. + + +# Working. +# Perfect. +# Complete. +# Do not remove the comments, they make the program understandable. +# Thank you. :) ❤️ +# Made with ❤️ diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png b/nitkarshchourasia/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png new file mode 100644 index 00000000000..699c362b46a Binary files /dev/null and b/nitkarshchourasia/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png differ diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/db.sqlite3 b/nitkarshchourasia/django_projects/ToDo_webapp/db.sqlite3 new file mode 100644 index 00000000000..8cfe025a904 Binary files /dev/null and b/nitkarshchourasia/django_projects/ToDo_webapp/db.sqlite3 differ diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/manage.py b/nitkarshchourasia/django_projects/ToDo_webapp/manage.py new file mode 100644 index 00000000000..5f76663dd2c --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_site.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/__init__.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py new file mode 100644 index 00000000000..bc4a2a3d232 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Todo + +# Register your models here. + +admin.site.register(Todo) diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py new file mode 100644 index 00000000000..c6fe8a1a75d --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TodoConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "todo" diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py new file mode 100644 index 00000000000..11fda28ba07 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py @@ -0,0 +1,8 @@ +from django import forms +from .models import Todo + + +class TodoForm(forms.ModelForm): + class Meta: + model = Todo + fields = "__all__" diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/0001_initial.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/0001_initial.py new file mode 100644 index 00000000000..71ce3e8d531 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.5 on 2023-09-30 16:11 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Todo", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("details", models.TextField()), + ("date", models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + ] diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/__init__.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py new file mode 100644 index 00000000000..96e4db39faa --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py @@ -0,0 +1,14 @@ +from typing import Any +from django.db import models +from django.utils import timezone + +# Create your models here. + + +class Todo(models.Model): + title = models.CharField(max_length=100) + details = models.TextField() + date = models.DateTimeField(default=timezone.now) + + def __str__(self) -> str: + return self.title diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/templates/todo/index.html b/nitkarshchourasia/django_projects/ToDo_webapp/todo/templates/todo/index.html new file mode 100644 index 00000000000..fa77155bcea --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/templates/todo/index.html @@ -0,0 +1,95 @@ + + + + + + + {{title}} + + + + + + + + + + + + {% if messages %} + {% for message in messages %} +
+ {{message}} +
+ {% endfor %} + {% endif %} + +
+

__TODO LIST__

+
+
+ +
+ +
+ + {% for i in list %} +
+
{{i.title}}
+
+ {{i.date}} +
+ {{i.details}} +
+
+
+ {% csrf_token %} + +
+
+ {% endfor%} +
+
+
+
+
+ {% csrf_token %} + {{forms}} +
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py new file mode 100644 index 00000000000..7ce503c2dd9 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py new file mode 100644 index 00000000000..931228df1ec --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render, redirect +from django.contrib import messages + +# Create your views here. + +# Import todo form and models + +from .forms import TodoForm +from .models import Todo + + +def index(request): + item_list = Todo.objects.order_by("-date") + if request.method == "POST": + form = TodoForm(request.POST) + if form.is_valid(): + form.save() + return redirect("todo") + form = TodoForm() + + page = { + "forms": form, + "list": item_list, + "title": "TODO LIST", + } + + return render(request, "todo/index.html", page) + + ### Function to remove item, it receives todo item_id as primary key from url ## + +def remove(request, item_id): + item = Todo.objects.get(id=item_id) + item.delete() + messages.info(request, "item removed !!!") + return redirect("todo") diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/__init__.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py new file mode 100644 index 00000000000..dde18f50c17 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for todo_site project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_site.settings") + +application = get_asgi_application() diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py new file mode 100644 index 00000000000..12e70bf4571 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for todo_site project. + +Generated by 'django-admin startproject' using Django 4.2.5. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-5xdo&zrjq^i)0^g9v@_2e_r6+-!02807i$1pjhcm=19m7yufbz" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "todo", + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "todo_site.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "todo_site.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py new file mode 100644 index 00000000000..226e326827f --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py @@ -0,0 +1,25 @@ +""" +URL configuration for todo_site project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from todo import views + +urlpatterns = [ + path("", views.index, name="todo"), + path("del/", views.remove, name="del"), + path("admin/", admin.site.urls), +] diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/wsgi.py b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/wsgi.py new file mode 100644 index 00000000000..5b71d7ed7a9 --- /dev/null +++ b/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for todo_site project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_site.settings") + +application = get_wsgi_application()