Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to generate axis rod cut list (Closes #25)
- Loading branch information
Showing
16 changed files
with
457 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__all__ = ['main_toolbar', 'register_commands', 'get_resource_path'] | ||
__all__ = [ | ||
'main_toolbar', 'main_toolbar', 'register_commands', 'get_resource_path'] | ||
|
||
from .commands import main_toolbar, register_commands | ||
from .commands import main_menu, main_toolbar, register_commands | ||
from .resources import get_resource_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .copy_cut_list_to_clipboard import CopyCutListToClipboard | ||
from .save_cut_list_as_csv import SaveCutListAsCsv |
8 changes: 8 additions & 0 deletions
8
ose3dprinter/workbench/generate_cut_list/convert_dict_list_to_wiki_list_markup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def convert_dict_list_to_wiki_list_markup(dict_list): | ||
return reduce(row_to_list_item, dict_list, '') | ||
|
||
|
||
def row_to_list_item(table_markup, row): | ||
list_item_template = u"* ['''{}'''] {} \u2014 {}\n" | ||
return table_markup + list_item_template.format( | ||
row['Quantity'], row['Description'], row['Length']) |
22 changes: 22 additions & 0 deletions
22
ose3dprinter/workbench/generate_cut_list/convert_dict_list_to_wiki_table_markup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
def convert_dict_list_to_wiki_table_markup(dict_list, columns): | ||
""" | ||
See: | ||
https://www.mediawiki.org/wiki/Help:Tables#Wiki_table_markup_summary | ||
:param dict_list: list of dictionaries | ||
:type dict_list: List(Dict) | ||
:param columns: Columns of table | ||
:type columns: list of strings | ||
:return: wiki table markup | ||
:rtype: string | ||
""" | ||
table = '{| class="wikitable"\n' | ||
row_separator = '|----\n' | ||
for column in columns: | ||
table += '!|{}\n'.format(column) | ||
table += row_separator | ||
for row in dict_list: | ||
for value in row.values(): | ||
table += '|{}\n'.format(value) | ||
table += row_separator | ||
return table + '|}\n' |
22 changes: 22 additions & 0 deletions
22
ose3dprinter/workbench/generate_cut_list/copy_cut_list_to_clipboard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from .generate_cut_list import generate_cut_list | ||
from .task_type import TaskType | ||
|
||
|
||
class CopyCutListToClipboard: | ||
""" | ||
Command to copy cut-list to clipboard | ||
""" | ||
|
||
NAME = 'CopyCutListToClipboard' | ||
|
||
def Activated(self): | ||
generate_cut_list(TaskType.CopyToClipboard) | ||
|
||
def IsActive(self): | ||
return True | ||
|
||
def GetResources(self): | ||
return { | ||
'MenuText': 'Copy Axis Rod Cut List to Clipboard', | ||
'ToolTip': 'Copy Axis Rod Cut List to Clipboard' | ||
} |
72 changes: 72 additions & 0 deletions
72
ose3dprinter/workbench/generate_cut_list/copy_cut_list_to_clipboard_task_panel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import FreeCADGui | ||
from FreeCAD import Console | ||
from PySide import QtGui | ||
|
||
from .convert_dict_list_to_wiki_list_markup import \ | ||
convert_dict_list_to_wiki_list_markup | ||
from .convert_dict_list_to_wiki_table_markup import \ | ||
convert_dict_list_to_wiki_table_markup | ||
from .generate_cut_list_task_panel import GenerateCutListTaskPanel | ||
|
||
|
||
class CopyCutListToClipboardTaskPanel(GenerateCutListTaskPanel): | ||
|
||
def __init__(self, cut_list_table_rows, columns): | ||
title = 'Copy Axis Rod Cut List to Clipboard' | ||
super(CopyCutListToClipboardTaskPanel, self).__init__( | ||
title, cut_list_table_rows, columns) | ||
|
||
# Row 1 - Markup Format options | ||
row1 = QtGui.QVBoxLayout() | ||
|
||
# Table option | ||
self.table_option = QtGui.QRadioButton('Table', self.form) | ||
self.table_option.setChecked(True) | ||
row1.addWidget(self.table_option) | ||
|
||
# List option | ||
self.list_option = QtGui.QRadioButton('List', self.form) | ||
row1.addWidget(self.list_option) | ||
|
||
self.layout.addLayout(row1) | ||
|
||
# ---------------------------------- | ||
|
||
# Row 2 | ||
row2 = QtGui.QHBoxLayout() | ||
|
||
# Copy Status Label | ||
self.copyStatusLabel = QtGui.QLabel(self.form) | ||
self.copyStatusLabel.setObjectName('copyStatusLabel') | ||
self.copyStatusLabel.setText('<b>Status:</b> Not Copied') | ||
row2.addWidget(self.copyStatusLabel) | ||
|
||
# Copy to Clipboard button | ||
copy_to_clipboard_button = QtGui.QPushButton( | ||
'Copy to Clipboard') | ||
copy_to_clipboard_button.clicked.connect(self.handle_copy_to_clipboard) | ||
row2.addWidget(copy_to_clipboard_button) | ||
|
||
self.layout.addLayout(row2) | ||
|
||
def handle_copy_to_clipboard(self): | ||
clipboard = QtGui.QApplication.clipboard() | ||
table_markup = '' | ||
if self.table_option.isChecked(): | ||
table_markup = convert_dict_list_to_wiki_table_markup( | ||
self.cut_list_table_rows, self.columns) | ||
elif self.list_option.isChecked(): | ||
table_markup = convert_dict_list_to_wiki_list_markup( | ||
self.cut_list_table_rows) | ||
else: | ||
raise ValueError('Table or list option must be checked.') | ||
clipboard.setText(table_markup) | ||
self.copyStatusLabel.setText('<b>Status:</b> Copied!') | ||
Console.PrintMessage('Copied table markup to clipboard.\n') | ||
|
||
def accept(self): | ||
""" | ||
Executed upon clicking "OK" button in FreeCAD Tasks panel. | ||
""" | ||
self.handle_copy_to_clipboard() | ||
FreeCADGui.Control.closeDialog() |
Oops, something went wrong.