submit coordinates
This commit is contained in:
parent
dac6f94e4b
commit
1b5aff80b3
|
@ -138,11 +138,11 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "label-size", "16", False)
|
||||
set_option(section, "label-precision", "2", False)
|
||||
set_option(section, "axis-label-count", "8", False)
|
||||
set_option(section, "prompt-size", "200, 80", False)
|
||||
set_option(section, "prompt-size", "380, 60", False)
|
||||
set_option(section, "prompt-border-color", "255, 0, 0", False)
|
||||
set_option(section, "prompt-border-width", "3", False)
|
||||
set_option(section, "prompt-character-limit", "6", False)
|
||||
set_option(section, "prompt-text-size", "52", False)
|
||||
set_option(section, "prompt-character-limit", "21", False)
|
||||
set_option(section, "prompt-text-size", "42", False)
|
||||
|
||||
def add_section(self, name):
|
||||
if name not in self.order:
|
||||
|
@ -326,15 +326,19 @@ class Configuration(RawConfigParser):
|
|||
items.append((option, self.get(section, option)))
|
||||
return items
|
||||
|
||||
def write(self, fp):
|
||||
def write(self):
|
||||
modifiable = self.modifiable
|
||||
fp = open(self.locate_project_config_file(), "w")
|
||||
break_line = False
|
||||
for section in self.order:
|
||||
if section in modifiable:
|
||||
break_line and fp.write("\n")
|
||||
fp.write("[%s]\n" % section)
|
||||
for option in modifiable[section]:
|
||||
value = self.get(section, option)
|
||||
fp.write("%s = %s\n" % (option, self.get_raw_value(value)))
|
||||
fp.write("\n")
|
||||
break_line = True
|
||||
fp.close()
|
||||
|
||||
def get_raw_value(self, value):
|
||||
if isinstance(value, list):
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from re import match
|
||||
|
||||
from pygame import Surface
|
||||
from pygame.font import Font
|
||||
from pygame.draw import aaline
|
||||
|
@ -122,9 +124,10 @@ class Nodeset(list):
|
|||
return splines[ii].get_y(t)
|
||||
return splines[-1].get_y(t)
|
||||
|
||||
def remove(self, node):
|
||||
def remove(self, node, refresh=True):
|
||||
list.remove(self, node)
|
||||
self.set_splines()
|
||||
if refresh:
|
||||
self.set_splines()
|
||||
|
||||
|
||||
class Node(list):
|
||||
|
@ -192,8 +195,11 @@ class GUI(GameChild):
|
|||
self.set_buttons()
|
||||
self.active = False
|
||||
self.set_nodeset_index()
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
self.subscribe(self.respond_to_command)
|
||||
self.subscribe(self.respond_to_mouse_down, MOUSEBUTTONDOWN)
|
||||
self.subscribe(self.respond_to_key, KEYDOWN)
|
||||
|
||||
def load_configuration(self):
|
||||
config = self.get_configuration("interpolator-gui")
|
||||
|
@ -247,8 +253,6 @@ class GUI(GameChild):
|
|||
index = limit
|
||||
self.nodeset_index = index
|
||||
self.set_nodeset_label()
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
|
||||
def set_nodeset_label(self):
|
||||
surface = self.font.render(self.get_nodeset().name, True, (0, 0, 0),
|
||||
|
@ -332,7 +336,7 @@ class GUI(GameChild):
|
|||
|
||||
def respond_to_mouse_down(self, event):
|
||||
redraw = False
|
||||
if self.active:
|
||||
if self.active and not self.prompt.active:
|
||||
nodeset_rect = self.nodeset_label_rect
|
||||
plot_rect = self.plot_rect
|
||||
if event.button == 1:
|
||||
|
@ -341,28 +345,32 @@ class GUI(GameChild):
|
|||
self.set_nodeset_index(1)
|
||||
redraw = True
|
||||
elif self.axis_labels[0][0][1].collidepoint(pos):
|
||||
self.prompt.activate(self.get_nodeset()[0].x, self.draw)
|
||||
text = "{0} {1}".format(*map(self.get_formatted_measure,
|
||||
self.get_nodeset()[0]))
|
||||
self.prompt.activate(text, self.set_node, 0)
|
||||
elif self.axis_labels[1][0][1].collidepoint(pos):
|
||||
text = "{0} {1}".format(*map(self.get_formatted_measure,
|
||||
self.get_nodeset()[1]))
|
||||
self.prompt.activate(text, self.set_node, -1)
|
||||
else:
|
||||
bi = self.collide_buttons(pos)
|
||||
if bi is not None:
|
||||
if bi == self.B_WRITE:
|
||||
self.write_configuration()
|
||||
self.get_configuration().write()
|
||||
else:
|
||||
nodeset = self.get_nodeset()
|
||||
if bi == self.B_LINEAR:
|
||||
nodeset.set_interpolation_method(Nodeset.LINEAR)
|
||||
else:
|
||||
nodeset.set_interpolation_method(Nodeset.CUBIC)
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
self.store_in_configuration()
|
||||
redraw = True
|
||||
elif plot_rect.collidepoint(pos) and \
|
||||
not self.collide_markers(pos):
|
||||
xp, yp = pos[0] - plot_rect.left, pos[1] - plot_rect.top
|
||||
self.get_nodeset().add_node(
|
||||
self.get_function_coordinates(xp, yp))
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
self.store_in_configuration()
|
||||
redraw = True
|
||||
elif event.button == 3:
|
||||
pos = event.pos
|
||||
|
@ -373,17 +381,36 @@ class GUI(GameChild):
|
|||
marker = self.collide_markers(pos)
|
||||
if marker:
|
||||
self.get_nodeset().remove(marker.node)
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
self.store_in_configuration()
|
||||
redraw = True
|
||||
redraw and self.draw()
|
||||
if redraw:
|
||||
self.set_yrange()
|
||||
self.set_markers()
|
||||
self.draw()
|
||||
|
||||
def set_node(self, text, index):
|
||||
result = match("^\s*(-{,1}\d*\.{,1}\d*)\s+(-{,1}\d*\.{,1}\d*)\s*$",
|
||||
text)
|
||||
if result:
|
||||
try:
|
||||
nodeset = self.get_nodeset()
|
||||
nodeset.remove(nodeset[index], False)
|
||||
nodeset.add_node(map(float, result.group(1, 2)))
|
||||
self.store_in_configuration()
|
||||
self.set_yrange()
|
||||
self.set_axis_labels()
|
||||
self.set_markers()
|
||||
self.draw()
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def collide_buttons(self, pos):
|
||||
for ii, button in enumerate(self.buttons):
|
||||
if button.location.collidepoint(pos):
|
||||
return ii
|
||||
|
||||
def write_configuration(self):
|
||||
def store_in_configuration(self):
|
||||
config = self.get_configuration()
|
||||
for nodeset in self.parent:
|
||||
code = "L" if nodeset.interpolation_method == Nodeset.LINEAR else \
|
||||
|
@ -394,7 +421,6 @@ class GUI(GameChild):
|
|||
code += " {0} {1}".format(*map(self.get_formatted_measure,
|
||||
node))
|
||||
config.set("interpolate", nodeset.name, code)
|
||||
config.write(open("/tmp/config", "w"))
|
||||
|
||||
def collide_markers(self, pos):
|
||||
for marker in self.markers:
|
||||
|
@ -461,6 +487,23 @@ class GUI(GameChild):
|
|||
for button in self.buttons:
|
||||
button.update()
|
||||
|
||||
def respond_to_key(self, event):
|
||||
if self.prompt.active:
|
||||
prompt = self.prompt
|
||||
if event.key == K_RETURN:
|
||||
if prompt.callback[0](prompt.text, *prompt.callback[1]):
|
||||
prompt.deactivate()
|
||||
elif event.key == K_BACKSPACE:
|
||||
prompt.text = prompt.text[:-1]
|
||||
prompt.update()
|
||||
prompt.draw_text()
|
||||
elif (event.unicode.isalnum() or event.unicode.isspace() or \
|
||||
event.unicode in (".", "-", "_")) and len(prompt.text) < \
|
||||
prompt.character_limit:
|
||||
prompt.text += event.unicode
|
||||
prompt.update()
|
||||
prompt.draw_text()
|
||||
|
||||
|
||||
class Marker(Sprite):
|
||||
|
||||
|
@ -511,10 +554,10 @@ class Prompt(Sprite):
|
|||
width = self.border_width * 2
|
||||
surface.fill((0, 0, 0), self.location.inflate(-width, -width))
|
||||
|
||||
def activate(self, text, callback):
|
||||
def activate(self, text, callback, *args):
|
||||
self.active = True
|
||||
self.text = str(text)
|
||||
self.callback = callback
|
||||
self.callback = callback, args
|
||||
self.update()
|
||||
self.draw_text()
|
||||
|
||||
|
|
Loading…
Reference in New Issue