Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot index dict_items in Python 3 #33

Open
kwinkunks opened this issue Jan 2, 2018 · 2 comments
Open

Cannot index dict_items in Python 3 #33

kwinkunks opened this issue Jan 2, 2018 · 2 comments

Comments

@kwinkunks
Copy link
Member

kwinkunks commented Jan 2, 2018

OK, I guess this tool is not meant for Python 3. In Python 3, items() on a dictionary must be cast to a list before you can index into it.

Running this:

from PyQt4.QtGui import QApplication
import segyviewlib
qapp = QApplication([])
l = segyviewlib.segyviewwidget.SegyViewWidget(fname)
l.show()

...I get this:

<ipython-input-8-e587dc28b0c1> in <module>()
      2 import segyviewlib
      3 qapp = QApplication([])
----> 4 l = segyviewlib.segyviewwidget.SegyViewWidget(fname)
      5 l.show()

~/anaconda/envs/python36/lib/python3.6/site-packages/segyviewlib-1.1.3.dev2+gc4b38be-py3.6.egg/segyviewlib/segyviewwidget.py in __init__(self, filename, show_toolbar, color_maps, width, height, dpi, segyioargs, parent)
     26         layout = QVBoxLayout()
     27 
---> 28         self._settings_window = SettingsWindow(self._context, self)
     29         self._help_window = HelpWindow(self)
     30 

~/anaconda/envs/python36/lib/python3.6/site-packages/segyviewlib-1.1.3.dev2+gc4b38be-py3.6.egg/segyviewlib/settingswindow.py in __init__(self, context, parent)
    143         self._tree.setColumnWidth(1, 180)
    144 
--> 145         self._build_tree(self._tree, tree_def, self._tree.invisibleRootItem())
    146 
    147         # layout

~/anaconda/envs/python36/lib/python3.6/site-packages/segyviewlib-1.1.3.dev2+gc4b38be-py3.6.egg/segyviewlib/settingswindow.py in _build_tree(self, tree_wdgt, tree_def, root)
    204 
    205     def _build_tree(self, tree_wdgt, tree_def, root):
--> 206         parent, children = tree_def.items()[0]
    207 
    208         # empty label /parent is a special case: either inline with the previous, or skip

TypeError: 'dict_items' object does not support indexing
@kwinkunks
Copy link
Member Author

Update: after downgrading to NumPy v1.11, I got the tool close to working on my Python 3.6 setup, with some other fixes (see below).

I get the expected non-fatal warnings from NumPy about the indices.

Something is throwing a bunch of errors, but I can't see what:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: invalid result from ArraySpinBox.validate()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: invalid result from ArraySpinBox.validate()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: invalid result from ArraySpinBox.validate()

The tool renders but is hung, with the spinning rainbow wheel (on macOS). I'm going to leave it alone now... I'm afraid I don't know a thing about Qt.


In _indexcontroller.py

def update_index(self, index):
    self.index_s_box.update_view(self._indexes, index)
    self.current_index = int(index)  # Index was turning into a float.
    self._update_label()

In colormapcombo.py

def itemText(self, index):
    return str(self.itemData(index, Qt.ToolTipRole))  # Object is already a string.

In layoutcombo.py

def _get_spec(self, index):
    user_data = self.itemData(index)
    return {str(key): value for key, value in user_data.items()}  # user_data is already a dict.

@jokva
Copy link

jokva commented Jan 2, 2018

Hi,

Thanks for the report! You're right, this seems like a 2/3 incompatibility issue, and should be an easy fix (as you point out). It's not immediately obvious to me what's wrong with the spinbox or indices code, but we'll investigate it in the morning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants