Up to Maya 2019 I was using the following script to customize the script editor font.
from PySide2 import QtGui, QtCore, QtWidgets
def set_font(font='Courier New', size=12):
"""
Sets the style sheet of Maya's script Editor
"""
# Find the script editor widget
app = QtWidgets.QApplication.instance()
win = next(w for w in app.topLevelWidgets() if w.objectName()=='MayaWindow')
# Add a custom property
win.setProperty('maya_ui', 'scriptEditor')
# Apply style sheet
styleSheet = '''
QWidget[maya_ui="scriptEditor"] QTextEdit {
font-family: %s;
font: normal %spx;
}
''' %(font, size)
app.setStyleSheet(styleSheet)
And with this I could change the script editor's font style and size uniformly across all tabs.
# this is my current favorite
set_font(font='Consolas', size=20)
In Maya 2018 and 2019 this works fine. I have not tested 2020, but in 2022 and 2023 it executes without errors but fails to change the interface as desired.
QUESTION
What has changed since 2019 that would make this script fail. Any tip on how to make this script work would be greatly appreciated. Otherwise I'll post a solution here when I find the issue.
I do not have a complete answer, but the following seems to work. One notable change is that QTextEdit appears to have been replaced with QPlainTextEdit, but only replacing that does not fix it.
However, the following accounts for Maya versions before and after 2022, and seems to work.
Tested on macOS 12.4 and Maya 2022.2 where the same solution applies. It may be that a different minor version of Maya 2022 requires the old solution.
import maya.cmds as cmds
from PySide2 import QtGui, QtCore, QtWidgets
def set_font(font='Courier New', size=12):
"""
Sets the style sheet of Maya's script Editor
"""
app = QtWidgets.QApplication.instance()
win = None
for w in app.topLevelWidgets():
if "Script Editor" in w.windowTitle():
win = w
break
if win is None:
return
# for Maya 2022 and above
if int(cmds.about(version=True)) >= 2022:
style = '''
QPlainTextEdit {
font-family: %s;
font: normal %dpx;
}
''' % (font, size)
win.setStyleSheet(style)
# for Maya 2020 and older
else:
style = '''
QWidget[maya_ui="scriptEditor"] QTextEdit {
font-family: %s;
font: normal %dpx;
}
''' % (font, size)
win.setProperty('maya_ui', 'scriptEditor')
app.setStyleSheet(style)
set_font(font='Consolas', size=20)
Related
Adding the cmds.connectAttr at the end does connect the selection set in Maya in the UI, but that's all it does. It acts as it its not registering.
import maya.cmds as cmds
import MASH.api as mapi
sel = cmds.ls(sl=1, l=1, fl=1)
new_set = cmds.sets(sel, n="custom_set")
obj_name = sel[0].split(".")[0]
shape = cmds.listRelatives(obj_name, s=True, f=1)
print(shape)
shape = "pCylinderShape1" #distribute mesh
cmds.select("|pCylinder2") #main mesh MASH
#create a new MASH network
mashNetwork = mapi.Network()
mashNetwork.createNetwork(name="Custom_placement", geometry="Repro")
shape = "pCylinderShape1"
mashNetwork.meshDistribute(shape, 4)
cmds.connectAttr(new_set+".message", mashNetwork.distribute+".selectionSetMessage")
Closest answer I found was here but I am not a programmer to know what that means.
If anyone can help, I'd much appreciate it.
After a lot of investigation I did manage to find the answer from the provided link.
The code I wrote was only the first part of the solution.
hasMASHFlag = cmds.objExists('%s.mashOutFilter' % (new_set))
if not hasMASHFlag:
cmds.addAttr( new_set, longName='mashOutFilter', attributeType='bool' )
cmds.setAttr( '%s.arrangement' % (mashNetwork.distribute), 4 )
cmds.setAttr( '%s.meshType' % (mashNetwork.distribute), 7 )
Note sure is needed but I noticed when you connect a selection set by default it has an extra attribute called mashOutFilter.
The part that is needed is the .meshType that makes it work.
I would like to instantiate the project.toml that's build in in a Pluto notebook with the native package manager. How do I read it from the notebook?
Say, I have a notebook, e.g.,
nb_source = "https://raw.githubusercontent.com/fonsp/Pluto.jl/main/sample/Interactivity.jl"
How can I create a temporary environment, and get the packages for the project of this notebook? In particular, how do I complete the following code?
cd(mktempdir())
import Pkg; Pkg.activate(".")
import Pluto, Pkg
nb = download(nb_source, ".")
### Some code using Pluto's build in package manager
### to read the Project.toml from nb --> nb_project_toml
cp(nb_project_toml, "./Project.toml", force=true)
Pkg.instantiate(".")
So, first of all, the notebook you are looking at is a Pluto 0.17.0 notebook, which does not have the internal package manager. I think it was added in Pluto 0.19.0.
This is what the very last few cells look like in a notebook using the internal pluto packages:
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
Plots = "~1.32.0"
PlutoUI = "~0.7.40"
PyCall = "~1.94.1"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.8.0"
...
so you could add something like:
import(nb)
write("./Project.toml", PLUTO_PROJECT_TOML_CONTENTS)
This has the drawback of running all the code in your notebook, which might take a while.
Alternatively, you could read the notebook file until you find the # ╔═╡ 00000000-0000-0000-0000-000000000001 line and then either parse the following string yourself or eval everything after that (something like eval(Meta.parse(string_stuff_after_comment)) should do it...)
I hope that helps a little bit.
The Pluto.load_notebook_nobackup() reads the information of a notebook. This gives a dictionary of deps in the field .nbpkg_ctx.env.project.deps
import Pluto, Pkg
Pkg.activate(;temp=true)
nb_source = "https://raw.githubusercontent.com/fonsp/Pluto.jl/main/sample/PlutoUI.jl.jl"
nb = download(nb_source)
nb_info = Pluto.load_notebook_nobackup(nb)
deps = nb_info.nbpkg_ctx.env.project.deps
Pkg.add([Pkg.PackageSpec(name=p, uuid=u) for (p, u) in deps])
I'm trying to add superscript to the new editor in Wagtail.
I see the documentation here: http://docs.wagtail.io/en/v2.0/advanced_topics/customisation/extending_draftail.html
Where am I supposed to add the example code?
And am I correct in assuming that I will be able to just change the example from feature_name = 'strikethrough' and type_ = 'STRIKETHROUGH' to superscript and it will work?
Once this is registered, do I have to modify each RichTextField that I have to include it in the features setting, or is there a way to add this to all RTF in my application?
I believe I have figured out how to do this, hopefully, someone will correct me if there is a better way!
Create a file in one of your registered (in INSTALLED_APPS) app directories called wagtail_hooks.py.
Put the following code in the file:
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
from wagtail.core import hooks
#hooks.register('register_rich_text_features')
def register_strikethrough_feature(features):
feature_name = 'superscript'
type_ = 'SUPERSCRIPT'
tag = 'sup'
control = {
'type': type_,
'label': '^',
'description': 'Superscript',
}
features.register_editor_plugin(
'draftail', feature_name, draftail_features.InlineStyleFeature(control)
)
db_conversion = {
'from_database_format': {tag: InlineStyleElementHandler(type_)},
'to_database_format': {'style_map': {type_: tag}},
}
features.default_features.append(feature_name)
features.register_converter_rule('contentstate', feature_name, db_conversion)
The line features.default_features.append(feature_name) is what answers the last part of my question - and is missing from the docs (well, it's there, but not in this context). This adds the feature to all RichTextFields without having to add the features=[] setting to each existing and/or new RTF.
To modify this to work with another built in Draftail feature, modify the feature_name, type_, tag, label, and description fields. Draftail supports the following types:
Block types: H1, H2, H3, H4, H5, H6, Blockquote, Code, UL, OL, P
Inline styles: Bold, Italic, Underline, Code, Strikethrough, Mark, Keyboard, Superscript, Subscript
And HR, BR
With bold, italic, h2, h3, h4, ul, ol, hr, and br already being in the Wagtail default set for a RichTextField.
As of Wagtail v2.5, superscript is a built-in format, disabled by default. To use it, all that's needed is to enable it. Either per-field, in the model definition:
# [...]
body = RichTextField(features=['superscript'])
# [...]
Or for all editors on a site:
from wagtail.core import hooks
#hooks.register('register_rich_text_features')
def enable_superscript_feature(features):
features.default_features.append('superscript')
Note that currently, while superscript will work as expected in the editor, it won’t be possible to copy-paste content with superscript from third-party sources (Google Docs, Word, web pages) and have the superscript formatting be preserved.
In an SSMS add-in, the following code will toggle the fontsize of the text editor window between 10 and 22:
Properties props_texteditor = _addInInstance.DTE.Properties["FontsAndColors", "TextEditor"];
Property propFontSize = props_texteditor.Item(3); //"FontSize"
propFontSize.Value = ((Int16)propFontSize.Value == 10 ? 22 : 10);
Not particularly useful, but it demonstrates that my add-in can set an SSMS Tools/Options property, in this case using the category/page names "FontsAndColors", "TextEditor".
What I actually want my add-in to do is set the scripting option "Include IF NOT EXISTS clause" to true or false, but I can't find any documentation on it. Anyone know how to do it?
Have a look at SSMSBoost add-in, that I develop. I have implemented custom scripting options there.
If you want to experiment yourself, have a look at these objects:
Microsoft.SqlServer.Management.UserSettings.ScriptingOptions
Microsoft.SqlServer.Management.Smo.Scripter
I want to verify the placeholder text present in a text field using robotframework.
I have used different Selenium2Library keywords but none of them do precisely what I want.
Does anyone have an approach to getting this functionality from within my test?
You can run the command getAttribute(input_field_locator#placeholder). This will return you the text you want and then you can assert on it.
Once you have managed to access the functionality you are looking for from the REPL, you may find that it is not accessible via robotframework. You can expose new keywords by creating a wrapper for Selenium2Library which extends it with extra functionality - for an example see https://github.com/alistair-broomhead/scalable-robotframework-example/blob/master/TestLibraries/Selenium2Custom from a tutorial I am working on.
This example simply adds two keywords to robotframework on top of those in Selenium2Library if you instead import this class (Get Text and Get HTML, which are useful for verification):
from Selenium2Library import Selenium2Library
class Selenium2Custom(Selenium2Library):
"""
Custom wrapper for robotframework Selenium2Library to add extra functionality
"""
def get_text(self, locator):
"""
Returns the text of element identified by `locator`.
See `introduction` for details about locating elements.
"""
return self._get_text(locator)
def get_html(self, id=None):
"""
Get the current document as an XML accessor object.
"""
from lxml import html
src = self.get_source().encode('ascii', 'xmlcharrefreplace')
page = html.fromstring(src)
element = page.get_element_by_id(id) if id is not None else page
return html.tostring(element)
As such it would be trivial to do something like this:
from Selenium2Library import Selenium2Library
class Selenium2Custom(Selenium2Library):
"""
Custom wrapper for robotframework Selenium2Library to add extra functionality
"""
def get_placeholder(self, locator):
"""
Returns the placeholder text of element identified by `locator`.
"""
element = self._element_find(locator, True, False)
return element.get_attribute("#placeholder")
Now I don't know that this will definately work for you, but for me it works like so:
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from Selenium2Library import Selenium2Library
>>> def get_placeholder(self, locator):
... element = self._element_find(locator, True, False)
... return element.get_attribute("placeholder")
...
>>> Selenium2Library.get_placeholder = get_placeholder
>>> session = Selenium2Library()
>>> session.open_browser("http://www.wikipedia.org/wiki/Main_Page",
remote_url="http://127.0.0.1:4444/wd/hub")
1
>>> session.get_placeholder("search")
u'Search'
>>>
I also wanted to check placeholder text and after coming here and reading the comments, I got some clue about it. Now, the tricky part is how to do this in robot framework and after doing some math, I was able to do this pretty easily. Here is my answer in 2 lines:
${webelement}= Get WebElement locator
${placeholder}= Call Method ${webelement} get_attribute placeholder