Repository: spyder-ide/spyder

Issue:
Error when drag and drop file from zip
## Description

**What steps will reproduce the problem?**

1. 
2. 
3. 

**What is the expected output? What do you see instead?**
Tried to drag and drop file into Spyder. Gave me error and took me here. 

**Please provide any additional information below**

  File "C:\Users\david.antonini\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\widgets\editor.py", line 2171, in dragEnterEvent
    text = [encoding.is_text_file(url) for url in all_urls]
TypeError: 'NoneType' object is not iterable


## Version and main components

* Spyder Version: 3.2.1 
* Python Version: 3.6.1
* Qt Versions: 5.6.2, PyQt5 5.6 on Windows

## Dependencies
```
pyflakes >=0.6.0 :  1.5.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.1 (OK)
numpy >=1.7      :  1.12.1 (OK)
sphinx >=0.6.6   :  1.5.6 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.1.1 (OK)
sympy >=0.7.3    :  1.0 (OK)
cython >=0.21    :  0.25.2 (OK)
qtconsole >=4.2.0:  4.3.0 (OK)
IPython >=4.0    :  5.3.0 (OK)
pylint >=0.25    :  1.6.4 (OK)

```



Discussion:
>Tried to drag and drop file into Spyder. Gave me error and took me here.

@toonarmycaptain what type of file ?
It was a .py
I figured afterwards that it was probably since it was housed within a zip file at the time, when unzipped it worked fine.
________________________________
From: Gonzalo Peña-Castellanos <notifications@github.com>
Sent: Tuesday, September 12, 2017 4:25:51 PM
To: spyder-ide/spyder
Cc: toonarmycaptain; Mention
Subject: Re: [spyder-ide/spyder] drag and drop file (#5218)


Tried to drag and drop file into Spyder. Gave me error and took me here.

@toonarmycaptain<https://github.com/toonarmycaptain> what type of file ?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://github.com/spyder-ide/spyder/issues/5218#issuecomment-328988982>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AckbHtT2Icm8B3ZQ1Jfh-1pDSZA2FfTPks5shvbfgaJpZM4PVMD8>.

I'd add that, particularly since other software will work with this (ie I can drag and drop files from zip archives into Word or Paint etc and they open), such functionality would be useful, as users could reasonably expect it to work. Even if the file opened as a 'new' script, rather than a saved/named one.
This was working before. We'll fix it in a future release.
@dalthviz, I think this only happens on Windows.
@ccordoba12 and @dalthviz I can reproduce it on master in Python 3.6.2 64bits, Qt 5.9.2, PyQt5 5.9.1 on Windows 7

Resolving patch:
diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py
--- a/spyder/widgets/editor.py
+++ b/spyder/widgets/editor.py
@@ -2249,7 +2249,10 @@ def dragEnterEvent(self, event):
         source = event.mimeData()
         # The second check is necessary on Windows, where source.hasUrls()
         # can return True but source.urls() is []
-        if source.hasUrls() and source.urls():
+        # The third check is needed since a file could be dropped from
+        # compressed files. In Windows mimedata2url(source) returns None
+        # Fixes issue 5218
+        if source.hasUrls() and source.urls() and mimedata2url(source):
             all_urls = mimedata2url(source)
             text = [encoding.is_text_file(url) for url in all_urls]
             if any(text):


Test patch: