Add rocket ship animation

This commit is contained in:
Micah Lee 2022-02-13 15:33:13 -08:00
parent e168080b77
commit 0250384280
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
7 changed files with 120 additions and 7 deletions

View File

@ -20,8 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import os
import random
import time
from PySide2 import QtCore, QtWidgets, QtGui
from onionshare_cli.censorship import (
@ -51,13 +49,14 @@ class AutoConnectTab(QtWidgets.QWidget):
tor_is_connected = QtCore.Signal()
tor_is_disconnected = QtCore.Signal()
def __init__(self, common, tab_id, status_bar, parent=None):
def __init__(self, common, tab_id, status_bar, window, parent=None):
super(AutoConnectTab, self).__init__()
self.common = common
self.common.log("AutoConnectTab", "__init__")
self.status_bar = status_bar
self.tab_id = tab_id
self.window = window
self.parent = parent
# Was auto connected?
@ -65,6 +64,11 @@ class AutoConnectTab(QtWidgets.QWidget):
self.curr_settings.load()
self.auto_connect_enabled = self.curr_settings.get("auto_connect")
# Rocket ship animation images
self.anim_stars = AnimStars(self, self.window)
self.anim_ship = AnimShip(self, self.window)
self.anim_smoke = AnimSmoke(self, self.window)
# Onionshare logo
self.image_label = QtWidgets.QLabel()
self.image_label.setPixmap(
@ -108,6 +112,9 @@ class AutoConnectTab(QtWidgets.QWidget):
self.tor_con = TorConnectionWidget(self.common, self.status_bar)
self.tor_con.success.connect(self.tor_con_success)
self.tor_con.fail.connect(self.tor_con_fail)
self.tor_con.update_progress.connect(self.anim_stars.update)
self.tor_con.update_progress.connect(self.anim_ship.update)
self.tor_con.update_progress.connect(self.anim_smoke.update)
self.tor_con.hide()
# Layout
@ -328,6 +335,102 @@ class AutoConnectTab(QtWidgets.QWidget):
self.first_launch_widget.show()
class Anim(QtWidgets.QLabel):
"""
Rocket ship animation base class
"""
force_update = QtCore.Signal(int)
def __init__(self, parent, window, w, h, filename):
super(Anim, self).__init__(parent=parent)
self.window = window
self.window.window_resized.connect(self.update_same_percent)
self.w = w
self.h = h
self.percent = 0
self.used_percentages = []
self.setPixmap(
QtGui.QPixmap.fromImage(
QtGui.QImage(
GuiCommon.get_resource_path(os.path.join("images", filename))
)
)
)
self.setFixedSize(self.w, self.h)
self.update(0)
self.force_update.connect(self.update)
def update_same_percent(self):
self.update(self.percent)
def update(self, percent):
self.percent = percent
self.move()
self.setGeometry(int(self.x), int(self.y), int(self.w), int(self.h))
def move(self):
# Implement in child
pass
class AnimStars(Anim):
"""
Rocket ship animation part: stars
"""
def __init__(self, parent, window):
super(AnimStars, self).__init__(
parent, window, 780, 629, "tor-connect-stars.png"
)
def move(self):
self.x = self.window.width() - self.w
self.y = 0
# Stars don't move until 10%, then move down
if self.percent >= 10:
self.y += self.percent * 6.6
class AnimShip(Anim):
"""
Rocket ship animation part: ship
"""
def __init__(self, parent, window):
super(AnimShip, self).__init__(parent, window, 239, 545, "tor-connect-ship.png")
def move(self):
self.x = self.window.width() - self.w - 150
self.y = self.window.height() - self.h - 40
# Ship moves up
self.y -= self.percent * 6.6
class AnimSmoke(Anim):
"""
Rocket ship animation part: smoke
"""
def __init__(self, parent, window):
super(AnimSmoke, self).__init__(
parent, window, 522, 158, "tor-connect-smoke.png"
)
def move(self):
self.x = self.window.width() - self.w
self.y = self.window.height() - self.h + 50
# Smoke moves up until 50%, then moves down
self.y -= self.percent * 6.6
if self.percent >= 50:
self.y += self.percent * 6.6
class AutoConnectFirstLaunchWidget(QtWidgets.QWidget):
"""
When you first launch OnionShare, this is the widget that is displayed
@ -346,7 +449,6 @@ class AutoConnectFirstLaunchWidget(QtWidgets.QWidget):
# Description and checkbox
description_label = QtWidgets.QLabel(strings._("gui_autoconnect_description"))
description_label.setWordWrap(True)
self.enable_autoconnect_checkbox = ToggleCheckbox(
strings._("gui_enable_autoconnect_checkbox")
)

View File

@ -36,6 +36,8 @@ class MainWindow(QtWidgets.QMainWindow):
MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs
"""
window_resized = QtCore.Signal()
def __init__(self, common, filenames):
super(MainWindow, self).__init__()
@ -140,7 +142,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.status_bar.addPermanentWidget(self.settings_button)
# Tabs
self.tabs = TabWidget(self.common, self.system_tray, self.status_bar)
self.tabs = TabWidget(self.common, self.system_tray, self.status_bar, self)
self.tabs.bring_to_front.connect(self.bring_to_front)
# If we have saved persistent tabs, try opening those
@ -335,3 +337,7 @@ class MainWindow(QtWidgets.QMainWindow):
# Wait 1 second for threads to close gracefully, so tests finally pass
time.sleep(1)
def resizeEvent(self, event):
self.window_resized.emit()
return super(MainWindow, self).resizeEvent(event)

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -38,13 +38,14 @@ class TabWidget(QtWidgets.QTabWidget):
bring_to_front = QtCore.Signal()
def __init__(self, common, system_tray, status_bar):
def __init__(self, common, system_tray, status_bar, window):
super(TabWidget, self).__init__()
self.common = common
self.common.log("TabWidget", "__init__")
self.system_tray = system_tray
self.status_bar = status_bar
self.window = window
# Keep track of tabs in a dictionary that maps tab_id to tab.
# Each tab has a unique, auto-incremented id (tab_id). This is different than the
@ -219,7 +220,7 @@ class TabWidget(QtWidgets.QTabWidget):
return
connection_tab = AutoConnectTab(
self.common, self.current_tab_id, self.status_bar, parent=self
self.common, self.current_tab_id, self.status_bar, self.window, parent=self
)
connection_tab.close_this_tab.connect(self.close_connection_tab)
connection_tab.tor_is_connected.connect(self.tor_is_connected)

View File

@ -49,6 +49,7 @@ class TorConnectionWidget(QtWidgets.QWidget):
open_tor_settings = QtCore.Signal()
success = QtCore.Signal()
fail = QtCore.Signal(str)
update_progress = QtCore.Signal(int)
def __init__(self, common, status_bar):
super(TorConnectionWidget, self).__init__(None)
@ -120,6 +121,7 @@ class TorConnectionWidget(QtWidgets.QWidget):
def _tor_status_update(self, progress, summary):
self.progress.setValue(int(progress))
self.update_progress.emit(int(progress))
self.label.setText(
f"<strong>{strings._('connecting_to_tor')}</strong><br>{summary}"
)
@ -131,6 +133,7 @@ class TorConnectionWidget(QtWidgets.QWidget):
# Close the dialog after connecting
self.progress.setValue(self.progress.maximum())
self.update_progress.emit(int(self.progress.maximum()))
self.success.emit()
self._reset()
@ -153,6 +156,7 @@ class TorConnectionWidget(QtWidgets.QWidget):
def _reset(self):
self.label.setText("")
self.progress.setValue(0)
self.update_progress.emit(0)
class TorConnectionThread(QtCore.QThread):