GUI creates the ini file now and add layers

Signed-off-by: John Thornton <bjt128@gmail.com>
This commit is contained in:
John Thornton
2015-11-05 08:20:53 -06:00
parent 98ac4ba3c1
commit 90c48ae594
5 changed files with 127 additions and 82 deletions

View File

@ -237,21 +237,49 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<child> <child>
<object class="GtkLabel" id="label4"> <object class="GtkTable" id="table2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Functioning menu items are: <property name="n_rows">3</property>
File &gt; Open: selects a .dxf file for processing <property name="n_columns">3</property>
File &gt; Convert: runs the .dxf file through dxf2gcode <child>
File &gt; Quit <placeholder/>
Help &gt; About</property> </child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkComboBox" id="layers_cbo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_layers_cbo_changed" swapped="no"/>
</object>
</child>
</object> </object>
</child> </child>
<child type="tab"> <child type="tab">
<object class="GtkLabel" id="label1"> <object class="GtkLabel" id="label1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Usage</property> <property name="label" translatable="yes">Setup</property>
</object> </object>
<packing> <packing>
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
@ -463,10 +491,14 @@ Help &gt; About</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="label8"> <object class="GtkLabel" id="label4">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">label</property> <property name="label" translatable="yes">Functioning menu items are:
File &gt; Open: selects a .dxf file for processing
File &gt; Convert: runs the .dxf file through dxf2gcode
File &gt; Quit
Help &gt; About</property>
</object> </object>
<packing> <packing>
<property name="position">2</property> <property name="position">2</property>
@ -476,7 +508,7 @@ Help &gt; About</property>
<object class="GtkLabel" id="label3"> <object class="GtkLabel" id="label3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">page 3</property> <property name="label" translatable="yes">Usage</property>
</object> </object>
<packing> <packing>
<property name="position">2</property> <property name="position">2</property>

111
dxf.py
View File

@ -6,7 +6,8 @@ version = '1.0.0'
import gtk import gtk
import os import os
import subprocess #import subprocess
from subprocess import Popen, PIPE
import ConfigParser import ConfigParser
class Buglump: class Buglump:
@ -28,7 +29,7 @@ class Buglump:
self.label2 = self.builder.get_object('label2') self.label2 = self.builder.get_object('label2')
self.save_directory = self.builder.get_object('save_directory_entry') self.save_directory = self.builder.get_object('save_directory_entry')
self.output_name = self.builder.get_object('output_name_entry') self.output_name = self.builder.get_object('output_name_entry')
self.file_name = '' self.input_file = ''
self.ini_file = '' self.ini_file = ''
self.config = ConfigParser.ConfigParser() self.config = ConfigParser.ConfigParser()
self.config.optionxform = str self.config.optionxform = str
@ -36,53 +37,7 @@ class Buglump:
self.window.show() self.window.show()
self.ini_check() self.ini_check()
def on_window_destroy(self, object, data=None): # Startup Checks
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'
def ini_check(self, data=None): def ini_check(self, data=None):
ini_path = os.path.expanduser('~') + '/.config/dxf2emc' ini_path = os.path.expanduser('~') + '/.config/dxf2emc'
self.ini_file = ini_path + '/dxf2emc.ini' self.ini_file = ini_path + '/dxf2emc.ini'
@ -114,10 +69,67 @@ class Buglump:
self.config.write(cfgfile) self.config.write(cfgfile)
cfgfile.close 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): def on_help_about(self, menuitem, data=None):
self.response = self.aboutdialog.run() self.response = self.aboutdialog.run()
self.aboutdialog.hide() self.aboutdialog.hide()
# Setup Tab
# Preferences Tab
def on_revert_prefrences(self, data=None): def on_revert_prefrences(self, data=None):
try: try:
self.tolerance.set_text(self.config.get('Configuration', 'TOLERANCE')) self.tolerance.set_text(self.config.get('Configuration', 'TOLERANCE'))
@ -150,6 +162,7 @@ class Buglump:
self.config.write(cfgfile) self.config.write(cfgfile)
cfgfile.close() cfgfile.close()
# Message Dialogs
def yesno_dialog(self, message): def yesno_dialog(self, message):
md = gtk.MessageDialog(self.window, md = gtk.MessageDialog(self.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO,

View File

@ -3,8 +3,8 @@ package main
// DXF to G code converter // DXF to G code converter
import ( import (
"flag" "flag"
"path/filepath" //"path/filepath"
"log" //"log"
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
@ -34,33 +34,35 @@ func main() {
flag.Parse() flag.Parse()
if flag.NFlag() == 0 { // if no flags are passed print usage if flag.NFlag() == 0 { // if no flags are passed print usage
flag.Usage() flag.Usage()
fmt.Println("Analyze", *analyze)
fmt.Println("Flags", flag.NFlag()) fmt.Println("Flags", flag.NFlag())
os.Exit(1) os.Exit(1)
} }
if *convert {
fmt.Println("Convert was true")
}
iniMap := make(map[string]string) iniMap := make(map[string]string)
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) usr, _ := user.Current() // get user information
if err != nil { iniFile := usr.HomeDir + "/.config/dxf2emc/dxf2emc.ini"
log.Fatal(err) dxfutil.Readini(iniMap, iniFile)
} //fmt.Println("OUTPUT", iniMap["OUTPUT"])
dxfutil.Readini(iniMap, dir) //i, ok := iniMap["OUTPUT"]
//fmt.Println(i, ok)
lines := dxfutil.GetLines(*input) lines := dxfutil.GetLines(*input)
entities := dxfutil.GetEntities(lines) entities := dxfutil.GetEntities(lines)
if *analyze { if *analyze {
dxfutil.GetLayers(entities) dxfutil.GetLayers(entities)
} }
if *convert {
fmt.Println("Convert was true")
}
os.Exit(1) 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 //var inFile string
/* /*
if len(os.Args) == 2 { if len(os.Args) == 2 {

View File

@ -153,7 +153,7 @@ func GetLayers(e []Ent){
} }
layers = append(layers, e[i].G8) layers = append(layers, e[i].G8)
} }
fmt.Println(layers) fmt.Println("Layers", layers)
} }
func GetEndPoints (e []Ent) ([]Ent){ func GetEndPoints (e []Ent) ([]Ent){

View File

@ -1,6 +1,5 @@
package dxfutil package dxfutil
import ( import (
"os" "os"
"bufio" "bufio"
@ -16,7 +15,6 @@ func PathExists(path string) (bool) {
} }
func Readini(m map[string]string, path string) { func Readini(m map[string]string, path string) {
path += "/dxf2gcode.ini"
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
panic(err) panic(err)
@ -26,9 +24,9 @@ func Readini(m map[string]string, path string) {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
parts := strings.Split(line, "=") if line != "[Configuration]" && len(line) > 0 {
for range parts { parts := strings.Split(line, "=")
m[parts[0]] = parts[1] m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
} }
} }
} }