Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
idanpa committed Jan 12, 2025
1 parent 77e40c7 commit e103479
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions pypad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from PyQt6.QtCore import (Qt, QObject, QRect, QMimeData, QEvent, QUrl, QSize,
QVariantAnimation, QEasingCurve,
QTimer, QRunnable, QThreadPool, pyqtSlot, pyqtSignal)
from PyQt6.QtGui import (QFont, QFontMetrics, QFontDatabase, QImage,
from PyQt6.QtGui import (QFont, QFontMetrics, QFontDatabase, QImage, QGuiApplication,
QPainter, QColor, QKeyEvent, QResizeEvent, QCloseEvent,
QTextCursor, QTextLength, QTextCharFormat, QTextFrameFormat, QTextBlockFormat,
QTextDocument, QTextImageFormat, QTextTableCell, QTextTableFormat, QTextTableCellFormat)
Expand Down Expand Up @@ -81,10 +81,9 @@ class Highlighter(PygmentsHighlighter):
def highlightBlock(self, string):
# don't highlight output cells
cursor = QTextCursor(self.currentBlock())
table = cursor.currentTable()
if table and table.cellAt(cursor).column() != 0:
return
return super().highlightBlock(string)
cell = self.parent().table.cellAt(cursor)
if cell.isValid() and cell.column() == 0:
return super().highlightBlock(string)

class CompletionWidget_(CompletionWidget):
def _complete_current(self):
Expand Down Expand Up @@ -124,9 +123,6 @@ def __init__(self, parent, debug=False):
self.char_height = font_metrics.height()
self.setTabStopDistance(4 * self.char_width)

self.highlighter = Highlighter(self)
self.highlighter.set_style('vs')

self.setFrameStyle(QFrame.Shape.NoFrame)

self.edit_block_cursor = self.textCursor()
Expand All @@ -141,6 +137,9 @@ def __init__(self, parent, debug=False):
QTextLength(QTextLength.PercentageLength, 60)])
self.table = cursor.insertTable(1, 2, table_format)

self.highlighter = Highlighter(self)
self.highlighter.set_style('vs')

self.execute_msg_id = ''
self.in_undo_redo = False
# last execution count of each cell
Expand All @@ -151,6 +150,8 @@ def __init__(self, parent, debug=False):
self.latex = ['']
self.execute_running = False
self.execute_cell_idx = -1
self.splash_visible = False
self.kernel_info = ''

# for setting cells format:
self.insert_cell(0)
Expand All @@ -172,10 +173,6 @@ def __init__(self, parent, debug=False):
self.kernel_manager = kernel_manager
self.kernel_client = kernel_client

self.splash_visible = False
self.kernel_info = ''
kernel_client.kernel_info()

self.html_converter = Ansi2HTMLConverter(dark_bg=theme['is_dark'])

self._control = self # for CompletionWidget
Expand All @@ -191,13 +188,12 @@ def __init__(self, parent, debug=False):

self.divider_drag = False
self.setMouseTracking(True)

self.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)

self.transformer_manager = TransformerManager()

self.thread_pool = QThreadPool()

kernel_client.kernel_info()

def set_splash(self):
if self.splash_visible:
return
Expand Down Expand Up @@ -845,6 +841,9 @@ def insertFromMimeData(self, source: QMimeData):

@pyqtSlot()
def recalculate_columns(self):
if QGuiApplication.mouseButtons() == Qt.LeftButton:
self.recalculate_columns_timer.start()
return
table_format = self.table.format()
width = self.viewport().width()*table_format.columnWidthConstraints()[1].rawValue()/100
padding = 10
Expand Down

0 comments on commit e103479

Please sign in to comment.