Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions coverage_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from xml.dom import minidom
from utils import score_to_rgb_color

if __name__ == '__main__':
file = minidom.parse('coverage.xml')
coverage = file.getElementsByTagName('coverage')
coverage = float(coverage[0].attributes['line-rate'].value)
if __name__ == "__main__":
file = minidom.parse("coverage.xml")
coverage = file.getElementsByTagName("coverage")
coverage = float(coverage[0].attributes["line-rate"].value)
coverage_min, coverage_max = 0, 1
if sys.argv[1] == '--score':
if sys.argv[1] == "--score":
print(f"{coverage:.1%}")
elif sys.argv[1] == '--color':
elif sys.argv[1] == "--color":
print(score_to_rgb_color(coverage, coverage_min, coverage_max))
else:
raise ValueError(f"Unknowed argument: {sys.argv[1]}")
21 changes: 12 additions & 9 deletions opencodeblocks/blocks/sliderblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def __init__(self, **kwargs):
self.edge_size * 2,
self.title_widget.height() + self.edge_size * 2,
self.edge_size * 2,
self.edge_size * 2
self.edge_size * 2,
)
self.layout.addWidget(self.slider)
self.layout.addLayout(self.variable_layout)

self.holder.setWidget(self.root)

def valueChanged(self):
""" This is called when the value of the slider changes """
"""This is called when the value of the slider changes"""
python_code = f"{self.var_name} = {self.value}"
self.variable_value.setText(f"{self.value}")

Expand All @@ -54,32 +54,35 @@ def valueChanged(self):

@property
def value(self):
""" The value of the slider """
"""The value of the slider"""
return str(self.slider.value() / 100)

@value.setter
def value(self, value: str):
self.slider.setValue(int(float(value) * 100))

@property
def var_name(self):
""" The name of the python variable associated with the slider """
"""The name of the python variable associated with the slider"""
return self.variable_text.text()

@var_name.setter
def var_name(self, value: str):
self.variable_text.setText(value)

def serialize(self):
""" Return a serialized version of this widget """
"""Return a serialized version of this widget"""
base_dict = super().serialize()
base_dict["value"] = self.value
base_dict["var_name"] = self.var_name

return base_dict

def deserialize(self, data: OrderedDict,
hashmap: dict = None, restore_id: bool = True):
""" Restore a slider block from it's serialized state """
for dataname in ['value','var_name']:
def deserialize(
self, data: OrderedDict, hashmap: dict = None, restore_id: bool = True
):
"""Restore a slider block from it's serialized state"""
for dataname in ["value", "var_name"]:
if dataname in data:
setattr(self, dataname, data[dataname])

Expand Down
31 changes: 13 additions & 18 deletions opencodeblocks/blocks/widgets/blocksizegrip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
Implements the SizeGrip Widget for the Blocks.

Expand All @@ -12,14 +11,14 @@


class OCBSizeGrip(QSizeGrip):
""" A grip to resize a block """
"""A grip to resize a block"""

def __init__(self, block: QGraphicsItem, parent: QWidget = None):
"""
Constructor for BlockSizeGrip
Constructor for BlockSizeGrip

block is the QGraphicsItem holding the QSizeGrip.
It's usually an OCBBlock
block is the QGraphicsItem holding the QSizeGrip.
It's usually an OCBBlock
"""
super().__init__(parent)
self.mouseX = 0
Expand All @@ -28,23 +27,25 @@ def __init__(self, block: QGraphicsItem, parent: QWidget = None):
self.resizing = False

def mousePressEvent(self, mouseEvent: QMouseEvent):
""" Start the resizing """
"""Start the resizing"""
self.mouseX = mouseEvent.globalX()
self.mouseY = mouseEvent.globalY()
self.resizing = True

def mouseReleaseEvent(self, mouseEvent: QMouseEvent): # pylint:disable=unused-argument
""" Stop the resizing """
def mouseReleaseEvent(
self, mouseEvent: QMouseEvent
): # pylint:disable=unused-argument
"""Stop the resizing"""
self.resizing = False
self.block.scene().history.checkpoint("Resized block", set_modified=True)

@property
def _zoom(self) -> float:
""" Returns how much the scene is """
"""Returns how much the scene is"""
return self.block.scene().views()[0].zoom

def mouseMoveEvent(self, mouseEvent: QMouseEvent):
""" Performs resizing of the root widget """
"""Performs resizing of the root widget"""
transformed_pt1 = self.block.mapFromScene(QPoint(0, 0))
transformed_pt2 = self.block.mapFromScene(QPoint(1, 1))

Expand All @@ -58,14 +59,8 @@ def mouseMoveEvent(self, mouseEvent: QMouseEvent):
# relative to the grip, so if the grip moves, the deltaX and deltaY changes.
# This creates a shaking effect when resizing. We use global to not
# have this effect.
new_width = max(
self.block.width + int(delta_x),
self.block.min_width
)
new_height = max(
self.block.height + int(delta_y),
self.block.min_height
)
new_width = max(self.block.width + int(delta_x), self.block.min_width)
new_height = max(self.block.height + int(delta_y), self.block.min_height)

self.parent().setGeometry(0, 0, new_width, new_height)
self.block.update_all()
Expand Down
2 changes: 1 addition & 1 deletion opencodeblocks/blocks/widgets/blocksplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def __init__(self, block: QWidget, orientation: int, parent: QWidget):
self.block = block

