2 This page is in the table of contents.
3 Display line is a mouse tool to select and display information about the line.
5 When a line is clicked, the line will be selected and information about the line will be displayed. If a gcode line is clicked, the information will be file line count of the line clicked, counting from one, and the line itself.
7 When the display line tool is chosen and the canvas has the focus, display line will listen to the arrow keys. Clicking in the canvas gives the canvas the focus, and when the canvas has the focus a thick black border is drawn around the canvas. When the right arrow key is pressed, display line will increase the line index of the layer by one, and change the selection accordingly. If the line index of the layer goes over the index of the last line, the layer index will be increased by one and the new line index will be zero. When the left arrow key is pressed, the index will be decreased. If the line index goes below the index of the first line, the layer index will be decreased by one and the new line index will be at the last line. The up arrow key increases the layer index by one and the down arow key decreases the line index.
11 from __future__ import absolute_import
12 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
15 from skeinforge_application.skeinforge_plugins.analyze_plugins.analyze_utilities.mouse_tool_base import MouseToolBase
16 from fabmetheus_utilities import gcodec
17 from fabmetheus_utilities import settings
19 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
20 __date__ = '$Date: 2008/21/04 $'
21 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
24 def getNewMouseTool():
25 "Get a new mouse tool."
29 class DisplayLine( MouseToolBase ):
30 "Display the line when it is clicked."
31 def button1( self, event, shift = False ):
32 "Print line text and connection line."
33 self.destroyEverythingGetFocus()
34 x = self.canvas.canvasx(event.x)
35 y = self.canvas.canvasy(event.y)
36 tags = self.getTagsGivenXY(x, y)
39 if tags.startswith('colored_line_index:'):
40 splitLine = tags.split()
41 coloredLineIndex = int(splitLine[1])
42 self.repository.line.value = coloredLineIndex
43 tags = self.getSelectedColoredLine().displayString
44 self.drawLineText( complex( float(x), float(y) ), tags )
46 def destroyEverything(self):
48 self.canvas.delete('mouse_item')
49 self.canvas.delete('selection_line')
51 def drawLineText( self, location, tags ):
53 self.window.getDrawnLineText( location, 'mouse_item', tags )
55 def drawSelectedColoredLineText(self):
56 "Draw the selected line and text."
57 selectedColoredLine = self.getSelectedColoredLine()
58 if len( self.canvas.find_withtag('selection_line') ) < 1 or selectedColoredLine == None:
60 tags = selectedColoredLine.displayString
61 lineCoordinates = self.canvas.coords( self.canvas.find_withtag('selection_line')[-1] )
62 begin = complex( lineCoordinates[0], lineCoordinates[1] )
63 end = complex( lineCoordinates[2], lineCoordinates[3] )
65 segmentLength = abs(segment)
66 if segmentLength <= 0.0:
68 towardEnd = 0.75 * segment
69 segmentClockwise = 20.0 * complex( segment.imag, - segment.real ) / segmentLength
70 location = begin + towardEnd + segmentClockwise
71 self.drawLineText( location, tags )
73 def getSelectedColoredLine(self):
74 "Draw the selected line, add it to the items and return the colored line."
75 self.window.cancelTimerResetButtons()
76 coloredLines = self.window.getColoredLines()
77 self.repository.line.value = max(0, self.repository.line.value)
78 if len(coloredLines) < 1:
80 self.repository.line.value = min(len(coloredLines) - 1, self.repository.line.value)
81 self.window.setLineButtonsState()
82 coloredLine = coloredLines[self.repository.line.value]
83 lineCoordinates = self.canvas.coords(self.window.getDrawnSelectedColoredLine(coloredLine))
84 end = complex(lineCoordinates[2], lineCoordinates[3])
85 radiusComplex = complex(16.0, 16.0)
86 upperLeft = end - radiusComplex
87 lowerRight = end + radiusComplex
88 self.canvas.create_oval (int(upperLeft.real), int(upperLeft.imag), int(lowerRight.real), int(lowerRight.imag), tags = 'mouse_item')
91 def isSelectionTool(self):
92 "Return if this mouse tool is a selection tool."
95 def keyPressDown(self, event):
96 "The down arrow was pressed."
97 self.destroyEverything()
98 self.window.setLayerIndex( self.repository.layer.value - 1 )
100 def keyPressLeft(self, event):
101 "The left arrow was pressed."
102 self.destroyEverything()
103 self.repository.line.value -= 1
104 if self.window.isLineBelowZeroSetLayer():
106 self.drawSelectedColoredLineText()
108 def keyPressRight(self, event):
109 "The right arrow was pressed."
110 self.destroyEverything()
111 self.repository.line.value += 1
112 if self.window.isLineBeyondListSetLayer():
114 self.drawSelectedColoredLineText()
116 def keyPressUp(self, event):
117 "The up arrow was pressed."
118 self.destroyEverything()
119 self.window.setLayerIndex( self.repository.layer.value + 1 )
122 "Update the mouse tool."
123 self.destroyEverything()
124 self.drawSelectedColoredLineText()