diff --git a/dxf.glade b/dxf.glade index 19240de..e9bd251 100644 --- a/dxf.glade +++ b/dxf.glade @@ -237,21 +237,49 @@ True True - + True False - Functioning menu items are: -File > Open: selects a .dxf file for processing -File > Convert: runs the .dxf file through dxf2gcode -File > Quit -Help > About + 3 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + True + False + + + True False - Usage + Setup False @@ -463,10 +491,14 @@ Help > About - + True False - label + Functioning menu items are: +File > Open: selects a .dxf file for processing +File > Convert: runs the .dxf file through dxf2gcode +File > Quit +Help > About 2 @@ -476,7 +508,7 @@ Help > About True False - page 3 + Usage 2 diff --git a/dxf.py b/dxf.py index f18a3e8..36130ca 100755 --- a/dxf.py +++ b/dxf.py @@ -6,7 +6,8 @@ version = '1.0.0' import gtk import os -import subprocess +#import subprocess +from subprocess import Popen, PIPE import ConfigParser class Buglump: @@ -28,7 +29,7 @@ class Buglump: self.label2 = self.builder.get_object('label2') self.save_directory = self.builder.get_object('save_directory_entry') self.output_name = self.builder.get_object('output_name_entry') - self.file_name = '' + self.input_file = '' self.ini_file = '' self.config = ConfigParser.ConfigParser() self.config.optionxform = str @@ -36,53 +37,7 @@ class Buglump: self.window.show() self.ini_check() - def on_window_destroy(self, object, data=None): - gtk.main_quit() - - def on_file_quit(self, menuitem, data=None): - gtk.main_quit() - - def on_file_open(self, menuitem, data=None): - self.fcd = gtk.FileChooserDialog("Open...", None, - gtk.FILE_CHOOSER_ACTION_OPEN, - (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) - if len(self.current_folder) > 0: - self.fcd.set_current_folder(self.current_folder) - self.response = self.fcd.run() - if self.response == gtk.RESPONSE_OK: - self.status.set_text('File Selected %s' % self.fcd.get_filename()) - self.file_name = "-f=" + self.fcd.get_filename() - self.current_folder = os.path.dirname(self.fcd.get_uri()[7:]) - self.file_analyze.set_sensitive(True) - self.file_convert.set_sensitive(True) - else: - self.status.set_text('No File Open') - self.fcd.destroy() - - def on_file_analyze(self, menuitem, data=None): - print 'Analyze %s' % self.file_name - - def on_file_convert(self, file_name, data=None): - if len(self.file_name) > 0: - self.args = self.file_name - self.result = subprocess.call("dxf2gcode %s" %self.args, shell=True) - if self.result == 0: - self.status.set_text('Processing Complete') - else: - self.status.set_text('Error %d Processing %s' % (self.result, self.file_name)) - else: - self.status.set_text('No File Open') - - def on_view_test(self, item, data=None): - message = 'Do you like my test?\nPick one.' - result = self.yesno_dialog(message) - if result == gtk.RESPONSE_YES: - print 'view yes' - if result == gtk.RESPONSE_NO: - print 'view no' - if result == gtk.RESPONSE_DELETE_EVENT: - print 'view delete' - +# Startup Checks def ini_check(self, data=None): ini_path = os.path.expanduser('~') + '/.config/dxf2emc' self.ini_file = ini_path + '/dxf2emc.ini' @@ -114,10 +69,67 @@ class Buglump: self.config.write(cfgfile) cfgfile.close + def on_window_destroy(self, object, data=None): + gtk.main_quit() + +# File Menu Items + def on_file_quit(self, menuitem, data=None): + gtk.main_quit() + + def on_file_open(self, menuitem, data=None): + self.fcd = gtk.FileChooserDialog("Open...", None, + gtk.FILE_CHOOSER_ACTION_OPEN, + (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) + if len(self.current_folder) > 0: + self.fcd.set_current_folder(self.current_folder) + self.response = self.fcd.run() + if self.response == gtk.RESPONSE_OK: + self.status.set_text('File Selected %s' % self.fcd.get_filename()) + self.input_file = "-f=" + self.fcd.get_filename() + self.current_folder = os.path.dirname(self.fcd.get_uri()[7:]) + self.file_analyze.set_sensitive(True) + self.file_convert.set_sensitive(True) + self.on_file_analyze() + else: + self.status.set_text('No File Open') + self.fcd.destroy() + + def on_file_analyze(self, menuitem, data=None): + print 'Analyze %s' % self.input_file + command = "dxf2gcode -a" + process = Popen(command, stdout=PIPE, stderr=PIPE, shell=True) + output, error = process.communicate() + + def on_file_convert(self, input_file, data=None): + if len(self.input_file) > 0: + self.args = self.input_file + self.result = Popen("dxf2gcode %s" %self.args, shell=True) + if self.result == 0: + self.status.set_text('Processing Complete') + else: + self.status.set_text('Error %d Processing %s' % (self.result, self.input_file)) + else: + self.status.set_text('No File Open') + +# View Menu Items + def on_view_test(self, item, data=None): + message = 'Do you like my test?\nPick one.' + result = self.yesno_dialog(message) + if result == gtk.RESPONSE_YES: + print 'view yes' + if result == gtk.RESPONSE_NO: + print 'view no' + if result == gtk.RESPONSE_DELETE_EVENT: + print 'view delete' + +# Help Menu Items def on_help_about(self, menuitem, data=None): self.response = self.aboutdialog.run() self.aboutdialog.hide() +# Setup Tab + +# Preferences Tab def on_revert_prefrences(self, data=None): try: self.tolerance.set_text(self.config.get('Configuration', 'TOLERANCE')) @@ -150,6 +162,7 @@ class Buglump: self.config.write(cfgfile) cfgfile.close() +# Message Dialogs def yesno_dialog(self, message): md = gtk.MessageDialog(self.window, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, diff --git a/dxf2gcode.go b/dxf2gcode.go index 454bc54..e227f0c 100644 --- a/dxf2gcode.go +++ b/dxf2gcode.go @@ -3,8 +3,8 @@ package main // DXF to G code converter import ( "flag" - "path/filepath" - "log" + //"path/filepath" + //"log" "fmt" "os" "os/user" @@ -34,33 +34,35 @@ func main() { flag.Parse() if flag.NFlag() == 0 { // if no flags are passed print usage flag.Usage() - fmt.Println("Analyze", *analyze) fmt.Println("Flags", flag.NFlag()) os.Exit(1) } - if *convert { - fmt.Println("Convert was true") - } iniMap := make(map[string]string) - dir, err := filepath.Abs(filepath.Dir(os.Args[0])) - if err != nil { - log.Fatal(err) - } - dxfutil.Readini(iniMap, dir) + usr, _ := user.Current() // get user information + iniFile := usr.HomeDir + "/.config/dxf2emc/dxf2emc.ini" + dxfutil.Readini(iniMap, iniFile) + //fmt.Println("OUTPUT", iniMap["OUTPUT"]) + //i, ok := iniMap["OUTPUT"] + //fmt.Println(i, ok) lines := dxfutil.GetLines(*input) entities := dxfutil.GetEntities(lines) if *analyze { dxfutil.GetLayers(entities) } + if *convert { + fmt.Println("Convert was true") + } os.Exit(1) - usr, _ := user.Current() // get user information - inipath := usr.HomeDir + "/.config/dxf2emc" - fmt.Println(inipath) - //fmt.Println(dxfutil.PathExists(inipath + "/dxf2emc.ini")) - //fmt.Println(dir) - //cwd, _ := os.Getwd() // get current working directory +/* + dir, err := filepath.Abs(filepath.Dir(os.Args[0])) + if err != nil { + log.Fatal(err) + } +*/ + + //cwd, _ := os.Getwd() // get current working directory //var inFile string /* if len(os.Args) == 2 { diff --git a/dxfutil/dxf_util.go b/dxfutil/dxf_util.go index b1f8197..7c89dbb 100644 --- a/dxfutil/dxf_util.go +++ b/dxfutil/dxf_util.go @@ -153,7 +153,7 @@ func GetLayers(e []Ent){ } layers = append(layers, e[i].G8) } - fmt.Println(layers) + fmt.Println("Layers", layers) } func GetEndPoints (e []Ent) ([]Ent){ diff --git a/dxfutil/file_util.go b/dxfutil/file_util.go index f042ab1..d04686c 100644 --- a/dxfutil/file_util.go +++ b/dxfutil/file_util.go @@ -1,6 +1,5 @@ package dxfutil - import ( "os" "bufio" @@ -16,7 +15,6 @@ func PathExists(path string) (bool) { } func Readini(m map[string]string, path string) { - path += "/dxf2gcode.ini" f, err := os.Open(path) if err != nil { panic(err) @@ -26,9 +24,9 @@ func Readini(m map[string]string, path string) { scanner := bufio.NewScanner(f) for scanner.Scan() { line := scanner.Text() - parts := strings.Split(line, "=") - for range parts { - m[parts[0]] = parts[1] + if line != "[Configuration]" && len(line) > 0 { + parts := strings.Split(line, "=") + m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1]) } } }