Site Sponsors:
PyDAO's NEW Graphical User Interface 
The Soft9000/PyDAO ("PyDAO") project now allows us to quickly create a Python Class from either a GUI, API, textual (CSV, TDF, Enpiped, etc.) data file, or using a Python Dictionary.



Workflows include (1) creating stand-alone PyDAO projects, (2) extracting PyDAO projects from textual (CSV, etc.) data files, (3) creating database code from PyDAO projects, and (4) directly creating code from textual data files. Result output-locations can also be specified.

The generated code can be used to create / drop database schema (DDL,) as well as to import & work with (C.R.U.D & query) your designed / detected / updated projects.

Project: https://github.com/soft9000/PyDAO

Project Video: https://youtu.be/azCokv4iI8k

[ view entry ] ( 219 views )   |  permalink  |  related link
REALLY easy data entry for Python... 
Had to share this one: Create a field-name dictionary, show the window, then enumerate-out the results.



Code: To see the code on GitHub, click here


[ view entry ] ( 320 views )   |  permalink  |  related link
Basic Subject Editor 
Building upon the techniques presented in our Graphical Command Line Editor, we decided to create a basic note-taking interface:



Here is the code:


#!/usr/bin/python3
from tkinter import *
from collections import OrderedDict
# Mission: Create a way to edit the subject & content of a message.

class EditorParams:
EDITBOX = "ZEDIT:"
def __init__(self, *fields):
self.params = OrderedDict()
for field in fields:
self.params[field] = ''
self.params[EditorParams.EDITBOX] = ''


class Editor:
def __init__(self):
self._dict = None
self._isOk = None
self.last_row = None
self.text = None
self.eparams = None

def _okay(self):
self._isOk = True
self.tk.quit()

def _cancel(self):
self._isOk = False
self.tk.quit()

@staticmethod
def Begin(eparams, title="Input"):
if not isinstance(eparams, EditorParams):
raise Exception("Begin: Instance of EditorParams expected.")

''' Create the frame, add the title, as well as the input fields.'''
self = Editor()
self.tk = Tk()

self.eparams = eparams
if self.eparams.params[EditorParams.EDITBOX] is None:
self.eparams.params[EditorParams.EDITBOX] = ""

self._dict = OrderedDict()

if title:
self.tk.title(title)

self.last_row = 0
# zFields (A Label, plus an Entry, in a grid layout)
for ref in self.eparams.params:
if ref == EditorParams.EDITBOX:
continue
obj = Label(master=self.tk, text=str(ref))
obj.grid(row=self.last_row, column=0)

if self.eparams.params[ref] is None:
self.eparams.params[ref] = ''

obj = Entry(master=self.tk, bd=5, width=50)
obj.grid(row=self.last_row, column=1)
obj.insert(0, self.eparams.params[ref])

self._dict[ref]=obj
self.last_row += 1
return self

@staticmethod
def End(prompter):
''' Add the closing edit area, buttons, center, and pack the Frame.'''
if prompter.last_row is None:
return False
if isinstance(prompter, Editor) is False:
return False

# zNotepad
bottom = Frame(prompter.tk)
bottom.grid(row=prompter.last_row, columnspan=2)
prompter.text = Text(bottom, height=25, width=50)
prompter.text.pack()
prompter.text.insert(END, prompter.eparams.params[EditorParams.EDITBOX])
prompter.last_row += 1

# zButtons (A Frame in the grid, plus the properly-centered pair of buttons)
bottom = Frame(prompter.tk)
bottom.grid(row=prompter.last_row, columnspan=2)
btn = Button(bottom, text="Okay", command=prompter._okay)
btn.pack(side=LEFT, pady=12)

btn = Button(bottom, text="Cancel", command=prompter._cancel)
btn.pack(side=RIGHT, padx=10)

# zCenter (Close enough to make no odds?)
width = prompter.tk.winfo_screenwidth()
height = prompter.tk.winfo_screenheight()
x = (width - prompter.tk.winfo_reqwidth()) / 2
y = (height - prompter.tk.winfo_reqheight()) / 2
prompter.tk.geometry("+%d+%d" % (x, y))

return True

def show(self):
from collections import OrderedDict
self.tk.mainloop()
try:
results = OrderedDict()
if self._isOk is not True:
return results

for ref in self._dict.keys():
results[ref] = (self._dict[ref]).get()
results[EditorParams.EDITBOX] = self.text.get("1.0", "end-1c")
return results
finally:
try:
self.tk.destroy()
except:
pass

@staticmethod
def Prompt(*fields, title="Input"):
''' Basic mission statement completed. '''
self = Editor.Begin(*fields, title=title)
if Editor.End(self) is False:
raise Exception("AddButtons: Unexpected Error.")
return self.show()


if __name__ == "__main__":
# Here is how we would use the Editor from a Console Program:
order = EditorParams("Preamble:", "Subject:")
order.params["Subject:"] = "of a modern ..."
order.params["Preamble:"] = "I am the very model ..."
order.params[EditorParams.EDITBOX] = "Python interface."
results = Editor.Prompt(order, title="Just Do It!")
if len(results) is 0:
print("Pressed Cancel - no values!")
else:
print("Pressed Okay - got values!")
for ref in results:
print(ref, results[ref])


New to this edition is the "Model View Controller" flavor, wherein we need to create + provide an EditorParams so as to support the mission statement (i.e. adding notes to a data record.)

Enjoy!

(NEW TODAY: Code now available on GitHub)


[ view entry ] ( 365 views )   |  permalink  |  related link

<<First <Back | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Next> Last>>