I'm designing a simple GUI for a Blender 2.80 plug-in. I've created a dialog box to enter some data:
I would like to replace the line of text ("Lorem ipsum ...") with a button with a custom label (example "click here to visit our website").
Below is the code I am using:
class ExportFDSCloudHPC(Operator):
bl_idname = "..."
bl_label = "Title"
bl_description = "..."
data1 = bpy.props.StringProperty(
name = "Text 1",
default = "..."
)
data2 = bpy.props.StringProperty(
name = "Text 2",
default = "..."
)
data3 = bpy.props.StringProperty(
name = "Text 3",
default = "..."
)
def draw(self, context):
col = self.layout.column(align = True)
col.prop(self, "data1")
self.layout.label(text="Lorem ipsum dolor sit amet, consectetur adipisci elit...")
col = self.layout.column(align = True)
col.prop(self, "data2")
col = self.layout.column(align = True)
col.prop(self, "data3")
def execute(self, context):
...
To get button you need to provide an existing operator: row.operator("wm.save_as_mainfile") button text is defined in operator. If you want to change name of existing operator use row.operator("wm.save_as_mainfile", text='My Save Label')
You can create own operator:
import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator" # <- put this string in layout.operator()
bl_label = "Simple Object Operator" # <- button name
#classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.object.simple_operator()
and then use it like that:
[..]
col.prop(self, "data1")
col.operator("object.simple_operator")
# self.layout.label(text="Lorem ipsum dolor sit amet, consectetur adipisci elit...")
col = self.layout.column(align = True)
[..]
Related
I'm designing a simple GUI for a Blender 2.80 plug-in. I've created a dialog box to enter some data:
class ExportFDSCloudHPC(Operator):
bl_idname = "..."
bl_label = "Dialog Box"
bl_description = "..."
data1 = bpy.props.StringProperty(
name = "Data 1",
default = "..."
)
data2 = bpy.props.StringProperty(
name = "Data 2",
default = "..."
)
data3 = bpy.props.StringProperty(
name = "Data 3",
default = "..."
)
def draw(self, context):
col = self.layout.column(align = True)
col.prop(self, "data1")
col = self.layout.column(align = True)
col.prop(self, "data2")
col = self.layout.column(align = True)
col.prop(self, "data3")
def execute(self, context):
...
I would like to add a line of text above Data 1 with a message that has the same length as the dialog box. It's possible?
Add label() in draw() as you adding column:
def draw(self, context):
self.layout.label(text="text")
col = self.layout.column(align = True)
Here is label documentation
I have model:
class Ingredient(models.Model):
KILOGRAM = 'kg'
LITER = 'ltr'
PIECES = 'pcs'
MUNITS_CHOICES = (
(KILOGRAM, 'Kilogram'),
(LITER, 'Liter'),
(PIECES, 'Pieces'),
)
name = models.CharField(max_length=200,unique=True,null=False)
slug = models.SlugField(unique=True)
munit = models.CharField(max_length=10,choices=MUNITS_CHOICES,default=KILOGRAM)
rate = models.DecimalField(max_digits=19, decimal_places=2,validators=[MinValueValidator(0)],default=0)
typeofingredient = models.ForeignKey(TypeOfIngredient, related_name='typeof_ingredient',null=True, blank=True,on_delete=models.PROTECT)
density_kg_per_lt = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (kg/lt)',null=True,blank=True,validators=[MinValueValidator(0)])
density_pcs_per_kg = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (pcs/kg)',null=True,blank=True,validators=[MinValueValidator(0)])
density_pcs_per_lt = models.DecimalField(max_digits=19, decimal_places=2,verbose_name='Density (pcs/lt)',null=True,blank=True,validators=[MinValueValidator(0)])
updated = models.DateTimeField(auto_now=True, auto_now_add=False)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
When i get the api i also want to get field types like char, decimal, datetime etc
Something like the below api result, is it possible. Because i am using reactJs as frontend, i have tell the input what kind of field it can accept and also helps in sorting by text or number
{
"id": {value: 1,type: number},
"name": {value: "adark",type: charfield},
"rate": {value: "12.00",type: decimal},
"updated": {value: "2017-07-14T10:51:47.847171Z",type: datetime},
.......so on
}
The Corresponding Serializer would be as follows:
class IngredientSerializer(serializers.ModelSerializer):
name = serializers.SerializerMethodField()
rate = serializers.SerializerMethodField()
updated = serializers.SerializerMethodField()
class Meta:
model = Ingredient
fields = ('name', 'rate', 'updated')
def get_name(self, obj):
response = dict()
response['value'] = obj.name
response['type'] = obj.name.get_internal_type()
return Response(response)
def get_rate(self, obj):
response = dict()
response['value'] = obj.rate
response['type'] = obj.rate.get_internal_type()
return Response(response)
def get_updated(self, obj):
response = dict()
response['value'] = obj.updated
response['type'] = obj.updated.get_internal_type()
return Response(response)
I have a text file say data.txt which contains content of format:
( {
city = Leesburg;
country = USA;
dob = "";
email = "email#domain.com";
firstName = "EricM.";
homePhone = "";
lastName = Abcdef;
mobilePhone = 12312312;
state = Virginia;
workPhone = 12312312;
},
{
city = "Mt. Uncle";
dob = "";
email = "";
firstName = first;
homePhone = "";
lastName = Berry;
mobilePhone = 234234;
state = MD;
workPhone = "";
}
)
require "json"
file = File.open("data.txt")
contents = file.read
hashes = contents.scan(/{(.*?)}/mx)
arr = []
hashes.each do |hash|
hashitems = hash[0].scan(/(\w+\s=\s.+?);/)
ahash = {}
hashitems.each do |hashitem|
itemarr = hashitem[0].split(" = ")
ahash[itemarr[0]] = itemarr[1]
end
arr << ahash
end
print JSON.dump(arr)
What I've done here is use two regex functions to break down your data into a Ruby object, then I've used the JSON library to dump the object to JSON.
in this example of GuidedTour of Swift by
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/
var optionalString: String? = "Hello"
optionalString == nil
var optionalName: String? = "John Appleseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \( name)"
}
I can not do this experiment, because of error
Change optionalName to nil. What greeting do you get? Add an else clause that sets a different greeting if optionalName is nil.
When I create new playground and enter exactly the same code you posted, it works. Can you post complete code ?
// Playground - noun: a place where people can play
import Foundation
var optionalString: String? = "Hello"
optionalString == nil
var optionalName: String? = "John Appleseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \( name)"
}
Only thing which is different, seems that you forgot to import Foundation framework:
import Foundation
var optionalString: String? = "Hello"
print(optionalString == nil)
var optionalName: String? = nil
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \(name)"
}else{
greeting = "Hello Max"
}
greeting
Hello everyone I am new to blackberry and I want a textfield that scroll it's text i.e greater than the preferred width horizontally , also able to show label out side the text draw area ( e.g. on the left side). Please help me.
This may be achieved by combining non-scrolling and scrolling HorizontalFieldManagers.
Try this code:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
editHolder.add(new TextField(TextField.NO_NEWLINE));
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Setting default text code:
class Scr extends MainScreen {
public Scr() {
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField(TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
// set some text then
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
textField.setText(text);
}
}
And something which basically works on 4.6/4.7:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"+
" adipiscing elit, sed diam nonummy nibh euismod tincidunt"+
" ut laoreet dolore magna aliquam erat volutpat.";
HorizontalFieldManager fieldHolder = new HorizontalFieldManager(
NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("",text,1024,TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}
Border for Manager
Border border = BorderFactory.createSimpleBorder(new XYEdges(4,4,4,4));
fieldHolder.setBorder(border);
Fixed size Manager
class SizedHFM extends HorizontalFieldManager {
int mWidth = 0;
public SizedHFM(int width) {
super(NO_HORIZONTAL_SCROLL | NO_HORIZONTAL_SCROLLBAR);
mWidth = width;
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mWidth, maxHeight);
setExtent(mWidth, getPreferredHeight());
}
}
Sample of use:
class Scr extends MainScreen {
public Scr() {
String text = "Lorem ipsum dolor sit amet, consectetuer"
+ " adipiscing elit, sed diam nonummy nibh euismod tincidunt"
+ " ut laoreet dolore magna aliquam erat volutpat.";
SizedHFM fieldHolder = new SizedHFM(200);
Border border = BorderFactory
.createSimpleBorder(new XYEdges(4, 4, 4, 4));
fieldHolder.setBorder(border);
fieldHolder.add(new LabelField("some label: "));
HorizontalFieldManager editHolder = new HorizontalFieldManager(
HORIZONTAL_SCROLL | HORIZONTAL_SCROLLBAR);
TextField textField = new TextField("", text, 1024,
TextField.NO_NEWLINE);
editHolder.add(textField);
fieldHolder.add(editHolder);
add(fieldHolder);
}
}