From d1c36fa04f82079def2e7cf36c13f259df8b7df2 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 15 Feb 2016 13:06:12 -0800 Subject: [PATCH] Got python3/Qt5 port working in Windows, but still need to finish packaging (#261) --- BUILD.md | 16 ++++++++-------- install/onionshare-launcher.py | 5 ++--- install/onionshare-win.spec | 7 ++++--- onionshare_gui/server_status.py | 18 ++---------------- 4 files changed, 16 insertions(+), 30 deletions(-) diff --git a/BUILD.md b/BUILD.md index 27f7a30c..1055ac71 100644 --- a/BUILD.md +++ b/BUILD.md @@ -100,24 +100,24 @@ Now you should have `dist/OnionShare.pkg`. ### Setting up your dev environment -TODO: Still need to make this working in Windows with Python3. +These instructions include adding folders to the path in Windows. To do this, go to Start and type "advanced system settings", and open "View advanced system settings" in the Control Panel. Click Environment Variables. Under "System variables" double-click on Path. From there you can add and remove folders that are available in the PATH. -Install the [latest Python 3.x from python.org](https://www.python.org/downloads/). While installing, check the box "Add Python 3.x to PATH". +First, download and install the 32-bit (x86) version of Python 3.4.x from https://www.python.org/downloads/windows/. You need 3.4 instead of 3.5 because PyQt5 was built with 3.4. Add `C:\Python34` and `C:\Python34\Scripts` to the path. Open a command prompt and install some dependencies with pip: `pip install flask stem pyinstaller` Download and install Qt5 from https://www.qt.io/download-open-source/. I downloaded `qt-unified-windows-x86-2.0.2-2-online.exe`. There's no need to login to a Qt account during installation. Make sure you install the latest Qt 5.x. -Download and install the latest PyQt5 for 32-bit Windows from https://www.riverbankcomputing.com/software/pyqt/download5. I downloaded `PyQt5-5.5.1-gpl-Py3.4-Qt5.5.1-x32.exe`. Make sure to install it to the location where you installed Python (in my case, `C:\Users\micah\AppData\Local\Programs\Python\Python35-32\`). +Download and install the latest PyQt5 for 32-bit Windows from https://www.riverbankcomputing.com/software/pyqt/download5. I downloaded `PyQt5-5.5.1-gpl-Py3.4-Qt5.5.1-x32.exe`. -Download and install the latest 32-bit pywin32 binary for Python 3.5 from http://sourceforge.net/projects/pywin32/. I downloaded `pywin32-220.win32-py3.5.exe`. +Download and install the latest 32-bit pywin32 binary for Python 3.4 from http://sourceforge.net/projects/pywin32/. I downloaded `pywin32-220.win32-py3.4.exe`. Download and install the [Microsoft Visual C++ 2008 Redistributable Package (x86)](http://www.microsoft.com/en-us/download/details.aspx?id=29). If you want to build the installer: * Go to http://nsis.sourceforge.net/Download and download the latest NSIS. I downloaded `nsis-3.0b0-setup.exe`. -* Go to Start and type "advanced system settings", and open "View advanced system settings" in the Control Panel. Click Environment Variables. Under "System variables" double-click on Path, and add `C:\Program Files (x86)\NSIS` to the end. Now you can just type `makensis [script]` to build an installer. +* Add `C:\Program Files (x86)\NSIS` to the path. If you want to sign binaries with Authenticode: @@ -126,10 +126,10 @@ If you want to sign binaries with Authenticode: * Windows 7: * Go to http://msdn.microsoft.com/en-us/vstudio/aa496123 and install the latest .NET Framework. I installed `.NET Framework 4.6`. * Go to http://www.microsoft.com/en-us/download/confirmation.aspx?id=8279 and install the Windows SDK. - * Right click on Computer, go to Properties. Click "Advanced system settings". Click Environment Variables. Under "System variables" double-click on Path and add `C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin` to the end. + * Add `C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin` to the path. * Windows 10: * Go to https://dev.windows.com/en-us/downloads/windows-10-sdk and install the standalone Windows 10 SDK. Note that you may not need this if you already have Visual Studio. - * Go to Start and type "advanced system settings", and open "View advanced system settings" in the Control Panel. Click Environment Variables. Under "System variables" double-click on Path, and add `C:\Program Files (x86)\Windows Kits\10\bin\x86`. + * Add `C:\Program Files (x86)\Windows Kits\10\bin\x86` to the path. ### To make a .exe: @@ -138,7 +138,7 @@ If you want to sign binaries with Authenticode: ### To build the installer: Note that you must have a codesigning certificate installed in order to use the `install\build_exe.bat` script, because it codesigns `onionshare.exe`, `uninstall.exe`, and `OnionShare_Setup.exe`. - +s Open a command prompt, cd to the onionshare directory, and type: `install\build_exe.bat` This will prompt you to codesign three binaries and execute one unsigned binary. When you're done clicking through everything you will have `dist\OnionShare_Setup.exe`. diff --git a/install/onionshare-launcher.py b/install/onionshare-launcher.py index 6a6a1627..83c8e910 100644 --- a/install/onionshare-launcher.py +++ b/install/onionshare-launcher.py @@ -19,11 +19,10 @@ along with this program. If not, see . """ from __future__ import division import os, sys, subprocess, time, hashlib, platform, json, locale, socket -import argparse, Queue, inspect, base64, random, functools, logging, ctypes +import argparse, queue, inspect, base64, random, functools, logging, ctypes import hmac, shutil -from itertools import izip import stem, stem.control, flask -from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtWidgets, QtGui import onionshare, onionshare_gui diff --git a/install/onionshare-win.spec b/install/onionshare-win.spec index b93470be..332bee2d 100644 --- a/install/onionshare-win.spec +++ b/install/onionshare-win.spec @@ -1,7 +1,7 @@ # -*- mode: python -*- a = Analysis(['onionshare-launcher.py'], - hiddenimports=['onionshare', 'onionshare_gui'], - excludes=['_tkinter'], + #hiddenimports=['onionshare', 'onionshare_gui'], + #excludes=['_tkinter'], hookspath=None, runtime_hooks=None) a.datas += [ @@ -22,6 +22,7 @@ a.datas += [ ('locale/pt.json', 'locale/pt.json', 'DATA'), ('locale/ru.json', 'locale/ru.json', 'DATA'), ('locale/tr.json', 'locale/tr.json', 'DATA'), + ('version', 'version', 'DATA'), ] pyz = PYZ(a.pure) exe = EXE(pyz, @@ -32,7 +33,7 @@ exe = EXE(pyz, strip=False, upx=True, icon='install/onionshare.ico', - console=False ) + console=False) coll = COLLECT(exe, a.binaries, a.zipfiles, diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py index 6e1ff0d4..9f79b727 100644 --- a/onionshare_gui/server_status.py +++ b/onionshare_gui/server_status.py @@ -161,21 +161,7 @@ class ServerStatus(QtWidgets.QVBoxLayout): """ url = 'http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug) - if platform.system() == 'Windows': - # Qt's QClipboard isn't working in Windows - # https://github.com/micahflee/onionshare/issues/46 - import ctypes - GMEM_DDESHARE = 0x2000 - ctypes.windll.user32.OpenClipboard(None) - ctypes.windll.user32.EmptyClipboard() - hcd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(url)) + 1) - pch_data = ctypes.windll.kernel32.GlobalLock(hcd) - ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pch_data), bytes(url)) - ctypes.windll.kernel32.GlobalUnlock(hcd) - ctypes.windll.user32.SetClipboardData(1, hcd) - ctypes.windll.user32.CloseClipboard() - else: - clipboard = self.qtapp.clipboard() - clipboard.setText(url) + clipboard = self.qtapp.clipboard() + clipboard.setText(url) self.url_copied.emit()