Skip to content

Commit

Permalink
Merge pull request #84 from chipmuenk/update_coeff_ui
Browse files Browse the repository at this point in the history
Bugfixes in fiter_coefficient.py UI
  • Loading branch information
chipmuenk committed Oct 16, 2017
2 parents a6fa591 + e9b47f0 commit 5acd2a3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 46 deletions.
3 changes: 0 additions & 3 deletions pyfda/filterbroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
# Project base directory
base_dir = ""

# store old data when modifying a field for restoring if new data is invalid
data_old = ""

# State of filter design: "ok", "changed", "error", "failed"
design_filt_state = "changed"

Expand Down
17 changes: 6 additions & 11 deletions pyfda/input_widgets/filter_coeffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import pyfda.pyfda_fix_lib as fix

# TODO: Clipboard functionality: CSD data is copied with leading blanks
# TODO: fb.data_old needed?!
# TODO: copy back handling of complex data from filter_pz to here

# TODO: Setting complex data (manually) crashes the app in setModelData():
Expand Down Expand Up @@ -158,13 +157,13 @@ def displayText(self, text, locale):
The instance parameter myQ.ovr_flag is set to +1 or -1 for positive /
negative overflows, else it is 0.
"""
string = qstr(text) # convert to "normal" string
data_str = qstr(text) # convert to "normal" string

if self.parent.myQ.frmt == 'float':
data = safe_eval(string, return_type='auto')
data = safe_eval(data_str, return_type='auto') # convert to float
return "{0:.{1}g}".format(data, params['FMT_ba'])
else:
return "{0:>{1}}".format(self.parent.myQ.float2frmt(string),
return "{0:>{1}}".format(self.parent.myQ.float2frmt(data_str),
self.parent.myQ.places)

# see: http://stackoverflow.com/questions/30615090/pyqt-using-qtextedit-as-editor-in-a-qstyleditemdelegate
Expand Down Expand Up @@ -194,17 +193,14 @@ def setEditorData(self, editor, index):
"""
Pass the data to be edited to the editor:
- retrieve data with full accuracy from self.ba (in float format)
- store data in fb.data_old in float format
- requantize data according to settings in fixpoint object
- represent it in the selected format (int, hex, ...)
editor: instance of e.g. QLineEdit
index: instance of QModelIndex
"""
# data = qstr(index.data()) # get data from QTableWidget
data = self.parent.ba[index.column()][index.row()] # data from self.ba
fb.data_old = data # store old data in floating point format
data_str = qstr(safe_eval(data, return_type='auto'))
data_str = qstr(safe_eval(self.parent.ba[index.column()][index.row()], return_type="auto"))

if self.parent.myQ.frmt == 'float':
# floating point format: pass data with full resolution
Expand Down Expand Up @@ -234,7 +230,8 @@ def setModelData(self, editor, model, index):
# else:
# super(ItemDelegate, self).setModelData(editor, model, index)
if self.parent.myQ.frmt == 'float':
data = safe_eval(qstr(editor.text()), fb.data_old, return_type='auto') # raw data without fixpoint formatting
data = safe_eval(qstr(editor.text()),
self.parent.ba[index.column()][index.row()], return_type='auto') # raw data without fixpoint formatting
else:
data = self.parent.myQ.frmt2float(qstr(editor.text()),
self.parent.myQ.frmt) # transform back to float
Expand Down Expand Up @@ -1080,8 +1077,6 @@ def _add_cells(self):

self._equalize_ba_length()
self._refresh_table()
qstyle_widget(self.butSave, 'changed')


#------------------------------------------------------------------------------
def _set_eps(self):
Expand Down
8 changes: 4 additions & 4 deletions pyfda/input_widgets/filter_pz.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def setEditorData(self, editor, index):
"""
# data = qstr(index.data()) # get data from QTableWidget
data = self.parent.zpk[index.column()][index.row()]
fb.data_old = data # store old data in floating point format
data_str = qstr(safe_eval(data, return_type="auto"))

editor.setText(data_str)


