Skip to content

Commit

Permalink
Merge pull request #33 from krisjans/master
Browse files Browse the repository at this point in the history
Propesed fix for issue #22: Renaming the Device Causes a Segmentation Fault
  • Loading branch information
Dylan M. Taylor committed May 13, 2012
2 parents dbabff7 + 63fd7a0 commit 170e56e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/GUIFrame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
40 changes: 37 additions & 3 deletions stf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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:
Expand Down

0 comments on commit 170e56e

Please sign in to comment.