diff --git a/src/GUIFrame.cc b/src/GUIFrame.cc index 351562e..c283449 100644 --- a/src/GUIFrame.cc +++ b/src/GUIFrame.cc @@ -706,10 +706,16 @@ void GUIFrame::RenameSmartpen(wxCommandEvent& event) { if (confirmationDialog.ShowModal() == wxID_YES) { printf("Request confirmed. Attempting to rename device...\n"); smartpen->setName((char*)desiredName.c_str()); - printf("returned from setting pen name. resetting device.\n"); + printf("returned from setting pen name. Disconnecting old smartpen instance.\n"); + smartpen->disconnect(); + printf("Destory old smartpen object."); + delete smartpen; + smartpen = NULL; + printf("Close usb decice connection"); libusb_close(dev); - dev = findSmartpen(); - printf("Retrieving smartpen name: %s\n", smartpen->getName()); + dev = NULL; + printf("Refresh decice. Device should be detected under new name.\n"); + doRefreshDeviceState(); } else printf("Rename operation cancelled.\n"); } } diff --git a/stf.py b/stf.py index 9d257a6..5c65bb8 100644 --- a/stf.py +++ b/stf.py @@ -292,7 +292,40 @@ def handle_point(self, x, y, force, time): assert False -surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 8000, 8000) +class PreParser(STFParser): + def __init__(self, *args): + super(PreParser, self).__init__(*args) + self.minx=8000 + self.miny=8000 + self.maxx=0 + self.maxy=0 + + def handle_point(self, x, y, f, time): + if f: + if x > self.maxx: + self.maxx=x + if x < self.minx: + self.minx=x + if y > self.maxy: + self.maxy=y + if y < self.miny: + self.miny=y + +try: + stf_file +except NameError: + stf_file = sys.argv[1] + +pref = file(stf_file) +prep = PreParser(pref) +prep.parse() + +if prep.maxx > 8000: + prep.maxx = 8000 +if prep.maxy > 8000: + prep.maxy = 8000 + +surface = cairo.ImageSurface(cairo.FORMAT_RGB24, prep.maxx-prep.minx, prep.maxy-prep.miny) ctx = cairo.Context(surface) print float(fgRed) @@ -303,6 +336,7 @@ def handle_point(self, x, y, force, time): print float(bgGreen) print float(bgBlue) +ctx.set_line_width(10) ctx.set_source_rgb(float(bgRed), float(bgGreen), float(bgBlue)) ctx.paint() ctx.set_source_rgb(float(fgRed), float(fgGreen), float(fgBlue)) @@ -319,9 +353,9 @@ def handle_stroke_end(self, time): def handle_point(self, x, y, f, time): if f: if self.last_force: - ctx.line_to(x, y) + ctx.line_to(x-prep.minx, y-prep.miny) else: - ctx.move_to(x, y) + ctx.move_to(x-prep.minx, y-prep.miny) self.last_force = 1 try: