Skip to content

Commit

Permalink
Merge pull request #138 from CadQuery/adam-urbanczyk-release_prep
Browse files Browse the repository at this point in the history
Prepare for 0.1 release
  • Loading branch information
adam-urbanczyk authored May 6, 2020
2 parents 97e1253 + 326bea9 commit cd5a0b6
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 29 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ install:
- cmd: activate cqgui
- conda list
- conda install -c conda-forge pytest=5.2.0 pluggy pytest-qt
- pip install pytest-xvfb pytest-mock pytest-cov pytest-repeat codecov pyvirtualdisplay==0.2.1
- pip install pytest-xvfb pytest-mock pytest-cov pytest-repeat codecov pyvirtualdisplay==0.2.1 EasyProcess==0.2.10

build: false

Expand Down
1 change: 1 addition & 0 deletions cq_editor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._version import __version__
1 change: 1 addition & 0 deletions cq_editor/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
21 changes: 11 additions & 10 deletions cq_editor/main_window.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

from PyQt5.QtWidgets import (QLabel, QMainWindow, QMessageBox, QToolBar,
QDockWidget, QAction)
from PyQt5.QtWidgets import (QLabel, QMainWindow, QToolBar, QDockWidget, QAction)

import cadquery as cq

Expand All @@ -14,7 +13,8 @@
from .widgets.cq_object_inspector import CQObjectInspector
from .widgets.log import LogViewer

from .utils import dock, add_actions, open_url, about_dialog, check_gtihub_for_updates
from . import __version__
from .utils import dock, add_actions, open_url, about_dialog, check_gtihub_for_updates, confirm
from .mixins import MainMixin
from .icons import icon
from .preferences import PreferencesWidget
Expand Down Expand Up @@ -63,10 +63,9 @@ def closeEvent(self,event):

if self.components['editor'].document().isModified():

rv = QMessageBox.question(self, 'Confirm close',
'Close without saving?',
QMessageBox.Yes, QMessageBox.No)
if rv == QMessageBox.Yes:
rv = confirm(self, 'Confirm close', 'Close without saving?')

if rv:
event.accept()
super(MainWindow,self).closeEvent(event)
else:
Expand Down Expand Up @@ -308,9 +307,11 @@ def edit_preferences(self):

def about(self):

about_dialog(self,
'CadQuery GUI (PyQT)',
'Experimental PyQt GUI for CadQuery')
about_dialog(
self,
'CadQuery GUI (PyQT)',
f'Experimental PyQt GUI for CadQuery.\nVersion: {__version__}.'
)

def check_for_cq_updates(self):

Expand Down
14 changes: 6 additions & 8 deletions cq_editor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QFileDialog, QMessageBox

DOCK_POSITIONS = {'right' : QtCore.Qt.RightDockWidgetArea,
'left' : QtCore.Qt.LeftDockWidgetArea,
Expand Down Expand Up @@ -94,14 +94,14 @@ def about_dialog(parent,title,text):
def get_save_filename(suffix):

rv,_ = QFileDialog.getSaveFileName(filter='*.{}'.format(suffix))
if rv is not '' and not rv.endswith(suffix): rv += '.'+suffix
if rv != '' and not rv.endswith(suffix): rv += '.'+suffix

return rv

def get_open_filename(suffix, curr_dir):

rv,_ = QFileDialog.getOpenFileName(directory=curr_dir, filter='*.{}'.format(suffix))
if rv is not '' and not rv.endswith(suffix): rv += '.'+suffix
if rv != '' and not rv.endswith(suffix): rv += '.'+suffix

return rv

Expand All @@ -127,10 +127,8 @@ def check_gtihub_for_updates(parent,

QtWidgets.QMessageBox.about(parent,title,text)

def confirm(parent,title,msg):

rv = QMessageBox.question(parent, title, msg, QMessageBox.Yes, QMessageBox.No)






return True if rv == QMessageBox.Yes else False
31 changes: 25 additions & 6 deletions cq_editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyqtgraph.parametertree import Parameter

from ..mixins import ComponentMixin
from ..utils import get_save_filename, get_open_filename
from ..utils import get_save_filename, get_open_filename, confirm

from ..icons import icon

Expand Down Expand Up @@ -112,17 +112,30 @@ def updatePreferences(self,*args):
self.findChild(QAction, 'autoreload') \
.setChecked(self.preferences['Autoreload'])

def confirm_discard(self):

if self.modified:
rv = confirm(self,'Please confirm','Current document is not saved - do you want to continue?')
else:
rv = True

return rv

def new(self):

if not self.confirm_discard(): return

self.set_text('')
self.filename = ''
self.reset_modified()

def open(self):

if not self.confirm_discard(): return

curr_dir = Path(self.filename).abspath().dirname()
fname = get_open_filename(self.EXTENSIONS, curr_dir)
if fname is not '':
if fname != '':
self.load_from_file(fname)

def load_from_file(self,fname):
Expand All @@ -133,7 +146,7 @@ def load_from_file(self,fname):

def save(self):

if self._filename is not '':
if self._filename != '':

if self.preferences['Autoreload']:
self._file_watcher.removePath(self.filename)
Expand All @@ -150,10 +163,11 @@ def save(self):

else:
self.save_as()

def save_as(self):

fname = get_save_filename(self.EXTENSIONS)
if fname is not '':
if fname != '':
with open(fname,'w') as f:
f.write(self.toPlainText())
self.filename = fname
Expand Down Expand Up @@ -194,17 +208,22 @@ def autoreload(self, enabled):
def reset_modified(self):

self.document().setModified(False)

@property
def modified(self):

return self.document().isModified()

def saveComponentState(self,store):

if self.filename is not '':
if self.filename != '':
store.setValue(self.name+'/state',self.filename)

def restoreComponentState(self,store):

filename = store.value(self.name+'/state',self.filename)

if filename and filename is not '':
if filename and filename != '':
try:
self.load_from_file(filename)
except IOError:
Expand Down
18 changes: 17 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import codecs
import os.path

from setuptools import setup, find_packages

def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
return fp.read()

def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")

setup(name='CQ-editor',
version='0.1.0dev',
version=get_version('cq_editor/_version.py'),
packages=find_packages(),
entry_points={
'gui_scripts': [
Expand Down
38 changes: 35 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,11 @@ def editor(qtbot):

return qtbot, win

def test_editor(monkeypatch,editor):
def conv_line_ends(text):

return '\n'.join(text.splitlines())

def conv_line_ends(text):
return '\n'.join(text.splitlines())
def test_editor(monkeypatch,editor):

qtbot, editor = editor

Expand Down Expand Up @@ -1027,3 +1028,34 @@ def get_rgba(ais):
# check if error occured
qtbot.wait(100)
assert('Unknown color format' in log.toPlainText().splitlines()[-1])

def test_confirm_new(monkeypatch,editor):

qtbot, editor = editor

#check that initial state is as expected
assert(editor.modified == False)

editor.document().setPlainText(code)
assert(editor.modified == True)

#monkeypatch the confirmation dialog and run both scenarios
def cancel(*args, **kwargs):
return QMessageBox.No

def ok(*args, **kwargs):
return QMessageBox.Yes

monkeypatch.setattr(QMessageBox, 'question',
staticmethod(cancel))

editor.new()
assert(editor.modified == True)
assert(conv_line_ends(editor.get_text_with_eol()) == code)

monkeypatch.setattr(QMessageBox, 'question',
staticmethod(ok))

editor.new()
assert(editor.modified == False)
assert(editor.get_text_with_eol() == '')

0 comments on commit cd5a0b6

Please sign in to comment.