Skip to content

Commit

Permalink
Merge pull request #275 from oracc/development
Browse files Browse the repository at this point in the history
Merge for version 0.8
  • Loading branch information
sgrieve authored Aug 29, 2017
2 parents 01418ab + cc88046 commit 2890215
Show file tree
Hide file tree
Showing 24 changed files with 856 additions and 155 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nammu: Desktop GUI for ORACC

To run Nammu on your computer, you can download it from
[here](https://github.com/oracc/nammu/releases/download/0.7.1/nammu-0.7.1.jar)
[here](https://github.com/oracc/nammu/releases/download/0.8.0/nammu-0.8.0.jar)
and just double click on it to open it.

## What is ORACC?
Expand Down Expand Up @@ -79,7 +79,7 @@ on how to correct them.
## How to run Nammu

To run Nammu on your computer, you can download it from
[here](https://github.com/oracc/nammu/releases/download/0.7.1/nammu-0.7.1.jar)
[here](https://github.com/oracc/nammu/releases/download/0.8.0/nammu-0.8.0.jar)
and just double click on it to open it and use it.

If you find any problem trying to open it, have a look in the [Troubleshooting](#known-problems-and-troubleshooting) section.
Expand Down Expand Up @@ -214,10 +214,13 @@ from previous executions:
like this:
```
java -jar target/nammu-0.7.1.jar
java -jar target/nammu-0.8.0.jar
```

6. You can also run Nammu in development mode from the console. See instructions:
https://github.com/oracc/nammu/wiki/Running-Nammu-from-a-console

If you find any problem or need more information, you can create an issue
[here](https://github.com/oracc/nammu/issues).

Expand Down
29 changes: 23 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>uk.ac.ucl.rc.development.oracc</groupId>
<artifactId>nammu</artifactId>
<version>0.7.1</version>
<version>0.8.0</version>
<packaging>jar</packaging>

<name>nammu</name>
Expand Down Expand Up @@ -64,16 +64,29 @@
<include>**/*py.class</include>
</includes>
</fileset>
<fileset>
<directory>./resources/lib</directory>
<includes>
<include>*.class</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
</plugin>

<!-- Make sure resources like toolbar icons are copied to final
jar -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<executions>

<execution>
<id>copy-resources</id>
<phase>validate</phase>
Expand All @@ -90,22 +103,26 @@
</resources>
</configuration>
</execution>

<execution>
<id>copy-java-class</id>
<phase>validate</phase>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/Lib</outputDirectory>
<outputDirectory>${basedir}/resources/lib</outputDirectory>
<resources>
<resource>
<directory>${basedir}/resources/lib</directory>
<filtering>false</filtering>
<directory>${basedir}/target/classes</directory>
<includes>
<include>*.class</include>
</includes>
</resource>
</resources>
</configuration>
</execution>

</executions>
</plugin>

Expand Down
180 changes: 177 additions & 3 deletions python/nammu/controller/AtfAreaController.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AtfAreaController(object):
def __init__(self, mainControler):
# Create text edition area
self.edit_area = AtfEditArea(self)
self.caret = self.edit_area.getCaret()
self.secondary_area = AtfEditArea(self)
# Create text panel to display the line numbers
self.line_numbers_area = TextLineNumber(self.edit_area)
Expand Down Expand Up @@ -144,11 +145,161 @@ def wrapper(*args, **kw):
return getattr(self.edit_area, name)(*args, **kw)
return wrapper

def syntax_highlight(self):
def get_viewport_top_bottom(self, top, bottom):
'''
Short hand for syntax highlighting.
Get the top and bottom of the viewport from scroll events
'''
self.syntax_highlighter.syntax_highlight()
top_line = self.edit_area.get_line_num(top)
bottom_line = self.edit_area.get_line_num(bottom)

return top_line, bottom_line

def pad_top_viewport_caret(self, top_left_char, text):
'''
Extend the top of the viewport to the nearest header, so we don't
have problems with malformed atf files being highlighted.
'''

# Test that there is text in the edit area
if len(text) == 0:
return top_left_char

# Test if the line we are currently on is a header line
if text[top_left_char] == '&':
return top_left_char

# slice text to only contain the characters above the viewport
text_above = text[:top_left_char]
# This catches malformed headers at the top of a file.
if len(text_above) == 0:
return top_left_char

# Split the text above the viewport into lines
lines = text_above.split('\n')
header_line_no = None

# Iterate over the list backwards, as this is more efficient
for line_no, line in reversed(list(enumerate(lines))):
if line.startswith('&'):
header_line_no = line_no
break

# line 0 will evaluate as false so need to be explicit here
if header_line_no is not None:
# If we have a header line, in the text above the viewport,
# update the top_left_char value
cursor_line_no = self.edit_area.get_line_num(top_left_char)
char_count = len('\n'.join(lines[header_line_no:cursor_line_no]))

top_left_char -= char_count

# This will catch any errors if the char_count goes wrong
if top_left_char < 0:
top_left_char = 0

return top_left_char
else:
return top_left_char

def pad_bottom_viewport_caret(self, bottom_left_char, text):
'''
Adds two lines to the bottom of the viewport so we dont have any
unhighlighted lines visible.
'''

# Test that there is text in the edit area
if len(text) == 0:
return bottom_left_char

# slice text to only contain the characters below the viewport
text_below = text[bottom_left_char:]

# Check there is text below the viewport
if len(text_below) == 0:
return bottom_left_char

# Split the text below the viewport into lines
lines = text_below.split('\n')

# Get no of chars on the last line of the viewport and the next 2 lines
char_count = len('\n'.join(lines[:3]))
bottom_left_char += char_count

return bottom_left_char

def update_error_lines(self, caret_line, no_of_lines, flag):
'''
Given a caret line number, a number of lines and a flag indicating
whether the error lines need incremented ('insert') or decremented
('remove'). Update the line numbers of the keys in the dictionary
self.validation_errors so that error highlighting follows broken lines
during editing.
'''

# If the supplied edit does not add or remove any lines, do nothing
if no_of_lines < 1:
return

error_lines = self.validation_errors.keys()

# For legacy reasons the keys are strings, but we need ints
e_lines_int = [int(a) for a in error_lines]

# We only care about edits hapenning above error lines
if caret_line > max(e_lines_int):
return

# We need the line end position and the caret position
positions = self.getLinePositions(self.view.oldtext)
caret_pos = self.edit_area.getCaretPosition()
line_end = positions[caret_line - 1][1]

tmp = {}
for q, err in enumerate(e_lines_int):
# We are above an error line or on an error line but not at its end
if (err > caret_line) or (err == caret_line and
caret_pos != line_end):
fixed_line_no = self.line_fix(e_lines_int[q], no_of_lines,
flag)

# rebuild self.controller.validation_errors
tmp[str(fixed_line_no)] = self.validation_errors[str(err)]

# We are below or after the error lines so do nothing
else:
tmp[str(err)] = self.validation_errors[str(err)]

# Write the updated line numbers to the error dictionary
self.validation_errors = tmp

def line_fix(self, e_line_no, no_of_lines, flag):
'''
Helper function containing the logic for incrementing or decrementing
line numbers
'''
if flag == 'insert':
e_line_no += no_of_lines
elif flag == 'remove':
e_line_no -= no_of_lines
# handle potential out of bounds - 1 is top of the file
if e_line_no < 1:
e_line_no = 1

return e_line_no

def syntax_highlight(self, top_caret=None, bottom_caret=None):
'''
Short hand for syntax highlighting. Takes the line bounds.
'''
if top_caret is not None and bottom_caret is not None:
top_line, bottom_line = self.get_viewport_top_bottom(top_caret,
bottom_caret)
self.syntax_highlighter.syntax_highlight(top_line,
bottom_line,
top_caret,
bottom_caret)
else:
self.syntax_highlighter.syntax_highlight()

def highlight_matches(self, matches, offset, current_match=None):
self.syntax_highlighter.highlight_matches(matches,
Expand Down Expand Up @@ -182,3 +333,26 @@ def getPositionFromLine(self, text, line_num):
pos = 0

return pos

def getLinePositions(self, text):
'''
Given a block of text, return the caret positions
at the start and end of each line as a list of tuples in the order
(start, end) assuming left to right text.
The hacky list addition is to handle off by one errors as the 1st line
starts at position 0, whereas every other line starts at +1 past the
end of the last line and we also need to add in the final line length
manually.
'''
if len(text) > 0:
compiled = re.compile(r"\n")
textiter = compiled.finditer(text)
pos = [m.start() for m in textiter]
else:
return [(0, 0)]

# Build lists of the starts and ends of each line
starts = [0] + [x + 1 for x in pos]
ends = pos + [len(text)]

return zip(starts, ends)
7 changes: 7 additions & 0 deletions python/nammu/controller/ConsoleController.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class ConsoleController(object):
Creates the console view and handles console actions.
'''
def __init__(self, mainControler):
# Load the config file
self.config = mainControler.config

# Create view with a reference to its controller to handle events
self.view = ConsoleView(self)

# Will also need delegating to parent presenter
self.controller = mainControler
# Need a record of previous messages so we can rebuild the html
Expand All @@ -46,3 +50,6 @@ def clearConsole(self):
Method to clear the console and console_record
'''
self.console_record = []

def refreshConsole(self):
self.view.refreshConsole()
12 changes: 8 additions & 4 deletions python/nammu/controller/EditSettingsController.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def __init__(self, maincontroller):
self.config = self.controller.config
self.load_config()
self.view = EditSettingsView(self, self.working_dir, self.servers,
self.keystrokes, self.languages,
self.projects)
self.console_style, self.keystrokes,
self.languages, self.projects)
self.view.display()

def load_config(self):
Expand All @@ -37,7 +37,7 @@ def load_config(self):
this settings editor.
'''
config_keywords = ['working_dir', 'servers', 'keystrokes',
'languages', 'projects']
'languages', 'projects', 'console_style']
for keyword in config_keywords:
try:
setattr(self, keyword, self.config[keyword])
Expand All @@ -46,7 +46,7 @@ def load_config(self):
keyword)
self.view.display_error(keyword)

def update_config(self, working_dir, server, keystrokes=None,
def update_config(self, working_dir, server, fontsize, keystrokes=None,
languages=None, projects=None):
'''
Update the settings file with the user input.
Expand All @@ -57,5 +57,9 @@ def update_config(self, working_dir, server, keystrokes=None,
# projects will be added later.
self.config['working_dir']['default'] = working_dir
self.config['servers']['default'] = server
self.config['console_style']['fontsize'] = fontsize
self.controller.logger.debug("Settings updated.")
save_yaml_config(self.config)

def refreshConsole(self):
self.controller.consoleController.refreshConsole()
Loading

0 comments on commit 2890215

Please sign in to comment.