Skip to content

Commit

Permalink
Remove all old logging calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sam210723 committed Mar 2, 2024
1 parent 8b84916 commit a6d5d83
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 82 deletions.
11 changes: 5 additions & 6 deletions wavebin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
Oscilloscope waveform capture viewer
"""

__version__: str = "3.0" # Application version
__min__: tuple = (3, 10) # Minimum Python version

import argparse
import logging
Expand Down Expand Up @@ -40,14 +38,15 @@ def main() -> None:
" _ ______ __ _____ / /_ (_)___ \n" +
" | | /| / / __ `/ | / / _ \\/ __ \\/ / __ \\\n" +
" | |/ |/ / /_/ /| |/ / __/ /_/ / / / / / \n" +
f" |__/|__/\\__,_/ |___/\\___/_.___/_/_/ /_/ v{__version__}\n\n" +
f" |__/|__/\\__,_/ |___/\\___/_.___/_/_/ /_/ v{config.app.version}\n\n" +
f" Oscilloscope waveform capture viewer\n" +
" https://wavebin.vksdr.com\n\n"
)

# Check Python version
if sys.version_info[1] < __min__[1]:
logging.critical(f"Python {__min__[0]}.{__min__[1]} or newer is required")
min_py: tuple = (3, 10)
if sys.version_info[1] < min_py[1]:
logging.critical(f"Python {min_py[0]}.{min_py[1]} or newer is required")
exit(1)

# Log system info (Python, OS, CPU)
Expand Down Expand Up @@ -153,7 +152,7 @@ def safe_exit(code: int = 0) -> None:
from os import name as os_name
if os_name == "nt":
import ctypes
appid = f"com.vksdr.wavebin.{__version__}"
appid = f"com.vksdr.wavebin.{config.app.version}"
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appid)

main()
Expand Down
12 changes: 9 additions & 3 deletions wavebin/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"""
wavebin
https://github.com/sam210723/wavebin
Oscilloscope waveform capture viewer
"""

import appdirs
import configparser
from dataclasses import dataclass, asdict, field
import logging
from pathlib import Path
from pprint import pformat

from wavebin import __main__ as main
from wavebin.vendor import Vendor, vendor_detect


Expand All @@ -16,7 +22,7 @@ class App():
"""

name: str = "wavebin" # Application name
version: str = main.__version__ # Application version
version: str = "3.0" # Application version
update: bool = False # Update available on GitHub

# Log file path
Expand Down Expand Up @@ -90,7 +96,7 @@ def load(self, reset: bool = False) -> bool:
return True

# Prepare configuration object
logging.info('Loading configuration')
logging.debug('Loading configuration')
parser = configparser.ConfigParser()
parser.read(str(self.path.absolute()))

Expand Down
17 changes: 5 additions & 12 deletions wavebin/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Oscilloscope waveform capture viewer
"""

import logging
from pathlib import Path
import numpy
import wave
Expand All @@ -18,7 +19,7 @@ def __init__(self, verbose, path, waveforms, clipped):
self.waveforms = waveforms
self.clipped = clipped

self.log(f"Exporting PulseView session to \"{self.path}\"")
logging.debug(f"Exporting PulseView session to \"{self.path}\"")

# Create ZIP file
self.zipf = zipfile.ZipFile(self.path, 'w', zipfile.ZIP_DEFLATED)
Expand All @@ -35,7 +36,7 @@ def __init__(self, verbose, path, waveforms, clipped):

# Close completed ZIP file
self.zipf.close()
self.log("Finished exporting")
logging.debug("Finished exporting")


def metadata(self):
Expand Down Expand Up @@ -94,17 +95,13 @@ def get_sample_rate(self):
return sr


def log(self, msg):
if self.verbose: print(msg)


class WaveFile():
def __init__(self, verbose, path, waveforms):
self.verbose = verbose
self.path = Path(path)
self.waveforms = waveforms

self.log(f"Exporting WAV file to \"{self.path}\"")
logging.debug(f"Exporting WAV file to \"{self.path}\"")

# Loop through waveforms
for i, w in enumerate(self.waveforms):
Expand All @@ -130,7 +127,7 @@ def __init__(self, verbose, path, waveforms):
#TODO: Fix analog waveform exporting
#TODO: Add max (ulong) data rate check

self.log("Finished exporting")
logging.debug("Finished exporting")


def get_sample_rate(self, i):
Expand All @@ -145,7 +142,3 @@ def get_sample_rate(self, i):
sr = 1 / self.waveforms[i]['header'].x_increment

return sr


def log(self, msg):
if self.verbose: print(msg)
1 change: 1 addition & 0 deletions wavebin/interface/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Oscilloscope waveform capture viewer
"""

