"ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values" even though the arguments seem right - pyside

MRE:
from PySide6 import QtWidgets as qtw
from PySide6 import QtGui as qtg
from PySide6 import QtCore as qtc
class Delegate(qtw.QAbstractItemDelegate):
def paint(self, painter, option, index):
text = index.model().data(
index, qtc.Qt.ItemDataRole.DisplayRole
)
text_rect = qtc.QRect(
option.rect.left(),
option.rect.top(),
option.rect.width(),
200
)
painter.drawText(text_rect, 0, text, text_rect)
def sizeHint(self, option, index):
return qtc.QSize(200, 200)
class Model(qtc.QAbstractListModel):
def __init__(self) -> None:
super().__init__()
self._texts = ["text" for _ in range(10)]
def rowCount(self, _) -> int:
return 10
def data(self, index, role):
if not index.isValid():
return None
if role == qtc.Qt.ItemDataRole.DisplayRole:
return self._texts[index.row()]
return None
class MainWindow(qtw.QMainWindow):
def __init__(self):
super().__init__()
delegate = Delegate(self)
self._model = Model()
self._view = qtw.QListView(self)
self._view.setModel(self._model)
self._view.setItemDelegate(delegate)
self.setCentralWidget(self._view)
self.show()
app = qtw.QApplication()
mw = MainWindow()
app.exec()
Error:
ValueError: 'PySide6.QtGui.QPainter.drawText' called with wrong argument values:
PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect(230, 10, 0, 200), 0, '', PySide6.QtCore.QRect(230, 10, 0, 200))
Found signature:
PySide6.QtGui.QPainter.drawText(PySide6.QtCore.QRect, int, str, PySide6.QtCore.QRect)
One of the signatures I get on VSCode for painter.drawText:
def drawText(r: PySide6.QtCore.QRect, flags: int, text: str, br: PySide6.QtCore.QRect) -> None
The provided signatures and the passed arguments match, don't they? Could this be a bug in PySide6?
The code causing the error is in the paint method in the Delegate class.
Please, ignore this.
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

Related

How to draw a text with unicode character on the main window using Gosu Ruby?

I'm trying to output text to the main window with unicode character like that
def initialize
super 800, 800
self.caption = 'Chess'
#font = Gosu::Font.new(self, Gosu.default_font_name, 100)
end
def draw
text = "Chess \u2658".encode('utf-8')
#font.draw(text, 100, 100, 10, 1, 1, Gosu::Color::BLACK)
end
but the window displays only the 'Сhess' string without unicode symbol '♘' as supposed.
What I have tried so far:
to change font name itself, 'Gosu.default_font_name' to 'Serif', 'Arial', 'Hack' - same result only 'Chess' string changes font but not displaying glyph
use symbol '♘' instead of unicode code
use .draw_markup, .draw_text, Gosu::Image.from_text.
use different unicode code, for example with cyrillic letter '\u0416' it worked as supposed.
use different encoding arguments.
use different colors.
I looked for similar problems on the Gosu forum, but I could not find anything.
You need to use a font that includes those Unicode characters or Gosu's internal font rendering code will return a 0 width image for drawing that character.
A font like: https://fontlibrary.org/en/font/chess
require "gosu"
class Window < Gosu::Window
def initialize(*args)
super
#font = Gosu::Font.new(28, name: "Chess.odf")
end
def draw
#font.draw_text("♘\u2658", 10, 10, 10)
end
end
Window.new(100, 100, false).show

Stop highlighting text in NSTextField after pressing enter key (alt: jump to end of line) [duplicate]

I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?
You need to set your text field current editor selected range property. Try like this:
textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)
You will need to call displayIfNeeded
textField.displayIfNeeded()

ckeditor removes new line characters from source