def createHandle(self):
""" Return the middle handle of the splitter """
"""Return the middle handle of the splitter"""
return OCBSplitterHandle(self.orientation(), self)
12 changes: 5 additions & 7 deletions opencodeblocks/blocks/widgets/blocktitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
size: int = 12,
parent: QWidget = None,
):
""" Create a new title for an OCBBlock """
"""Create a new title for an OCBBlock"""
Serializable.__init__(self)
QLineEdit.__init__(self, text, parent)
self.clickTime = None
Expand All @@ -33,7 +33,7 @@ def __init__(
self.setCursorPosition(0)

def init_ui(self, color: str, font: str, size: int):
""" Apply the style given to the title """
"""Apply the style given to the title"""
self.color = color
self.setStyleSheet(
f"""
Expand Down Expand Up @@ -74,7 +74,7 @@ def mouseDoubleClickEvent(self, event: QMouseEvent):
self.setFocus(Qt.MouseFocusReason)

def serialize(self) -> OrderedDict:
""" Return a serialized version of this widget """
"""Return a serialized version of this widget"""
return OrderedDict(
[
("color", self.color),
Expand All @@ -83,10 +83,8 @@ def serialize(self) -> OrderedDict:
]
)

def deserialize(
self, data: OrderedDict, hashmap: dict = None, restore_id=True
):
""" Restore a title from serialized data """
def deserialize(self, data: OrderedDict, hashmap: dict = None, restore_id=True):
"""Restore a title from serialized data"""
if restore_id:
self.id = data.get("id", id(self))
self.init_ui(data["color"], data["font"], data["size"])
12 changes: 7 additions & 5 deletions opencodeblocks/core/serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
from typing import OrderedDict


class Serializable():
class Serializable:

""" Serializable base for serializable objects. """
"""Serializable base for serializable objects."""

def __init__(self):
self.id = id(self)

def serialize(self) -> OrderedDict:
""" Serialize the object as an ordered dictionary. """
"""Serialize the object as an ordered dictionary."""
raise NotImplementedError()

def deserialize(self, data: OrderedDict, hashmap: dict = None, restore_id=True) -> None:
""" Deserialize the object from an ordered dictionary.
def deserialize(
self, data: OrderedDict, hashmap: dict = None, restore_id=True
) -> None:
"""Deserialize the object from an ordered dictionary.

Args:
data: Dictionnary containing data do deserialize from.
Expand Down
12 changes: 6 additions & 6 deletions opencodeblocks/graphics/theme_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@


class ThemeManager(QObject):
""" Class loading theme files and providing the options set in those files """
"""Class loading theme files and providing the options set in those files"""

themeChanged = pyqtSignal()

def __init__(self, parent=None):
""" Load the default themes and the fonts available to construct the ThemeManager """
"""Load the default themes and the fonts available to construct the ThemeManager"""
super().__init__(parent)
self._preferred_fonts = ["Inconsolata", "Roboto Mono", "Courier"]
self.recommended_font_family = "Monospace"
Expand All @@ -39,7 +39,7 @@ def __init__(self, parent=None):
full_path = os.path.join(theme_path, p)
if os.path.isfile(full_path) and full_path.endswith(".theme"):
name = os.path.splitext(os.path.basename(p))[0]
with open(full_path, 'r', encoding="utf-8") as f:
with open(full_path, "r", encoding="utf-8") as f:
theme = Theme(name, f.read())
self._themes.append(theme)

Expand All @@ -53,19 +53,19 @@ def selected_theme_index(self, value: int):
self.themeChanged.emit()

def list_themes(self) -> List[str]:
""" List the themes """
"""List the themes"""
return [theme.name for theme in self._themes]

def current_theme(self) -> Theme:
""" Return the current theme """
"""Return the current theme"""
return self._themes[self.selected_theme_index]


theme_handle = None


def theme_manager():
""" Retreive the theme manager of the application """
"""Retreive the theme manager of the application"""
global theme_handle
if theme_handle is None:
theme_handle = ThemeManager()
Expand Down
17 changes: 9 additions & 8 deletions opencodeblocks/graphics/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


class WorkerSignals(QObject):
""" Defines the signals available from a running worker thread. """
"""Defines the signals available from a running worker thread."""

stdout = pyqtSignal(str)
image = pyqtSignal(str)
finished = pyqtSignal()
Expand All @@ -17,18 +18,18 @@ class WorkerSignals(QObject):


class Worker(QRunnable):
""" Worker thread """
"""Worker thread"""

def __init__(self, kernel, code):
""" Initialize the worker object. """
"""Initialize the worker object."""
super().__init__()

self.kernel = kernel
self.code = code
self.signals = WorkerSignals()

async def run_code(self):
""" Run the code in the block """
"""Run the code in the block"""
# Execute the code
self.kernel.client.execute(self.code)
done = False
Expand All @@ -37,17 +38,17 @@ async def run_code(self):
# Save kernel message and send it to the GUI
output, output_type, done = self.kernel.update_output()
if done is False:
if output_type == 'text':
if output_type == "text":
self.signals.stdout.emit(output)
elif output_type == 'image':
elif output_type == "image":
self.signals.image.emit(output)
elif output_type == 'error':
elif output_type == "error":
self.signals.error.emit()
self.signals.finished.emit()
self.signals.finished_block.emit()

def run(self):
""" Execute the run_code method asynchronously. """
"""Execute the run_code method asynchronously."""
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.run_code())
Expand Down
12 changes: 7 additions & 5 deletions opencodeblocks/qss/dark_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
\x00\x00\x01\x68\xe2\x98\x0e\xbe\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
qt_version = [int(v) for v in QtCore.qVersion().split(".")]
if qt_version < [5, 8, 0]:
rcc_version = 1
qt_resource_struct = qt_resource_struct_v1
Expand All @@ -502,13 +502,15 @@


def qInitResources():
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct,
qt_resource_name, qt_resource_data)
QtCore.qRegisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


def qCleanupResources():
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct,
qt_resource_name, qt_resource_data)
QtCore.qUnregisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


qInitResources()
Loading