Skip to content

Commit

Permalink
git: merge pull request #5 from /develop
Browse files Browse the repository at this point in the history
  • Loading branch information
StuSerious authored Jun 1, 2023
2 parents d3d3dde + 0df1f30 commit 6031a8e
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
--name "threedy" `
--clean `
--add-data "${{ steps.customtkinter.outputs.location }}/customtkinter;customtkinter/" `
--add-data "src/threedy/components;components/" `
--add-data "src/threedy/interface;interface/" `
--add-data "src/threedy/modules;modules/" `
"src/threedy/main.py"
Expand Down
52 changes: 0 additions & 52 deletions src/threedy/components/tabview.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
116 changes: 116 additions & 0 deletions src/threedy/interface/tabview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import customtkinter as ctk
from modules.settings import *


class Tabview(ctk.CTkTabview):
def __init__(self, parent, **kwargs):
super().__init__(master=parent, **kwargs)
# defaults
self.normal_font = ctk.CTkFont(family=FONT, size=FONT_SIZE)

# setup layout
self.grid(
row=0,
column=1,
columnspan=2,
padx=PADDING["medium"],
pady=PADDING["none"],
sticky="nsew",
)
self.grid_rowconfigure(3, weight=1)

# add tabs
self.add("G-Code Tools")
self.add("CSV Tools")

# setup tabs
self.tab("G-Code Tools").grid_columnconfigure(
(0, 1),
weight=1,
)

self.select_all_gcode = ctk.CTkSwitch(
self.tab("G-Code Tools"),
text="Select All",
command=self.toggle_all_switches,
)
self.select_all_gcode.place(anchor="nw")

self.gcode_switch_data = [
{
"text": "Remove Comments",
"variable": "remove_comments_switch",
"row": 0,
"column": 1,
},
{
"text": "Remove M-Codes",
"variable": "remove_mcodes_switch",
"row": 1,
"column": 1,
},
{
"text": "Remove F/E-Codes",
"variable": "remove_fecodes_switch",
"row": 2,
"column": 1,
},
{
"text": "Keep only G0 & G1 moves",
"variable": "remove_nontravel_switch",
"row": 0,
"column": 2,
},
{
"text": "Remove lines with lonely G0/G1s",
"variable": "remove_lone_gs_switch",
"row": 1,
"column": 2,
},
{
"text": "Remove coordinate names",
"variable": "remove_coordname_switch",
"row": 2,
"column": 2,
},
]

for data in self.gcode_switch_data:
switch_variable = data["variable"]
switch = ctk.CTkCheckBox(
self.tab("G-Code Tools"),
text=data["text"],
font=self.normal_font,
onvalue=True,
offvalue=False,
)
setattr(self, switch_variable, switch)
switch.grid(
row=data["row"],
column=data["column"],
padx=PADDING["small"],
pady=PADDING["small"],
sticky="W",
)

def toggle_all_switches(self):
"""iterates over every switch and toggles it"""
for data in self.gcode_switch_data:
switch_variable = data["variable"]
if isinstance(switch_variable, str):
# Get the actual variable object based on its name
switch_variable = getattr(self, switch_variable)
if self.select_all_gcode.get() == False:
switch_variable.deselect()
self.select_all_gcode.configure(text="Select All")
else:
switch_variable.select()
self.select_all_gcode.configure(text="Deselect All")

def selected_tab(self):
"""Returns the currently selected tab
Returns:
string: current tab name
"""
return self.get()
File renamed without changes.
51 changes: 32 additions & 19 deletions src/threedy/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import sys

import customtkinter as ctk
from components.commandbar import Commandbar
from components.sidebar import Sidebar
from components.tabview import Tabview
from components.terminal import Terminal
from interface.commandbar import Commandbar
from interface.sidebar import Sidebar
from interface.tabview import Tabview
from interface.terminal import Terminal
from modules.compute import process_file_contents
from modules.dialogs import export_file_dialog, select_file_dialog
from modules.settings import *
Expand All @@ -11,20 +14,10 @@
# PyInstaller helper
# https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile/13790741#13790741
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller
Args:
relative_path (string): the relative path of the resource
Returns:
string: the base pass joined with the relative path
"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
try: # PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)


Expand All @@ -34,7 +27,7 @@ def __init__(self):

# setup window
self.geometry(f"{APP_SIZE['width']}x{APP_SIZE['height']}")
# self.iconbitmap("src//threedy//resources//logo.ico")
self.iconbitmap(resource_path("src\\threedy\\resources\\logo.ico"))
self.title("threedy")