import logging
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QApplication, QMenuBar, QMenu
import qtawesome as qta
Expand Down
1 change: 1 addition & 0 deletions wavebin/interface/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Oscilloscope waveform capture viewer
"""

import logging
import numpy as np
import pyqtgraph as pg
from pyqtgraph import GraphicsLayoutWidget, PlotItem, ViewBox, AxisItem
Expand Down
15 changes: 2 additions & 13 deletions wavebin/interface/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def download_device_image(self, url: str) -> bool:
res = urllib.request.urlopen(req)
self.device_image_pixmap.loadFromData(res.read())
self.device_image_label.setPixmap(self.device_image_pixmap)
self.log(f"Downloaded properties dialog device image")
logging.debug(f"Downloaded properties dialog device image")

return True

Expand All @@ -146,16 +146,5 @@ def download_device_image(self, url: str) -> bool:
self.grid_layout.addWidget(self.vendor_image_label, 0, 0, 1, 4, Qt.AlignmentFlag.AlignCenter)
self.grid_layout.addWidget(self.device_info_label, 1, 0, 1, 4, Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignCenter)

self.log(f"Failed to download device image \"{url}\" ({e})")
logging.debug(f"Failed to download device image \"{url}\" ({e})")
return False


def log(self, msg: str) -> None:
"""
Print message to console if verbose mode enabled
Args:
msg (str): Message to print to console
"""

logging.debug(msg)
16 changes: 3 additions & 13 deletions wavebin/interface/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Oscilloscope waveform capture viewer
"""

import logging
from pathlib import Path
from PyQt6.QtWidgets import QApplication, QWidget, QToolBar, QLabel, QMessageBox, QSizePolicy
from PyQt6.QtCore import Qt
Expand Down Expand Up @@ -155,7 +156,7 @@ def button_export(self) -> None:

# Handle cancelled dialog
if file_path == "":
self.log("Export file dialog cancelled")
logging.debug("Export file dialog cancelled")
return
else:
file_path = Path(file_path)
Expand Down Expand Up @@ -184,7 +185,7 @@ def button_bug(self) -> bool:
Open issue form on GitHub
"""

self.log("Opening GitHub issue form in default web browser")
logging.debug("Opening GitHub issue form in default web browser")
return webbrowser.open(
"https://github.com/sam210723/wavebin/issues/new" +
"?template=bug.md" +
Expand Down Expand Up @@ -255,14 +256,3 @@ def set_props(self, waveform: Vendor) -> None:
waveform.serial
)
#TODO: Pass waveform properties to dialog


def log(self, msg: str) -> None:
"""
Print message to console if verbose mode enabled
Args:
msg (str): Message to print to console
"""

if self.app.config['verbose']: print(msg)
57 changes: 24 additions & 33 deletions wavebin/interface/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,66 @@ def __init__(self) -> None:
super(MainWindow, self).__init__([])

# Setup main Qt application
self.log("Initialising Qt application")
logging.debug("Initialising Qt application")
self.setApplicationName(config.app.name)
self.setApplicationDisplayName(config.app.name)
self.setApplicationDisplayName(f"{config.app.name} v{config.app.version}")
self.setApplicationVersion(config.app.version)

# Create main Qt window
self.log("Creating main Qt window")
logging.debug("Creating main Qt window")
self.window = QMainWindow()

# Apply window style for Windows platforms
try:
import pywinstyles
pywinstyles.apply_style(self.window, "dark")
except ImportError: pass
self.window.setFocus()

# Add Inter font
font_dir = Path(__file__).parent / "assets" / "Inter"
QFontDatabase.addApplicationFont(str( font_dir / "Inter-Regular.ttf"))
QFontDatabase.addApplicationFont(str( font_dir / "Inter-Bold.ttf"))

# Window styling and state
self.log("Updating window style")
logging.debug("Updating window style")
self.icon_path = Path(__file__).parent / "assets" / "icon.ico"
self.icon_path_multi = Path(__file__).parent / "assets" / "icon-multi.ico"
self.icon = QIcon(str(self.icon_path_multi))
self.setWindowIcon(self.icon)
self.window.setMinimumSize(800, 500)

# Styling for Windows platforms
try:
import pywinstyles
pywinstyles.apply_style(self.window, "dark")
except ImportError: pass

# Add menu bar to main window
self.log("Building menu bar")
logging.debug("Building menu bar")
self.menu_bar = MainMenuBar(self)
self.window.setMenuBar(self.menu_bar)

# Add tool bar to main window
self.log("Building tool bar")
logging.debug("Building tool bar")
self.tool_bar = MainToolBar(self)
self.window.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.tool_bar)

# Create main widget
self.log("Creating main widget")
logging.debug("Creating main widget")
self.widget = QWidget()
self.window.setCentralWidget(self.widget)
self.widget.setStyleSheet("background-color: #000;")
self.widget.setContentsMargins(0, 0, 0, 0)

# Attach event handlers
self.window.resizeEvent = self.event_resize
self.window.changeEvent = self.event_change
self.window.keyPressEvent = self.event_keypress
self.window.setFocus()

# Create main layout
self.log("Creating main grid layout")
logging.debug("Creating main grid layout")
self.layout = QGridLayout()
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.widget.setLayout(self.layout)

# Create open/save file dialogs
self.log("Creating file dialogs")
logging.debug("Creating file dialogs")
self.open_dialog = QFileDialog()
self.save_dialog = QFileDialog()

Expand All @@ -108,7 +110,7 @@ def run(self) -> int:
Launch main application window
"""