Expand All @@ -154,9 +152,11 @@ def setModelData(self, editor, model, index):
# else:
# super(ItemDelegate, self).setModelData(editor, model, index)
if qget_cmb_box(self.parent.ui.cmbPZFrmt, data=False) == 'Cartesian':
data = safe_eval(qstr(editor.text()), fb.data_old, return_type="auto") # raw data without reformatting
data = safe_eval(qstr(editor.text()),
self.parent.zpk[index.column()][index.row()], return_type="auto") # raw data without reformatting
else:
data = safe_eval(qstr(editor.text()), fb.data_old, return_type="auto") # same for now
data = safe_eval(qstr(editor.text()),
self.parent.zpk[index.column()][index.row()], return_type="auto") # same for now

model.setData(index, data) # store in QTableWidget
self.parent.zpk[index.column()][index.row()] = data # and in self.ba
Expand Down
24 changes: 1 addition & 23 deletions pyfda/pyfda_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,6 @@ def extract_file_ext(file_type):
return [t.strip('(*)') for t in ext_list] # remove '(*)'

#------------------------------------------------------------------------------
def qstr(data):
"""
Convert object (QVariant, QSTring, string, number) to string.
In Python 3, python Qt objects are automatically converted to QVariant
when stored as "data" e.g. in a QComboBox and converted back when
retrieving. In Python 2, QVariant is returned when itemData is retrieved.
This is first converted from the QVariant container format to a
QString, next to a "normal" non-unicode string.
Returns:
The current text / QVariant data as a string
"""
if "QVariant" in str(type(data)):
# Python 2: convert QVariant -> QString -> str
string = str(data.toString())
else:
# `data` is of type str already, is numeric or is a QString (Py3)
string = str(data)
return string


def dB(lin, power = False):
"""
Expand Down Expand Up @@ -1177,7 +1155,7 @@ def fil_save(fil_dict, arg, format_in, sender, convert = True):
else:
a = a[:D] # discard last D elements of a (only zeros anyway)

fil_dict['ba'] = [b, a]
fil_dict['ba'] = [b.astype(np.complex), a.astype(np.complex)]

else:
raise ValueError("Unknown input format {0:s}".format(format_in))
Expand Down
10 changes: 5 additions & 5 deletions pyfda/pyfda_qt_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import csv
import io
import numpy as np
from .pyfda_lib import PY3
from .pyfda_lib import PY3, safe_eval
from .pyfda_rc import params

from .compat import (QFrame, QLabel, QComboBox, QDialog, QPushButton,
Expand Down Expand Up @@ -382,7 +382,7 @@ def qcopy_to_clipboard(table, data, target, frmt='float'):
if use_header: # add the table header
text += table.horizontalHeaderItem(c).text() + tab
for r in range(num_rows):
text += str(data[c][r]) + tab
text += str(safe_eval(data[c][r], return_type='auto')) + tab
text = text.rstrip(tab) + cr
text = text.rstrip(cr) # delete last cr
else: # rows are vertical
Expand All @@ -392,7 +392,7 @@ def qcopy_to_clipboard(table, data, target, frmt='float'):
text = text.rstrip(tab) + cr
for r in range(num_rows):
for c in range(num_cols):
text += str(data[c][r]) + tab
text += str(safe_eval(data[c][r], return_type='auto')) + tab
text = text.rstrip(tab) + cr
text = text.rstrip(cr) # delete CRLF after last row

Expand All @@ -408,7 +408,7 @@ def qcopy_to_clipboard(table, data, target, frmt='float'):
for r in sel[0]:
item = table.item(r,0)
if item and item.text() != "":
text += table.itemDelegate().text(item) + tab
text += table.itemDelegate().text(item).lstrip(" ") + tab
text = text.rstrip(tab) # remove last tab delimiter again

if sel[1]: # returns False for []
Expand Down Expand Up @@ -440,7 +440,7 @@ def qcopy_to_clipboard(table, data, target, frmt='float'):
item = table.item(r,c)
print(c,r)
if item and item.text() != "":
text += table.itemDelegate().text(item) + tab
text += table.itemDelegate().text(item).lstrip(" ") + tab
text = text.rstrip(tab) + cr
text.rstrip(cr)

Expand Down

0 comments on commit 5acd2a3

Please sign in to comment.