1

Topic: Python script to generate vertical line numbers for ladder style

I have been bending QElectroTech to do my bidding which right now is ladder style diagrams. I still see a huge number of these style diagrams even on new equipment here in the USA.

Input: Starting number, Increment, Y increment in pixels, Max height in pixels. It will generate code to copy to the clipboard which you can then paste into your folio in QElectroTech.

2

Re: Python script to generate vertical line numbers for ladder style

Saw file did not show up, here is the code itself you could copy and paste to a new python file:

import tkinter as tk
from tkinter import ttk, scrolledtext

HTML_TEMPLATE = '''        <input y="{y}" x="0" text="&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;>&#xa;&lt;html>&lt;head>&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; />&lt;style type=&quot;text/css&quot;>&#xa;p, li {{ white-space: pre-wrap; }}&#xa;&lt;/style>&lt;/head>&lt;body style=&quot; font-family:'Liberation Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;>&#xa;&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;>{number}&lt;/p>&lt;/body>&lt;/html>" font="Liberation Sans,9,-1,5,50,0,0,0,0,0,Regular" rotation="0"/>'''

def generate():
    try:
        start = int(entry_start.get())
        step = int(entry_step.get())
        y_step = int(entry_ystep.get())
        max_height = int(entry_maxheight.get())
    except ValueError:
        output_text.delete('1.0', tk.END)
        output_text.insert(tk.END, "Please enter valid integers.")
        return

    count = max_height // y_step
    inputs = []
    for i in range(count):
        number = start + i * step
        y = i * y_step
        inputs.append(HTML_TEMPLATE.format(number=number, y=y))

    full_output = "<diagram projectId=\"0\">\n    <inputs>\n" + "\n".join(inputs) + "\n    </inputs>\n</diagram>"

    output_text.delete('1.0', tk.END)
    output_text.insert(tk.END, full_output)

def copy_to_clipboard():
    root.clipboard_clear()
    root.clipboard_append(output_text.get('1.0', tk.END))
    root.update()

# GUI Setup
root = tk.Tk()
root.title("QElectroTech JIC-NFPA Number Generator")

frm = ttk.Frame(root, padding=10)
frm.grid(row=0, column=0)

ttk.Label(frm, text="Starting Number:").grid(column=0, row=0, sticky="e")
entry_start = ttk.Entry(frm)
entry_start.insert(0, "101")
entry_start.grid(column=1, row=0)

ttk.Label(frm, text="Increment:").grid(column=0, row=1, sticky="e")
entry_step = ttk.Entry(frm)
entry_step.insert(0, "1")
entry_step.grid(column=1, row=1)

ttk.Label(frm, text="Y Increment (px):").grid(column=0, row=2, sticky="e")
entry_ystep = ttk.Entry(frm)
entry_ystep.insert(0, "20")
entry_ystep.grid(column=1, row=2)

ttk.Label(frm, text="Max Height (px):").grid(column=0, row=3, sticky="e")
entry_maxheight = ttk.Entry(frm)
entry_maxheight.insert(0, "300")
entry_maxheight.grid(column=1, row=3)

ttk.Button(frm, text="Generate", command=generate).grid(column=0, row=4, columnspan=2, pady=(10, 2))
ttk.Button(frm, text="Copy to Clipboard", command=copy_to_clipboard).grid(column=0, row=5, columnspan=2)

output_text = scrolledtext.ScrolledText(root, width=100, height=25)
output_text.grid(row=1, column=0, padx=10, pady=10)

root.mainloop()