<commit_before>Class {
	#name : #LWTVariableImageWidget,
	#superclass : #LWTWidget,
	#instVars : [
		'form',
		'value',
		'forms'
	],
	#category : 'ViennaTalk-LivelyWalkThrough-Widgets'
}

{ #category : #json }
LWTVariableImageWidget class >> fromJsonObject: aDictionary on: aLWTDirector [
	^ (super fromJsonObject: aDictionary on: aLWTDirector)
		rawValue: (aDictionary at: '_rawValue');
		yourself
]

{ #category : #operations }
LWTVariableImageWidget >> addImage [
	| key |
	[ 
	key := UIManager default request: 'Enter a value to map from'.
	key ifNil: [ ^ self ].
	(forms includesKey: key) and: [ (UIManager proceed: key , ' is already defined. Do you want to overwite it?') not ] ]
		whileTrue.
	(LivelyWalkThrough
		fileOpen: 'Select an image file'
		extensions: #('png' 'jpg' 'jpeg')
		path: nil
		preview: #image)
		ifNotNil: [ :filename | 
			[forms at: key put: (Form fromFileNamed: filename fullName)] on: Error do: [:ex | ].
			self updateImage ]
]

{ #category : #json }
LWTVariableImageWidget >> asJsonObject [
	^ super asJsonObject
		at: 'base64Forms' put: self base64Forms;
		at: '_rawValue' put: self rawValue;
		yourself
]

{ #category : #events }
LWTVariableImageWidget >> availableEventSelectors [
	^ #(#changed #clicked #doubleClicked #entered #moved #left #up)
]

{ #category : #private }
LWTVariableImageWidget >> base64Forms [
	| base64Forms |
	base64Forms := Dictionary new.
	forms
		keysAndValuesDo: [ :key :image | 
			base64Forms
				at: (key ifNil: [ '' ])
				put:
					(Base64MimeConverter
						mimeEncode:
							(ByteArray new: 1024 streamContents: [ :stream | PNGReadWriter putForm: image onStream: stream ]) readStream
						multiLine: false) contents ].
	^ base64Forms
]

{ #category : #private }
LWTVariableImageWidget >> base64Forms: aDictionary [
	| newForms |
	newForms := Dictionary new.
	aDictionary
		keysAndValuesDo: [ :key :base64 | 
			newForms
				at: (key ifEmpty: [ nil ])
				put: (PNGReadWriter formFromStream: (Base64MimeConverter mimeDecodeToBytes: base64 readStream)) ].
	forms := newForms
]

{ #category : #accessing }
LWTVariableImageWidget >> basename [
	^ 'VariableImage'
]

{ #category : #operations }
LWTVariableImageWidget >> changeDefaultImage [
	(LivelyWalkThrough
		fileOpen: 'Select an image file'
		extensions: #('png' 'jpg' 'jpeg')
		path: nil
		preview: #image)
		ifNotNil: [ :filename | 
			[ forms at: nil put: (Form fromFileNamed: filename fullName) ]
				on: Error
				do: [ :ex |  ].
			self updateImage ]<commit_msg>empty log message<commit_after>Class {
	#name : #LWTVariableImageWidget,
	#superclass : #LWTWidget,
	#instVars : [
		'form',
		'value',
		'forms'
	],
	#category : 'ViennaTalk-LivelyWalkThrough-Widgets'
}

{ #category : #operations }
LWTVariableImageWidget >> addImage [
	| key |
	[ 
	key := UIManager default request: 'Enter a value to map from'.
	key ifNil: [ ^ self ].
	(forms includesKey: key) and: [ (UIManager proceed: key , ' is already defined. Do you want to overwite it?') not ] ]
		whileTrue.
	(LivelyWalkThrough
		fileOpen: 'Select an image file'
		extensions: #('png' 'jpg' 'jpeg')
		path: nil
		preview: #image)
		ifNotNil: [ :filename | 
			[forms at: key put: (Form fromFileNamed: filename fullName)] on: Error do: [:ex | ].
			self updateImage ]
]

{ #category : #json }
LWTVariableImageWidget >> asJsonObject [
	^ super asJsonObject
		at: 'base64Forms' put: self base64Forms;
		at: '_rawValue' put: self rawValue;
		yourself
]

{ #category : #events }
LWTVariableImageWidget >> availableEventSelectors [
	^ #(#changed #clicked #doubleClicked #entered #moved #left #up)
]

{ #category : #private }
LWTVariableImageWidget >> base64Forms [
	| base64Forms |
	base64Forms := Dictionary new.
	forms
		keysAndValuesDo: [ :key :image | 
			base64Forms
				at: (key ifNil: [ '' ])
				put:
					(Base64MimeConverter
						mimeEncode:
							(ByteArray new: 1024 streamContents: [ :stream | PNGReadWriter putForm: image onStream: stream ]) readStream
						multiLine: false) contents ].
	^ base64Forms
]

{ #category : #private }
LWTVariableImageWidget >> base64Forms: aDictionary [
	| newForms |
	newForms := Dictionary new.
	aDictionary
		keysAndValuesDo: [ :key :base64 | 
			newForms
				at: (key ifEmpty: [ nil ])
				put: (PNGReadWriter formFromStream: (Base64MimeConverter mimeDecodeToBytes: base64 readStream)) ].
	forms := newForms.
	self updateImage
]

{ #category : #accessing }
LWTVariableImageWidget >> basename [
	^ 'VariableImage'
]

{ #category : #operations }
LWTVariableImageWidget >> changeDefaultImage [
	(LivelyWalkThrough
		fileOpen: 'Select an image file'
		extensions: #('png' 'jpg' 'jpeg')
		path: nil
		preview: #image)
		ifNotNil: [ :filename | 
			[ forms at: nil put: (Form fromFileNamed: filename fullName) ]
				on: Error
				do: [ :ex |  ].
			self updateImage ]
{'fraction_non_alphanumeric': 0.12476528270394326, 'fraction_numerical': 0.011683705403713749, 'mean_word_length': 4.056962025316456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6443166', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1628, 'n_words': 432}