<commit_before>from . import *


@deferred_define
def set_central_widget(self: Widget, widget):
    if isinstance(widget, WidgetController):
        widget = widget.w
    if not isinstance(widget, QWidget):
        raise TypeError('Only Support Widget or WidgetController')

    if isinstance(self, QMainWindow):
        self.setCentralWidget(widget)
    elif isinstance(self, QDockWidget):
        self.setWidget(widget)
    else:
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(widget)
        self.setLayout(layout)
    self.center_widget = widget


@deferred_define
def set_square_widget(self: Widget, widget: Widget, spacing=0):
    if isinstance(widget, WidgetController):
        widget = widget.w
    if not isinstance(widget, QWidget):
        raise TypeError('Only Support Widget or WidgetController')

    layout = SquareLayout()
    layout.setSpacing(spacing)
    layout.addWidget(widget)
    self.setLayout(layout)
    self.center_widget = widget


@deferred_define
def set_layout_spacing(self: Widget, spacing):
    layout = self.layout()
    assert isinstance(layout, SquareLayout)
    layout.setSpacing(spacing)
    layout.update()


@deferred_define
def export_to_pdf(self: Widget, filename: str, export_size=QSize(1060, 730)):
    assert isinstance(export_size, QSize)
    w, h = self.size
    if w > h:
        self.resize(export_size.width(), export_size.height())
    else:
        self.resize(export_size.height(), export_size.width())

    self.show()
    self.hide()
    p = QPicture()
    painter = QPainter(p)
    self.render(painter, QPoint(0, 0))
    painter.end()

    printer = QPrinter()
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName(filename)
    if w > h:
        printer.setOrientation(QPrinter.Landscape)
    if export_size.width() != 1060 or export_size.height() != 730:
        printer.setPageSize(QPrinter.Custom)
        printer.setPaperSize(QSizeF(self.size[1] * 0.8 + 20, self.size[0] * 0.8 + 20), QPrinter.Point)

    painter = QPainter()
    ok = painter.begin(printer)
    if ok:
        painter.drawPicture(0, 0, p)
        ok = painter.end()
    return ok


@deferred_define
def export_to_bitmap(self: Widget, filename: str):
    if filename.endswith('pdf'):
        return export_to_pdf(self, filename)

    p = QPixmap(*self.size)
    painter = QPainter(p)
    self.render(painter, QPoint(0, 0))
    painter.end()

    return p.save(filename)<commit_msg>added export size paramater in export_to_bitmap function<commit_after>from . import *


@deferred_define
def set_central_widget(self: Widget, widget):
    if isinstance(widget, WidgetController):
        widget = widget.w
    if not isinstance(widget, QWidget):
        raise TypeError('Only Support Widget or WidgetController')

    if isinstance(self, QMainWindow):
        self.setCentralWidget(widget)
    elif isinstance(self, QDockWidget):
        self.setWidget(widget)
    else:
        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(widget)
        self.setLayout(layout)
    self.center_widget = widget


@deferred_define
def set_square_widget(self: Widget, widget: Widget, spacing=0):
    if isinstance(widget, WidgetController):
        widget = widget.w
    if not isinstance(widget, QWidget):
        raise TypeError('Only Support Widget or WidgetController')

    layout = SquareLayout()
    layout.setSpacing(spacing)
    layout.addWidget(widget)
    self.setLayout(layout)
    self.center_widget = widget


@deferred_define
def set_layout_spacing(self: Widget, spacing):
    layout = self.layout()
    assert isinstance(layout, SquareLayout)
    layout.setSpacing(spacing)
    layout.update()


@deferred_define
def export_to_pdf(self: Widget, filename: str, export_size=QSize(1060, 730)):
    assert isinstance(export_size, QSize)
    w, h = self.size
    if w > h:
        self.resize(export_size.width(), export_size.height())
    else:
        self.resize(export_size.height(), export_size.width())

    self.show()
    self.hide()
    p = QPicture()
    painter = QPainter(p)
    self.render(painter, QPoint(0, 0))
    painter.end()

    printer = QPrinter()
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName(filename)
    if w > h:
        printer.setOrientation(QPrinter.Landscape)
    if export_size.width() != 1060 or export_size.height() != 730:
        printer.setPageSize(QPrinter.Custom)
        printer.setPaperSize(QSizeF(self.size[1] * 0.8 + 20, self.size[0] * 0.8 + 20), QPrinter.Point)

    painter = QPainter()
    ok = painter.begin(printer)
    if ok:
        painter.drawPicture(0, 0, p)
        ok = painter.end()
    return ok


@deferred_define
def export_to_bitmap(self: Widget, filename: str, export_size=QSize(1060, 730)):
    if filename.endswith('pdf'):
        return export_to_pdf(self, filename)
    assert isinstance(export_size, QSize)
    w, h = self.size
    if w > h:
        self.resize(export_size.width(), export_size.height())
    else:
        self.resize(export_size.height(), export_size.width())
        
    self.show()
    self.hide()
    p = QPixmap(*self.size)
    painter = QPainter(p)
    self.render(painter, QPoint(0, 0))
    painter.end()

    return p.save(filename)
{'fraction_non_alphanumeric': 0.11343283582089553, 'fraction_numerical': 0.014738805970149253, 'mean_word_length': 3.2819488817891376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2820845', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1734, 'n_words': 365}