Using CKEditor 4.9.2 on a textarea, which already has content, separated by new lines (\r\n). When the CKEditor instance loaded, these new lines were removed like this:
<textarea name="message" >
row 1 text text text
row 2 text text text text text text
row 3 text text
row 4 text
row 5
</textarea>
I can't convert them to <br> tags, have to work with \r\n characters.
How can I keep the \r\n characters?
You can't preserve new line character in CKEditor, it is not regular textarea. It is displaying your content by using html elements on page and it cant work like you want.
Easy solution I can suggest would bo to replace all new lines with <br>.
editor.on( 'setData', function(event) {
event.data.dataValue = event.data.dataValue.replace( 'your regexp', '<br>' );
} );
And then after getting editor data, just replace each <br> with new line character.

Add Scrollbar to popup table in Tkinter

I have a menu button in a GUI I am making that displays a popup containing a CSV file, using pd.read_csv through pandas. However, there is a lot of data, and when the popup is displayed, pandas cuts off a lot of the data, only displaying the data in the beginning and in the end of the file.
I want to be able to scroll through all the data in my popup window. Any suggestions?
Here is the code for the popup command:
def popuptable():
popup = tk.Tk()
popup.wm_title("!")
label = ttk.Label(popup, text=(pd.read_csv('NameofCSVFile.csv')), font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
popup.mainloop()
I give you an example of how to do a scrollable text widget that looks like a label. I put it in the main window for this example, but you just have to replace root by a toplevel to adapt it to your case.
from tkinter import Tk, Text, Scrollbar
root = Tk()
# only the column containing the text is resized when the window size changes:
root.columnconfigure(0, weight=1)
# resize row 0 height when the window is resized
root.rowconfigure(0, weight=1)
txt = Text(root)
txt.grid(row=0, column=0, sticky="eswn")
scroll_y = Scrollbar(root, orient="vertical", command=txt.yview)
scroll_y.grid(row=0, column=1, sticky="ns")
# bind txt to scrollbar
txt.configure(yscrollcommand=scroll_y.set)
very_long_list = "\n".join([str(i) for i in range(100)])
txt.insert("1.0", very_long_list)
# make the text look like a label
txt.configure(state="disabled", relief="flat", bg=root.cget("bg"))
root.mainloop()
Screenshot:

Sublime text 3 character offset highlighting by numeral range

Is there a way/plugin in sublime text 3 for highlighting multiple character offset ranges? The ideal desired functionality would be something like this: given a range of character offsets (e.g. 200-400, 5000-5300, 6400-6450) highlight the corresponding ranges.
This can be done with a WindowCommand plugin. Go to Tools -> New Plugin... and replace the contents with the following:
import sublime
import sublime_plugin
class SelectRegionCommand(sublime_plugin.WindowCommand):
def highlight_region(self, regions):
region_list = []
if "," in regions:
for region in regions.split(","):
region_list.append(tuple(region.split("-")))
else:
region_list.append(tuple(regions.split("-")))
view = self.window.active_view()
view.show(int(region_list[0][0]))
for region in region_list:
begin = int(region[0])
end = int(region[1])
to_highlight = sublime.Region(begin, end)
view.sel().add(to_highlight)
def run(self):
message = "Enter offset range(s) to select, separated by commas:"
default = "0-100"
self.window.show_input_panel(message, default, self.highlight_region, None, None)
Save the file as Packages/User/select_region.py (it should open that directory automatically), where Packages is the directory opened by selecting Preferences -> Browse Packages....
Next, create a custom key binding to trigger the plugin. Open Preferences -> Key Bindings-User and add the following line:
{ "keys": ["ctrl+alt+shift+s"], "command": "select_region" }
If the file is empty, surround the key binding with square brackets [ ]. Save the file, and you're all set. Hitting CtrlAltShiftS will bring up an input panel at the bottom of the window where you can enter the character offsets. Please don't include any spaces, so your input should look like the following:
Hit Enter, and the regions you entered will be selected:
EDIT
I altered the code slightly so that the view scrolls to the beginning of the first region entered (it should be centered on the screen). If you don't want that functionality for some reason, just comment out the view.show(int(region_list[0][0])) line (line 14).

Resources