readonly-attribute

python, __slots__, and “attribute is read-only”

戏子无情 提交于 2019-12-02 20:36:03
I want to create an object in python that has a few attributes and I want to protect myself from accidentally using the wrong attribute name. The code is as follows: class MyClass( object ) : m = None # my attribute __slots__ = ( "m" ) # ensure that object has no _m etc a = MyClass() # create one a.m = "?" # here is a PROBLEM But after running this simple code, I get a very strange error: Traceback (most recent call last): File "test.py", line 8, in <module> a.m = "?" AttributeError: 'test' object attribute 'm' is read-only Is there any wise programmer who can spare a bit of their time and

How can I make a read only version of a class?

天涯浪子 提交于 2019-11-30 11:14:46
I have a class with various public properties which I allow users to edit through a property grid. For persistence this class is also serialized/deserialized to/from an XML file through DataContractSerializer. Sometimes I want to user to be able to save (serialize) changes they've made to an instance of the class. Yet at other times I don't want to allow the user to save their changes, and should instead see all the properties in the property grid as read only. I don't want to allow users to make changes that they'll never be able to save later. Similar to how MS Word will allow users to open

Ace Editor: Lock or Readonly Code Segment

强颜欢笑 提交于 2019-11-30 06:48:25
Using the Ace Code Editor can I lock or make readonly a segment of code but still allow other lines of code to be written or edited during a session? Here is the start of a solution: $(function() { var editor = ace.edit("editor1") , session = editor.getSession() , Range = require("ace/range").Range , range = new Range(1, 4, 1, 10) , markerId = session.addMarker(range, "readonly-highlight"); session.setMode("ace/mode/javascript"); editor.keyBinding.addKeyboardHandler({ handleKeyboard : function(data, hash, keyString, keyCode, event) { if (hash === -1 || (keyCode <= 40 && keyCode >= 37)) return

How can I make a read only version of a class?

大城市里の小女人 提交于 2019-11-29 16:53:08
问题 I have a class with various public properties which I allow users to edit through a property grid. For persistence this class is also serialized/deserialized to/from an XML file through DataContractSerializer. Sometimes I want to user to be able to save (serialize) changes they've made to an instance of the class. Yet at other times I don't want to allow the user to save their changes, and should instead see all the properties in the property grid as read only. I don't want to allow users to

Ace Editor: Lock or Readonly Code Segment

痴心易碎 提交于 2019-11-29 06:15:50
问题 Using the Ace Code Editor can I lock or make readonly a segment of code but still allow other lines of code to be written or edited during a session? 回答1: Here is the start of a solution: $(function() { var editor = ace.edit("editor1") , session = editor.getSession() , Range = require("ace/range").Range , range = new Range(1, 4, 1, 10) , markerId = session.addMarker(range, "readonly-highlight"); session.setMode("ace/mode/javascript"); editor.keyBinding.addKeyboardHandler({ handleKeyboard :

WTForms support for input readonly attribute?

家住魔仙堡 提交于 2019-11-28 23:17:29
Here they say it's not supported out of the box. Do you know a way to make HTML input form fields use the 'readonly' attribute with WTForms? I assume you are talking about the <input readonly> attribute in HTML/XHTML, which is not what that discussion thread you linked is about. (the linked thread is about a lower-level issue with how to ignore passed form input) The way to set a readonly attribute (and indeed any attribute on a field) is as a keyword-arg in your template. If using Jinja, this looks like (html5): {{ form.myfield(readonly=true) }} And for XHTML or versions of WTForms older than

How to create readonly textbox in ASP.NET MVC3 Razor

那年仲夏 提交于 2019-11-28 04:26:29
How to create a readonly textbox in ASP.NET MVC3, With Razor view engine ? Is there an HTMLHelper method available to do that ? Something like this ? @Html.ReadOnlyTextBoxFor(m => m.userCode) @Html.TextBoxFor(m => m.userCode, new { @readonly="readonly" }) You are welcome to make an HTML Helper for this, but this is simply just an HTML attribute like any other. Would you make an HTML Helper for a text box that has other attributes? UPDATE: Now it's very simple to add html attributes to default editor templates. Means instead of doing this: @Html.TextBoxFor(m => m.userCode, new { @readonly=

Does ReadOnly(true) work with Html.EditorForModel?

人盡茶涼 提交于 2019-11-27 16:49:27
问题 Consider the following setup: Model: public class Product { [ReadOnly(true)] public int ProductID { get; set; } public string Name { get; set; } } View: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication4.Models.Product>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Home Page </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <%= Html.EditorForModel()

WTForms support for input readonly attribute?

心不动则不痛 提交于 2019-11-27 13:46:21
问题 Here they say it's not supported out of the box. Do you know a way to make HTML input form fields use the 'readonly' attribute with WTForms? 回答1: I assume you are talking about the <input readonly> attribute in HTML/XHTML, which is not what that discussion thread you linked is about. (the linked thread is about a lower-level issue with how to ignore passed form input) The way to set a readonly attribute (and indeed any attribute on a field) is as a keyword-arg in your template. If using Jinja

How to create a readonly textbox in ASP.NET MVC3 Razor

安稳与你 提交于 2019-11-27 05:20:37
问题 How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine? Is there an HTMLHelper method available to do that? Something like the following? @Html.ReadOnlyTextBoxFor(m => m.userCode) 回答1: @Html.TextBoxFor(m => m.userCode, new { @readonly="readonly" }) You are welcome to make an HTML Helper for this, but this is simply just an HTML attribute like any other. Would you make an HTML Helper for a text box that has other attributes? 回答2: UPDATE: Now it's very simple to add HTML