self.log("Starting Qt application")
logging.debug("Starting Qt application")

# Get center of primary screen
screen: QRect = self.primaryScreen().geometry()
Expand Down Expand Up @@ -137,7 +139,7 @@ def welcome(self) -> None:
Builds welcome screen when no waveforms are loaded
"""

self.log("Building welcome screen")
logging.debug("Building welcome screen")

# Text banner
banner = QTextEdit()
Expand Down Expand Up @@ -238,14 +240,14 @@ def update(self) -> None:
"""

# Clear grid layout
self.log("Resetting main grid layout")
logging.debug("Resetting main grid layout")
while self.layout.count():
child = self.layout.takeAt(0)
if child.widget():
child.widget().deleteLater()

# Set file name in window title
self.window.setWindowTitle(f"\"{config.file.name}\"")
self.window.setWindowTitle(config.file.name)

# Add plot widget to grid layout
self.plot = WaveformPlot(config.waveform)
Expand Down Expand Up @@ -308,7 +310,7 @@ def button_open(self) -> bool:

# Handle cancelled dialog
if file_path == "":
self.log("Open file dialog cancelled")
logging.debug("Open file dialog cancelled")
return False
else:
file_path = Path(file_path)
Expand Down Expand Up @@ -345,7 +347,7 @@ def button_docs(self) -> bool:
Open documentation in browser
"""

self.log("Opening documentation in default web browser")
logging.debug("Opening documentation in default web browser")
return webbrowser.open("https://wavebin.vksdr.com")


Expand Down Expand Up @@ -406,14 +408,3 @@ def event_keypress(self, event: QKeyEvent) -> None:
elif mod == None and key == Qt.Key.Key_I:
# Show waveform properties dialog
if config.file: self.menu_bar.menu_view_props()


def log(self, msg: str) -> None:
"""
Print message to console if verbose mode enabled
Args:
msg (str): Message to print to console
"""

logging.debug(msg)
1 change: 1 addition & 0 deletions wavebin/vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

from enum import Enum
import logging
import numpy as np
from pathlib import Path
import pyqtgraph
Expand Down
3 changes: 2 additions & 1 deletion wavebin/vendor/keysight.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"""

from collections import namedtuple
import struct
import logging
import numpy as np
import struct

from wavebin.vendor import Vendor, Channel, Unit

Expand Down
Loading

0 comments on commit a6d5d83

Please sign in to comment.