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

some ui-changes and features #11

Open
wants to merge 4 commits into
base: main
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.DS_Store
.DS_Store
.vscode/settings.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ Hit "Send to Farm" to upload all files in the folder to your print farm. The log

## Todo

- Test on printers other than BambuLab P1P
- Test on printers other than BambuLab P1P and P1S
- Support deleting existing files from the printer's SD
- Handle uploading files that share a name with an existing file on the SD
14 changes: 14 additions & 0 deletions settings-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
"printers": [
{
"name": "Printer #1",
"group": "B",
"ip": "192.168.1.1",
"pw": "12345678"
},
{
"name": "Printer #2",
"group": "A",
"ip": "192.168.1.2",
"pw": "12345678"
},
{
"name": "Printer #3",
"group": "B",
"ip": "192.168.1.3",
"pw": "12345678"
},
{
"name": "Printer #4",
"group": "A",
"ip": "192.168.1.4",
"pw": "12345678"
}
]
}
182 changes: 39 additions & 143 deletions src/FarmUpload.py
Original file line number Diff line number Diff line change
@@ -1,160 +1,56 @@
import tkinter as tk
from tkinter import filedialog
import tkinter.scrolledtext as st
import json, os
import threading, queue
import customtkinter as CTk
from typing import Literal
from gui.SelectSettings import SelectSettings
from gui.Main import Main

from Printer import Printer
from Log import Logger
class App(CTk.CTk):

class App():
def __init__(self):
self.settings = None
self.printers = []
self.fileDirectory = ""

self.ui = tk.Tk()
self.loadUI()

self.logQueue = queue.Queue()
self.log = Logger(self.logUI)

self.ui.after(50, self.processQueue)

self.ui.mainloop()

def loadSettings(self):

settingsDirectory = filedialog.askopenfilename()
self.s.config(text=os.path.basename(settingsDirectory))
f = open(settingsDirectory)
self.settings = json.load(f)
f.close()

# loading printers into app printer array

for printer in self.settings["printers"]:
var = tk.BooleanVar()
self.printers.append(Printer(
name = printer["name"],
ip = printer["ip"],
pw = printer["pw"],
enabled = var
))

checkbox = tk.Checkbutton(self.printerSelectFrame, text=printer["name"], variable=var, onvalue=True, offvalue=False)
checkbox.pack(side=tk.LEFT, pady=10)

self.s.update_idletasks()

def loadUI(self):

self.ui.title("FarmUpload")

w = tk.Label(self.ui, text='Select the printers to send to:')
w.pack()

choose_settings_button = tk.Button(self.ui, text="Choose Settings JSON File", command=self.loadSettings)
choose_settings_button.pack(pady=10, padx=10)

self.s = tk.Label(self.ui, text='No settings file selected')
self.s.pack(pady=10, padx=10)

select_printers = tk.Label(self.ui, text="Select which printers to send to:")
select_printers.pack(pady=10)

self.printerSelectFrame = tk.Frame(master=self.ui, highlightbackground="black", highlightthickness=1)
self.printerSelectFrame.pack()
## design GUI (https://excalidraw.com/#json=_gYLOEMIdrXcCb3VUiZ8-,gJ0XoeU5ao8QGx4KIrMM5Q)

choose_folder_button = tk.Button(self.ui, text="Choose Folder to Upload", command=self.chooseFolder)
choose_folder_button.pack(pady=10, padx=10)

self.v = tk.Label(self.ui, text='No directory selected')
self.v.pack(pady=10)

send_button = tk.Button(self.ui, text="Send to Farm", command=self.send)
send_button.pack(pady=10)
def __init__(self):
super().__init__()
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.title("Farm Upload")
self._current_window = ""

# Logging
self.main_window = None
self.printers: dict = {}
self.printers_selected: dict = {}
self.settings_path: str = None
self.settings: dict = None
self.selected_files: list = []

self.logUI = st.ScrolledText(self.ui)
self.logUI.pack()

def chooseFolder(self):
self.fileDirectory = filedialog.askdirectory()
self.v.config(text=os.path.basename(self.fileDirectory))
self.v.update_idletasks()
self.changeWindow("SelectSettings")

def processQueue(self):
try:
msg = self.logQueue.get_nowait()
self.log.write(msg)
except queue.Empty:
pass

def sendOnePrinter(self, printer, toSend):
def changeWindow(self, window_name: Literal["SelectSettings", "Main"]): # find better name to 'main'
"""Select what page to show to the user.

printer.connect()

if printer.connected:
Args:
window_name (str): page to open

self.logQueue.put("Connected to " + str(printer.name))
Raises:
NotImplementedError: if the page is not implemented
"""
if self.main_window:
self.main_window.destroy()

for filename in toSend:
try:
with open(os.path.join(self.fileDirectory,filename), 'rb') as file:
self.logQueue.put("Sending " + str(filename) + " to printer " + printer.name + "..." )

printer.ftp.storbinary(f'STOR {filename}', file)
self.logQueue.put("Success: " + str(filename) + " to printer " + printer.name)
if window_name == "SelectSettings":
self.main_window = SelectSettings(self)
self.main_window.grid(row=0, column=0, padx=25, pady=(12, 25), sticky="nsew")

except:
try:
with open(os.path.join(self.fileDirectory,filename), 'rb') as file:
self.logQueue.put("Reattempting to send " + str(filename) + " to printer " + printer["name"] + "..." )
printer.ftp.storbinary(f'STOR {filename}', file)
self.logQueue.put("Success: " + str(filename) + " to printer " + printer.name)
except:
self.logQueue.put("Failure: " + str(filename) + " to printer " + printer.name)
elif window_name == "Main":

printer.disconnect()
self.main_window = Main(self)
self.main_window.grid(row=0, column=0, padx=25, pady=(12, 25), sticky="nsew")
self._current_window = window_name

else:
self.logQueue.put("Could not connect to " + printer.name)


def send(self):

self.log.wipe()

toSend = os.listdir(self.fileDirectory)

self.log.write("Files to be sent: " + str(toSend))

printerThreads = list()

for printer in self.printers:

if printer.enabled.get():

thread = threading.Thread(target=self.sendOnePrinter, args=(printer, toSend))
printerThreads.append(thread)
thread.start()

else:
self.log.write("Skipping " + printer.name)

while any(t.is_alive() for t in printerThreads):
self.processQueue()
# keeps ui from hanging
self.ui.update()

self.processQueue()

self.logQueue.put("Process Complete!")

self.processQueue()
raise NotImplementedError(f"{window_name} window does not exist")


if __name__ == "__main__":
app = App()
app = App()

app.mainloop()
16 changes: 0 additions & 16 deletions src/Log.py

This file was deleted.

Loading