def init_code_gen(self):
gen = self.code_gen
# Send reference to the widget to the generator
gen.set_widget(self)
# Add imported external dependencies
gen.add_import([os, FileFormat, UrlReader])
# Declarations inserted into __init__(self)
gen.add_init("LOCAL_FILE", 0)
gen.add_init("source", "Setting(self.LOCAL_FILE)", iscode=True)
gen.add_init("recent_paths", "Setting([\n" +
indent(3, "RecentPath(\"\", \"sample-datasets\", \"iris.tab\"),\n") +
indent(3, "RecentPath(\"\", \"sample-datasets\", \"titanic.tab\"),\n") +
indent(3, "RecentPath(\"\", \"sample-datasets\", \"housing.tab\"),\n") +
indent(2, "])"), iscode=True)
gen.add_init("url_text", self.url_combo.currentText())
gen.add_init("sheet_text", self.sheet_combo.currentText())
# Copy attributes from widget to code generator
gen.add_attr(name=["load_data", "_get_reader", "select_sheet"])
# Remove lines that contain strings in output
gen.null_ln(["_update_sheet_combo", "editor_model.set_domain"])
# Replaces instances of arg1 with arg2 in generated source code
gen.repl_maps([
("url_combo.currentText()", "url_text"),
("sheet_combo.currentText()", "sheet_text"),
])
# Add variable not part of function to the output
gen.add_extern(add_origin)
# Add main function that produces output
gen.add_body(self.load_data)