Skip to content

Commit

Permalink
typing
Browse files Browse the repository at this point in the history
  • Loading branch information
MAKOMO committed Nov 21, 2023
1 parent cedba0b commit 73b142e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/artisanlib/acaia.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def acaiaProtocolParser(self, write:Callable[[Optional[bytes]],None], dataIn:byt
self.resetProtocolParser()


def reset(self):
def reset(self) -> None:
self.__init__() # type: ignore # pylint: disable=unnecessary-dunder-call

# return a bytearray of len 2 containing the even and odd CRCs over the given payload
Expand Down
12 changes: 6 additions & 6 deletions src/artisanlib/ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __init__(self,
self.sendStop: Optional[Callable[[Callable[[Optional[bytes]],None]], None]] = sendStop
self.connected: Optional[Callable[[], None]] = connected

self.ENABLE_NOTIFICATION_VALUE:QtCore.QByteArray = QtCore.QByteArray.fromHex(b'0100') # type: ignore
self.DISABLE_NOTIFICATION_VALUE:QtCore.QByteArray = QtCore.QByteArray.fromHex(b'0000') # type: ignore
self.ENABLE_NOTIFICATION_VALUE:QtCore.QByteArray = QtCore.QByteArray.fromHex(b'0100') # OFF type: ignore
self.DISABLE_NOTIFICATION_VALUE:QtCore.QByteArray = QtCore.QByteArray.fromHex(b'0000') # OFF type: ignore

self.m_deviceDiscoveryAgent:QtBluetooth.QBluetoothDeviceDiscoveryAgent = QtBluetooth.QBluetoothDeviceDiscoveryAgent()
self.m_deviceDiscoveryAgent.setLowEnergyDiscoveryTimeout(500)
Expand All @@ -108,7 +108,7 @@ def __init__(self,

self.dataReceived.connect(self.dataReceivedProcessing)

def disconnectDiscovery(self):
def disconnectDiscovery(self) -> None:
self.m_deviceDiscoveryAgent.deviceDiscovered.disconnect()
self.m_deviceDiscoveryAgent.errorOccurred.disconnect()
self.m_deviceDiscoveryAgent.finished.disconnect()
Expand Down Expand Up @@ -167,12 +167,12 @@ def write(self, data:Optional[bytes] = None) -> None:
if len(data) > self.CHUNK_SIZE:
sentBytes = 0
while sentBytes < len(data):
self.m_service.writeCharacteristic(self.m_writeCharacteristic,data[sentBytes:sentBytes + self.CHUNK_SIZE],self.m_writemode) # type: ignore # "bytearray" is incompatible with "QByteArray"
self.m_service.writeCharacteristic(self.m_writeCharacteristic,data[sentBytes:sentBytes + self.CHUNK_SIZE],self.m_writemode) # OFF type: ignore # "bytearray" is incompatible with "QByteArray"
sentBytes += self.CHUNK_SIZE
# if self.m_writemode == QtBluetooth.QLowEnergyService.WriteMode.WriteWithResponse:
# pass
else:
self.m_service.writeCharacteristic(self.m_writeCharacteristic,data,self.m_writemode) # type: ignore # "bytearray" is incompatible with "QByteArray"
self.m_service.writeCharacteristic(self.m_writeCharacteristic,data,self.m_writemode) # OFF type: ignore # "bytearray" is incompatible with "QByteArray"

def update_connected(self,connected:bool) -> None:
_log.debug('update_connected(%s)', connected)
Expand Down Expand Up @@ -411,7 +411,7 @@ def scanDevices(self) -> None:
QBluetoothDeviceDiscoveryAgent_LowEnergyMethod))


def main():
def main() -> None:
import sys
app = QtCore.QCoreApplication(sys.argv)
from artisanlib.acaia import AcaiaBLE
Expand Down
30 changes: 18 additions & 12 deletions src/artisanlib/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
if TYPE_CHECKING:
from artisanlib.main import ApplicationWindow # pylint: disable=unused-import
from PyQt6.QtWidgets import QPushButton # pylint: disable=unused-import
from PyQt6.QtGui import QCloseEvent # pylint: disable=unused-import
from PyQt6.QtGui import QCloseEvent, QDragEnterEvent, QDropEvent # pylint: disable=unused-import

_log: Final[logging.Logger] = logging.getLogger(__name__)

Expand Down Expand Up @@ -226,21 +226,27 @@ def __init__(self, parent:QWidget, aw:'ApplicationWindow', title:str = '', label
okButton.setFocus()

@pyqtSlot()
def accept(self):
def accept(self) -> None:
self.url = self.inputLine.text()
super().accept()

@staticmethod
def dragEnterEvent(event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()

def dropEvent(self, event):
urls = event.mimeData().urls()
if urls and len(urls)>0:
self.inputLine.setText(urls[0].toString())
def dragEnterEvent(event:Optional['QDragEnterEvent']) -> None:
if event is not None:
mimeData = event.mimeData()
if mimeData is not None:
if mimeData.hasUrls():
event.accept()
else:
event.ignore()

def dropEvent(self, event:Optional['QDropEvent']) -> None:
if event is not None:
mimeData = event.mimeData()
if mimeData is not None and mimeData.hasUrls():
urls = mimeData.urls()
if urls and len(urls)>0:
self.inputLine.setText(urls[0].toString())


class ArtisanComboBoxDialog(ArtisanDialog):
Expand Down
33 changes: 17 additions & 16 deletions src/artisanlib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14894,7 +14894,7 @@ def weightVolumeDigits(v):
return 4

@staticmethod
def float2floatWeightVolume(v):
def float2floatWeightVolume(v:float) -> float:
d = ApplicationWindow.weightVolumeDigits(v)
return ApplicationWindow.float2float(v,d)

Expand Down Expand Up @@ -23705,7 +23705,7 @@ def saveVectorGraph_PDF(self,_=False):
self.saveVectorGraph(extension='*.pdf')

#resizes and saves graph to a new width w and h preserving maximal image quality independent of screen resolution
def resizeImgToSize(self,w,h,filetype='PNG',fname=''):
def resizeImgToSize(self, w:int, h:int, filetype:str = 'PNG', fname:str = '') -> None:
try:
fileext = '.png'
if filetype == 'JPEG':
Expand Down Expand Up @@ -23770,7 +23770,7 @@ def resizeImgToSize(self,w,h,filetype='PNG',fname=''):
except Exception as e: # pylint: disable=broad-except
_log.exception(e)

def saveVectorGraph(self,extension='*.pdf',fname=''):
def saveVectorGraph(self,extension:str = '*.pdf',fname:str = '') -> None:
try:
if fname == '' or fname is None:
if extension == '*.pdf':
Expand Down Expand Up @@ -23803,14 +23803,14 @@ def saveVectorGraph(self,extension='*.pdf',fname=''):
#displays Dialog for the setting of the curves parameters (like RoR, Filters,..)
@pyqtSlot()
@pyqtSlot(bool)
def setCurves(self,_=False):
def setCurves(self, _:bool = False) -> None:
from artisanlib.curves import CurvesDlg
curvesDlg = CurvesDlg(self,self,self.CurveDlg_activeTab)
curvesDlg.show()

#used by WheelGraphDlg()
#wrap values in unicode(.) if and only if those are of type string
def getWheelGraph(self):
def getWheelGraph(self) -> Wheel:

Check failure on line 23813 in src/artisanlib/main.py

View workflow job for this annotation

GitHub Actions / reviewdog

src/artisanlib/main.py#L23813

E0601: Using variable 'Wheel' before assignment (used-before-assignment)
Raw output
src/artisanlib/main.py:23813:31: E0601: Using variable 'Wheel' before assignment (used-before-assignment)
wheel:Wheel = {}
#two dimension lists
wheel['wheelnames'] = self.qmc.wheelnames
Expand All @@ -23829,7 +23829,7 @@ def getWheelGraph(self):
wheel['wheelaspect'] = self.qmc.wheelaspect
return wheel

def loadWheel(self,filename):
def loadWheel(self, filename:str) -> None:
f = None
try:
f = QFile(filename)
Expand Down Expand Up @@ -23882,27 +23882,28 @@ def loadWheel(self,filename):
if f:
f.close()

def standardButtonsVisibility(self):
def standardButtonsVisibility(self) -> None:
if self.lowerbuttondialog.isVisible():
self.lowerbuttondialog.setVisible(False)
self.messagelabel.setVisible(False)
else:
self.lowerbuttondialog.setVisible(True)
self.messagelabel.setVisible(True)

def toggleextraeventrows(self):
def toggleextraeventrows(self) -> None:
if self.extrabuttondialogs.isVisible():
self.hideExtraButtons()
else:
self.showExtraButtons()

@staticmethod
def clearBoxLayout(layout):
def clearBoxLayout(layout:QLayout) -> None:
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
if widget is not None:
widget.deleteLater()
if item is not None:
widget = item.widget()
if widget is not None:
widget.deleteLater()

# applies button label substitutions like \t => eventname, \0 => ON,...
def substButtonLabel(self, buttonNr:int, label:str, eventtype:int) -> str:
Expand Down Expand Up @@ -23948,7 +23949,7 @@ def substButtonLabel(self, buttonNr:int, label:str, eventtype:int) -> str:

#orders extra event buttons based on max number of buttons
@pyqtSlot()
def realignbuttons(self):
def realignbuttons(self) -> None:
#clear buttons
self.clearBoxLayout(self.e1buttonbarLayout)
self.clearBoxLayout(self.e2buttonbarLayout)
Expand Down Expand Up @@ -24063,7 +24064,7 @@ def realignbuttons(self):
self.update_extraeventbuttons_visibility()

#assigns tooltips to extra event buttons
def settooltip(self):
def settooltip(self) -> None:
for i, bl in enumerate(self.buttonlist):
if self.show_extrabutton_tooltips:
try:
Expand All @@ -24082,7 +24083,7 @@ def settooltip(self):
bl.setToolTip('')

@pyqtSlot()
def update_extraeventbuttons_visibility(self):
def update_extraeventbuttons_visibility(self) -> None:
for i, bl in enumerate(self.buttonlist):
try:
if self.extraeventsvisibility[i]:
Expand All @@ -24100,7 +24101,7 @@ def findPalette(self, label:str) -> Optional[int]:
return None

#transfers current buttons to a palette number
def transferbuttonsto(self,pindex):
def transferbuttonsto(self, pindex:int) -> None:
self.buttonpalette[pindex] = self.makePalette()
self.buttonpalettemaxlen[pindex] = self.buttonlistmaxlen
self.sendmessage(f"{QApplication.translate('Message','Buttons copied to Palette #')}{pindex}")
Expand Down
2 changes: 1 addition & 1 deletion src/includes/Machines/Probat/P_Series_III.aset
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ SCs_node=secondCrackBeginningEvent
STARTonCHARGE=true
addEvent_message=addEvent
channel_modes=1, 1, 0, 0, 0, 0, 1, 1, 1, 1
channel_nodes=beanTemp, ambientTemp, burner, airPressure, drum, exhaustFan, intakeAirTemp, exhaustAirTemp, coolingAirTemp, rateOfRise
channel_nodes=beanTemp, ambientTemp, burner, airPressure, drum, exhaustFan, intakeAirTemp, exhaustAirTemp, coolingAirTemp, exhaustAirTempRor
channel_requests=, , , , , , , , ,
charge_message=startRoasting
command_node=command
Expand Down
2 changes: 1 addition & 1 deletion src/includes/Machines/Probat/Sample_Roaster.aset
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ SCs_node=secondCrackBeginningEvent
STARTonCHARGE=false
addEvent_message=addEvent
channel_modes=1, 1, 0, 0, 0, 0, 0, 0, 0, 1
channel_nodes=beanTemp, exhaustAirTemp, burner, airPressure, , , , , , rateOfRise
channel_nodes=beanTemp, exhaustAirTemp, burner, airPressure, , , , , , exhaustAirTempRor
channel_requests=, , , , , , , , ,
charge_message=startRoasting
command_node=command
Expand Down
4 changes: 2 additions & 2 deletions src/plus/blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from artisanlib.util import comma2dot
from artisanlib.dialogs import ArtisanDialog
from artisanlib.widgets import MyQComboBox
from uic import BlendDialog # type: ignore[attr-defined] # pylint: disable=no-name-in-module
from uic import BlendDialog # OFF type: ignore[attr-defined] # pylint: disable=no-name-in-module
from typing import Final, Optional, List, Collection, Dict, Tuple, TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(self, parent:'QWidget', aw:'ApplicationWindow', inWeight:float, wei

# configure UI
self.ui = BlendDialog.Ui_customBlendDialog()
self.ui.setupUi(self) # type:ignore[no-untyped-call]
self.ui.setupUi(self) # OFF type:ignore[no-untyped-call]
self.setWindowTitle(QApplication.translate('Form Caption','Custom Blend'))
self.ui.buttonBox.setStandardButtons(QDialogButtonBox.StandardButton.Cancel|QDialogButtonBox.StandardButton.Apply)
# hack to assign the Apply button the AcceptRole without losing default system translations
Expand Down
2 changes: 1 addition & 1 deletion src/plus/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def start(app_window:'ApplicationWindow') -> None:

# toggles between connected and disconnected modes. If connected and
# not is_synced() send current data to server
def toggle(app_window):
def toggle(app_window:'ApplicationWindow') -> None:
_log.debug('toggle()')
config.app_window = app_window
if config.app_window is not None and config.app_window.plus_account is None: # @UndefinedVariable
Expand Down

0 comments on commit 73b142e

Please sign in to comment.