Skip to content

Commit

Permalink
Added typehints to two new files.
Browse files Browse the repository at this point in the history
  • Loading branch information
michdcode committed May 4, 2019
1 parent 83276d0 commit 3341d96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SHELL := /bin/bash
mypy: ## Run static type checker
@mypy --ignore-missing-imports securedrop_client
@# Add files that are 100% typed to the below call (eventually just the below line will run so that code without static type hints will fail CI)
@mypy --ignore-missing-imports --disallow-incomplete-defs --disallow-untyped-defs securedrop_client/db.py securedrop_client/crypto.py securedrop_client/config.py
@mypy --ignore-missing-imports --disallow-incomplete-defs --disallow-untyped-defs securedrop_client/db.py securedrop_client/crypto.py securedrop_client/config.py securedrop_client/gui/__init__.py securedrop_client/resources/__init__.py

.PHONY: clean
clean: ## Clean the workspace of generated resources
Expand Down
16 changes: 8 additions & 8 deletions securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SvgToggleButton(QPushButton):
The display size of the SVG, defaults to filling the entire size of the widget.
"""

def __init__(self, on: str, off: str, svg_size=None):
def __init__(self, on: str, off: str, svg_size: str=None):
super().__init__()

# Set layout
Expand All @@ -57,13 +57,13 @@ def __init__(self, on: str, off: str, svg_size=None):
# Make this a toggle button
self.setCheckable(True)

def enable(self):
def enable(self) -> None:
self.setEnabled(True)

def disable(self):
def disable(self) -> None:
self.setEnabled(False)

def set_icon(self, on: str, off: str):
def set_icon(self, on: str, off: str) -> None:
self.icon = load_toggle_icon(on=on, off=off)
self.setIcon(self.icon)

Expand All @@ -87,7 +87,7 @@ class SvgPushButton(QPushButton):
The display size of the SVG, defaults to filling the entire size of the widget.
"""

def __init__(self, normal: str, disabled=None, active=None, selected=None, svg_size=None):
def __init__(self, normal: str, disabled: str=None, active: str=None, selected: str=None, svg_size:str=None) -> None:
super().__init__()

# Set layout
Expand All @@ -103,10 +103,10 @@ def __init__(self, normal: str, disabled=None, active=None, selected=None, svg_s
self.setIcon(self.icon)
self.setIconSize(svg_size) if svg_size else self.setIconSize(QSize())

def enable(self):
def enable(self) -> None:
self.setEnabled(True)

def disable(self):
def disable(self) -> None:
self.setEnabled(False)


Expand All @@ -122,7 +122,7 @@ class SvgLabel(QLabel):
The display size of the SVG, defaults to filling the entire size of the widget.
"""

def __init__(self, filename: str, svg_size=None):
def __init__(self, filename: str, svg_size: str=None) -> None:
super().__init__()

# Remove margins and spacing
Expand Down
10 changes: 5 additions & 5 deletions securedrop_client/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
QDir.addSearchPath('css', resource_filename(__name__, 'css'))


def path(name, resource_dir="images/"):
def path(name: str, resource_dir: str = "images/") -> str:
"""
Return the filename for the referenced image.
Expand Down Expand Up @@ -63,7 +63,7 @@ def load_toggle_icon(on: str, off: str) -> QIcon:
return icon


def load_icon(normal: str, disabled: str = None, active=None, selected=None) -> QIcon:
def load_icon(normal: str, disabled: str=None, active: str=None, selected: str=None) -> QIcon:
"""
Add the contents of Scalable Vector Graphics (SVG) files provided for associated icon modes,
see https://doc.qt.io/qt-5/qicon.html#Mode-enum.
Expand Down Expand Up @@ -102,21 +102,21 @@ def load_icon(normal: str, disabled: str = None, active=None, selected=None) ->
return icon


def load_svg(name):
def load_svg(name: str) -> QSvgWidget:
"""
Return a QSvgWidget representation of a file in the resources.
"""
return QSvgWidget(path(name))


def load_image(name):
def load_image(name: str) -> QPixmap:
"""
Return a QPixmap representation of a file in the resources.
"""
return QPixmap(path(name))


def load_css(name):
def load_css(name: str) -> str:
"""
Return the contents of the referenced CSS file in the resources.
"""
Expand Down

0 comments on commit 3341d96

Please sign in to comment.