def LoadFile(fq_file): ''' Will always return an Instance, else False ''' if not os.path.exists(fq_file): return False try: with open(fq_file, 'r') as fh: data = fh.readline() data = data.strip() zdict = eval(data) order_def = OrderDef() for key in zdict: if key == OrderDef.IOKEY: pw_def = TableDef(name=OrderDef.NONAME) zrows = eval(zdict[key]) for row in zrows: if pw_def.get_table_name() != row[0]: if pw_def.get_table_name() != OrderDef.NONAME: order_def.add_table(pw_def) pw_def = TableDef(name=row[0]) pw_def.add_field(row[1], row[2]) order_def.add_table(pw_def) else: order_def._zdict[key] = zdict[key] order_def.fixup() return order_def except Exception as ex: print(ex.__traceback__) return False
def _on_new(self): self.title(self.ztitle) self.order_def = OrderDef() self.table_frame.empty() self.table_frame.got_results() self.table_frame.table_name.set(TableDef1.DEFAULT_NAME) self._show_order()
def __init__(self, *args, **kwargs): from SqltDAO.CodeGen01.Meta import Meta super().__init__(*args, **kwargs) self.ztitle = Meta.Title() self.d2c = None self.project = None self.zoptions = ( ( "Projects", [("Open Project...", self._on_open), ("Save Project...", self._on_save), ("Create Code", self._on_code_create)], ), ("Tools", [("Data2Code...", self._on_d2c), ("Data2Project...", self._on_d2p), ("Preferences...", self._on_d2pref)]), ("About", [("About PyDao...", self._on_about), ("Quit", self.destroy)]), ) self.table_frame = None self.home = "." self.order_def = OrderDef() ''' activeBackground, foreground, selectColor, activeForeground, highlightBackground, selectBackground, background, highlightColor, selectForeground, disabledForeground, insertBackground, troughColor. ''' self.tk_setPalette( background="Light Green", # e.g. Global foreground="dark blue", # e.g. Font color insertBackground="blue", # e.g. Entry cursor selectBackground="gold", # e.g. Editbox selections activeBackground="gold", # e.g. Menu selections )
def Convert(order_class): ''' Convert an OrderClass to an OrderDef. Raise an exception on error. ''' if isinstance(order_class, OrderClass) is False: raise TypeError("Error: Instance of OrderClass is required.") order_def = OrderDef() data = order_class.__dict__() for key in data: order_def._zdict[key] = data[key] order_def.fixup() return order_def
def do_save(self): ''' Project file must be created for both saving same, as well as for creating code. ''' ztbl = self.table_frame.pull_results() zdict = ztbl.__dict__() if not zdict: messagebox.showerror("No Data", "Schema Definition Required.") return False self.order_def = OrderDef(name=ztbl.get_table_name()) if not self.order_def.add_table(ztbl): messagebox.showerror("Invalid Table", "Please verify SQL Table Definition.") return False if Factory1.SaveFile(DataPreferences.Load(self.home), self.order_def, overwrite=True) is False: messagebox.showerror("Exportation Error", "Please verify user locations.") return False self.table_frame.got_results() return True
## newline += col + '\t' ## print(newline.strip(), file=fh2) files = ( ("../DaoTest01/Income.csv", "COMMA"), ("../DaoTest01/nasdaqlisted.txt", "PIPE"), ("../DaoTest01/tc001_data.txt", "CSV"), ("../DaoTest01/tc002_data.txt", "TAB"), ) for file, result in files: print(file, result) detect = Factory1.Detect(file) print(detect.__dict__) else: from SqltDAO.Gui.DataPreferences import Dp1 as DataPreferences pref = DataPreferences.Load('.') zorder = OrderDef(name=OrderDef.DEFAULT_SCHEMA) zname = zorder.project_name print("zname", zname) if os.path.exists(zname): print("unlinking", zname) os.unlink(zname) for ss in range(4): table = "zTable " + str(ss) ztable = TableDef(name=table) for ztype in TableDef.SupportedTypes: ztable.add_field(table + ' ' + ztype, ztype) zorder.add_table(ztable) print("zorder:\n", zorder, '\n') zname = zorder.project_name # print("zname", zname)