Skip to content

Commit

Permalink
made most examples executable again mostly by fixing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Trilarion committed Jul 26, 2017
1 parent f3143b5 commit a3a104d
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 136 deletions.
18 changes: 13 additions & 5 deletions examples/client/audio_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

import sys
"""
Starts an audio player.
"""

import PyQt5.QtWidgets as QtWidgets
import os, sys

import imperialism_remake.client.audio as audio
import lib.qt as qt
from PyQt5 import QtWidgets

from imperialism_remake.client import audio
from imperialism_remake.lib import qt

def playlist_index_changed(position):
print('Next song')
qt.Notification(window, 'Next song', positioner=qt.Relative_Positioner().center_horizontal().south(20))

if __name__ == '__main__':

# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

app = QtWidgets.QApplication([])

window = QtWidgets.QWidget()
Expand All @@ -35,7 +44,6 @@ def playlist_index_changed(position):
# setup sound system and start playing
audio.load_soundtrack_playlist()
audio.setup_soundtrack_player()
audio.setup_soundtrack_player()
audio.soundtrack_playlist.currentIndexChanged.connect(playlist_index_changed)
audio.soundtrack_player.play()

Expand Down
18 changes: 12 additions & 6 deletions examples/client/map_nation_borders_example.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
"""
Calculates the contour of nation maps.
Calculates the contour of nation maps.
"""

import os, sys

from PyQt5 import QtWidgets

import imperialism_remake
from server.scenario import *
from imperialism_remake.base import constants
from imperialism_remake.server.scenario import Scenario


if __name__ == '__main__':

# load scenario
# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

scenario = Scenario()
scenario.load(constants.extend(constants.CORE_SCENARIO_FOLDER, 'Europe1814.scenario'))
# load scenario
scenario = Scenario.from_file(constants.extend(constants.CORE_SCENARIO_FOLDER, 'Europe1814.scenario'))

# nation map
columns = scenario[constants.ScenarioProperty.MAP_COLUMNS]
Expand Down
17 changes: 11 additions & 6 deletions examples/lib/browser_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

"""
Starts the browser. Start with project root as working directory.
Starts the browser. Start with project root as working directory.
"""

import PyQt5.QtWidgets as QtWidgets
import PyQt5.QtCore as QtCore
import os, sys

import imperialism_remake
from base import tools
from lib import qt_webengine
from PyQt5 import QtCore, QtWidgets

from imperialism_remake.base import tools
from imperialism_remake.lib import qt_webengine

if __name__ == '__main__':

# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

app = QtWidgets.QApplication([])

widget = qt_webengine.BrowserWidget(tools.load_ui_icon)
Expand Down
14 changes: 9 additions & 5 deletions examples/lib/network_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

"""
Examples for usages of ExtendedTcpSocket and ExtendedTcpServer from lib.network
Examples for usages of ExtendedTcpSocket and ExtendedTcpServer from lib.network
"""

import sys
import sys, os
import datetime

import PyQt5.QtCore as QtCore
from PyQt5 import QtCore

import imperialism_remake
import lib.network as network
from imperialism_remake.lib import network

PORT = 37846

Expand Down Expand Up @@ -113,6 +112,11 @@ def server_client_sends_something():

if __name__ == '__main__':

# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

app = QtCore.QCoreApplication([])

# create client
Expand Down
18 changes: 13 additions & 5 deletions examples/lib/qt_graphics_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

'''
Tests some of the generic graphics elements in lib/qt
'''
"""
Tests some of the generic graphics elements in lib/qt
"""

import os, sys

from PyQt5 import QtWidgets

import imperialism_remake
import lib.qt as qt
from imperialism_remake.lib import qt


class Window(QtWidgets.QWidget):
def __init__(self):
Expand Down Expand Up @@ -56,6 +58,12 @@ def show_notification(self):
self.notification.show()

if __name__ == '__main__':

# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

app = QtWidgets.QApplication([])

window = Window()
Expand Down
6 changes: 3 additions & 3 deletions examples/lib/yaml_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

'''
YAML test
'''
"""
YAML test
"""

import yaml

Expand Down
3 changes: 0 additions & 3 deletions examples/pyinstaller/pyinstaller_win.bat

This file was deleted.

20 changes: 0 additions & 20 deletions examples/pyinstaller/test_qt5.py