# setup grid
Expand Down Expand Up @@ -74,12 +67,32 @@ def on_file_select(self):
self.terminal.newline("File selected: " + self.file_path + "\n\n")

def on_file_export(self):
self.focused_tab = self.tabview.focused_tab()
export_file_dialog(self.focused_tab, self.file_contents)
self.selected_tab = self.tabview.selected_tab()
export_file_dialog(self.selected_tab, self.file_contents)
self.terminal.newline("File exported successfully!\n\n")

def on_compute(self):
print()
remove_comments = self.tabview.remove_comments_switch.get()
remove_mcodes = self.tabview.remove_mcodes_switch.get()
remove_fecodes = self.tabview.remove_fecodes_switch.get()
remove_nontravel = self.tabview.remove_nontravel_switch.get()
remove_lone_gs = self.tabview.remove_lone_gs_switch.get()
remove_coordname = self.tabview.remove_coordname_switch.get()

self.terminal.newline("Vars OK. Compute started...\n\n")

self.file_contents, self.compute_time_taken = process_file_contents(
self.file_contents,
remove_comments,
remove_mcodes,
remove_fecodes,
remove_nontravel,
remove_lone_gs,
remove_coordname,
)
self.terminal.newline(
"Compute done! Took " + f"{self.compute_time_taken}" + " seconds\n\n"
)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions src/threedy/modules/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def select_file_dialog():


# --------------------------------------- export file logic -------------------------------------- #
def export_file_dialog(focused_tab, file_contents):
if focused_tab == "G-Code Tools":
def export_file_dialog(selected_tab, file_contents):
if selected_tab == "G-Code Tools":
extension = ".gcode"
elif focused_tab == "CSV Tools":
elif selected_tab == "CSV Tools":
extension = ".csv"

file_path = filedialog.asksaveasfilename(
Expand Down
68 changes: 68 additions & 0 deletions src/threedy/modules/process_gcode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import re
import time

from interface.tabview import gcode_switch_data
from modules.settings import RE_PATTERNS


def process_file_contents(
file_contents,
remove_comments=False,
remove_mcodes=False,
remove_fecodes=False,
remove_nontravel=False,
remove_lone_gs=False,
remove_coordname=False,
):
timer = time.process_time()

if remove_comments:
file_contents = re.sub(
RE_PATTERNS["remove_comments"],
"",
file_contents,
flags=re.MULTILINE,
)

if remove_mcodes:
file_contents = re.sub(
RE_PATTERNS["remove_mcodes"],
"",
file_contents,
flags=re.MULTILINE,
)

if remove_fecodes:
file_contents = re.sub(
RE_PATTERNS["remove_fecodes"],
"",
file_contents,
)

if remove_nontravel:
file_contents = re.sub(
RE_PATTERNS["remove_nontravel"],
"",
file_contents,
flags=re.MULTILINE,
)

if remove_lone_gs:
file_contents = re.sub(
RE_PATTERNS["remove_lone_gs"],
"",
file_contents,
flags=re.MULTILINE,
)

if remove_coordname:
file_contents = re.sub(
RE_PATTERNS["remove_coordname"],
r"\2 \3 \4 \1\5",
file_contents,
)
file_contents = re.sub(r"G", "", file_contents)

elapsed_time = time.process_time() - timer

return file_contents, elapsed_time
4 changes: 2 additions & 2 deletions src/threedy/modules/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# size
APP_SIZE = {"width": 800, "height": 500}
APP_SIZE = {"width": 900, "height": 500}

# text
FONT = "Calibri"
FONT_SIZE = 14

# styling
PADDING = {"none": 0, "medium": 10, "large": 20}
PADDING = {"none": 0, "small": 5, "medium": 10, "large": 20}

# terminal
TERMINAL_FONT = "Fira Code"
Expand Down
11 changes: 11 additions & 0 deletions src/threedy/resources/test-gcode.gcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; test comment

;

;
M104 S180 T1 ; non G-Code

G28 ; non 01 G-Code
G92 E0 ; Reset Extruder

G1 Z2 F3000 ; no WY
8 changes: 8 additions & 0 deletions tmp/gcode-processor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class GCodeProcessor(file_contents):

def remove_comments(self, file_contents):
file_contents = re.sub(
RE_PATTERNS["remove_comments"], "", file_contents, flags=re.MULTILINE
)


Loading

0 comments on commit 6031a8e

Please sign in to comment.