Skip to content

Commit

Permalink
Added instructions to update the sw correctly and fixed settings upda…
Browse files Browse the repository at this point in the history
…te between versions
  • Loading branch information
texx00 committed Oct 3, 2020
1 parent a7b2ce9 commit dea56f3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion UIserver/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function save(connect = false){
port : $("#serial_ports").val(),
baud : $("#serial_baud").val()
},
dimensions : {
device : {
width: $("#device_width").val(),
height : $("#device_height").val()
},
Expand Down
7 changes: 5 additions & 2 deletions UIserver/templates/preferences/manual_control.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h3>Gcode command: </h3>
<div>
<canvas id="path_canvas" class="w-100 border-primary border-1"></canvas>
</div>
<div id="device_width" class="data">{{settings.dimensions.width}}</div>
<div id="device_height" class="data">{{settings.dimensions.height}}</div>
<div id="device_width" class="data">{{settings.device.width}}</div>
<div id="device_height" class="data">{{settings.device.height}}</div>
</div>
</div>
<div class="row">
Expand All @@ -33,6 +33,9 @@ <h3>Gcode command: </h3>

</div>
</div>
<div class="p-5">

</div>
</div>
<!-- TODO add button to move it manualy or launch specific gcodes/files (for example to make the referencing or run a cleaning script)-->
{%endblock%}
6 changes: 3 additions & 3 deletions UIserver/templates/preferences/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ <h3>Dimensions</h3><!-- TODO should add type (rectangular or round/gcode or thr)
<div class="col">
<div>
<p class="d-block">Width</p>
<input id="device_width" value="{{settings.dimensions.width}}"></input>
<input id="device_width" value="{{settings.device.width}}"></input>
</div>
</div>
<div class="col">
<div>
<p class="d-block">Height</p>
<input id="device_height" value="{{settings.dimensions.height}}"></input>
<input id="device_height" value="{{settings.device.height}}"></input>
</div>
</div>
</div>
Expand All @@ -68,7 +68,7 @@ <h3>Scripts</h3>
</div>
</div>
</div>
<div class="center_h add_space_before">
<div class="center_h add_space_before mb-5">
<button id="save_button" onclick="save()">Save settings</button>
</div>
<!-- TODO better management and layout for the settings. should save only the one changed and ask before leaving if at least one was changed (also, add a color change for the settings changed?)-->
Expand Down
25 changes: 23 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,33 @@ It may happen that the serial port is not working correctly.
In this case activate the environment, uninstall the "serial" and the "pyserial" modules and install again the "pyserial":
```
$> source env/bin/activate
python3 -m pip uninstall serial pyserial
python3 -m pip install pyserial
(env) $> python3 -m pip uninstall serial pyserial
(env) $> python3 -m pip install pyserial
```

If you find any bug or problem please open an issue in the dedicated page.

# Updates

To update to the last available version of the software in linux you can run the following commands:

```
$> source env/bin/activate
(env) $> git pull
(env) $> sh install.sh
```

If you are working on Windows you should use instead:

```
$> source env/bin/activate
(env) $> git pull
(env) $> install.bat
```

Some browser may cache the scripts. If you get any error try to clean the cache of your browser related to the sandipy site.


# Development and testing

Any help in the app development is accepted.
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import time
import platform
import os

from utils import settings_utils

class PostDevelopCommand(develop):
def run(self):
develop.run(self)
print("Running post develop script")
settings_utils.update_settings_file_version()

class PostInstallCommand(install):
def run(self):
install.run(self)
print("Running post install script")
settings_utils.update_settings_file_version()

setup(
name='UIserver',
Expand Down
35 changes: 32 additions & 3 deletions utils/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,46 @@
import json

settings_path = "./UIserver/saves/saved_settings.json"
defaults_path = "UIserver/saves/default_settings.json"

def save_settings(settings):
dataj = json.dumps(settings)
with open(settings_path,"w") as f:
f.write(dataj)

def load_settings():
if(not os.path.exists(settings_path)):
shutil.copyfile("UIserver/saves/default_settings.json", settings_path)
settings = ""
with open(settings_path) as f:
settings = json.load(f)
return settings


def update_settings_file_version():
print("Updating settings save files")
if(not os.path.exists(settings_path)):
shutil.copyfile(defaults_path, settings_path)
else:
old_settings = load_settings()
def_settings = ""
with open(defaults_path) as f:
def_settings = json.load(f)

new_settings = match_dict(old_settings, def_settings)
save_settings(new_settings)

def match_dict(mod_dict, ref_dict):
new_dict = {}
for k in ref_dict.keys():
if k in mod_dict:
if type(mod_dict[k]) is dict:
new_dict[k] = match_dict(mod_dict[k], ref_dict[k])
else:
new_dict[k] = mod_dict[k]
else:
new_dict[k] = ref_dict[k]
return new_dict

if __name__ == "__main__":
# testing update_settings_file_version
settings_path = "../"+settings_path
defaults_path = "../"+defaults_path
update_settings_file_version()

0 comments on commit dea56f3

Please sign in to comment.