This file was deleted.

24 changes: 0 additions & 24 deletions examples/pyinstaller/test_qt5_with_webengine.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/pyinstaller/test_simple.py

This file was deleted.

23 changes: 12 additions & 11 deletions examples/pyqt5/network_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

'''
Basic actions of QTcpServer, QTcpSocket communication.
'''
"""
Basic actions of QTcpServer, QTcpSocket communication.
"""

from PyQt5 import QtCore, QtNetwork

Expand All @@ -30,14 +30,15 @@ def setup():
server.listen(QtNetwork.QHostAddress.LocalHost, 34543)
client_socket.connectToHost(QtNetwork.QHostAddress.LocalHost, 34543)

if __name__ == '__main__':

app = QtCore.QCoreApplication([])
app = QtCore.QCoreApplication([])

server = QtNetwork.QTcpServer()
server.newConnection.connect(new_server_connection)
client_socket = QtNetwork.QTcpSocket()
client_socket.connected.connect(new_client_connection)
server = QtNetwork.QTcpServer()
server.newConnection.connect(new_server_connection)
client_socket = QtNetwork.QTcpSocket()
client_socket.connected.connect(new_client_connection)

QtCore.QTimer.singleShot(0, setup)
QtCore.QTimer.singleShot(3000, app.quit)
app.exec_()
QtCore.QTimer.singleShot(0, setup)
QtCore.QTimer.singleShot(3000, app.quit)
app.exec_()
6 changes: 3 additions & 3 deletions examples/pyqt5/pyqt_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

'''
Infos about PyQt
'''
"""
Infos about PyQt
"""

from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
from sip import SIP_VERSION_STR
Expand Down
27 changes: 14 additions & 13 deletions examples/pyqt5/webengineview_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>

"""
Simple example of how to show a web view with PyQt5. Uses QtWebEngineWidgets.QtWebEngineView
Simple example of how to show a web view with PyQt5. Uses QtWebEngineWidgets.QtWebEngineView
"""

import PyQt5.QtWidgets as QtWidgets
import PyQt5.QtCore as QtCore
import PyQt5.QtWebEngineWidgets as QtWebEngineWidgets
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets

# create app
app = QtWidgets.QApplication([])
if __name__ == '__main__':

# QWebEngineView
web_view_widget = QtWebEngineWidgets.QWebEngineView()
web_view_widget.titleChanged.connect(web_view_widget.setWindowTitle) # displays the actual page title as windows title
web_view_widget.load(QtCore.QUrl("http://qt-project.org/"))
web_view_widget.show()
# create app
app = QtWidgets.QApplication([])

# run
app.exec_()
# QWebEngineView
web_view_widget = QtWebEngineWidgets.QWebEngineView()
# displays the actual page title as windows title
web_view_widget.titleChanged.connect(web_view_widget.setWindowTitle)
web_view_widget.load(QtCore.QUrl("http://qt-project.org/"))
web_view_widget.show()

# run
app.exec_()
20 changes: 12 additions & 8 deletions examples/server/network_chat_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
Examples for base.network and server.network using chat
"""

import os, sys

from PyQt5 import QtCore

import imperialism_remake
from base import constants, network
from server.server import ServerManager
from imperialism_remake.base import constants, network as base_network
from imperialism_remake.server import server

def clients_connect():
"""
Expand Down Expand Up @@ -73,14 +74,17 @@ def clientB_chats():
clientB.send(constants.C.CHAT, constants.M.CHAT_MESSAGE, 'Hi Alice, how are you?')

if __name__ == '__main__':
imperialism_remake.fix_pyqt5_exception_eating()
imperialism_remake.set_start_directory()

# add source directory to path if needed
source_directory = os.path.realpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.path.pardir, os.path.pardir, 'source'))
if source_directory not in sys.path:
sys.path.insert(0, source_directory)

app = QtCore.QCoreApplication([])

server_manager = ServerManager()
clientA = network.NetworkClient()
clientB = network.NetworkClient()
server_manager = server.ServerManager()
clientA = base_network.NetworkClient()
clientB = base_network.NetworkClient()

# actions
QtCore.QTimer.singleShot(0, server_manager.start)
Expand Down

0 comments on commit a3a104d

Please sign in to comment.