Skip to content

Commit

Permalink
add read access to settings for jsavascript
Browse files Browse the repository at this point in the history
add an option to disable lightbox modal
  • Loading branch information
AUTOMATIC1111 committed Sep 18, 2022
1 parent 21086e6 commit f3d83fd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
4 changes: 2 additions & 2 deletions javascript/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function showGalleryImage(){
e.style.cursor='pointer'

e.addEventListener('click', function (evt) {
showModal(evt)

if(!opts.js_modal_lightbox) return;
showModal(evt)
},true);
}
});
Expand Down
39 changes: 39 additions & 0 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,42 @@ function ask_for_style_name(_, prompt_text, negative_prompt_text) {
name_ = prompt('Style name:')
return name_ === null ? [null, null, null]: [name_, prompt_text, negative_prompt_text]
}

opts = {}
function apply_settings(jsdata){
console.log(jsdata)

opts = JSON.parse(jsdata)

return jsdata
}

onUiUpdate(function(){
if(Object.keys(opts).length != 0) return;

json_elem = gradioApp().getElementById('settings_json')
if(json_elem == null) return;

textarea = json_elem.querySelector('textarea')
jsdata = textarea.value
opts = JSON.parse(jsdata)


Object.defineProperty(textarea, 'value', {
set: function(newValue) {
var valueProp = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');
var oldValue = valueProp.get.call(textarea);
valueProp.set.call(textarea, newValue);

if (oldValue != newValue) {
opts = JSON.parse(textarea.value)
}
},
get: function() {
var valueProp = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');
return valueProp.get.call(textarea);
}
});

json_elem.parentElement.style.display="none"
})
5 changes: 5 additions & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __init__(self, default=None, label="", component=None, component_args=None,
"interrogate_clip_max_length": OptionInfo(48, "Interrogate: maximum description length", gr.Slider, {"minimum": 1, "maximum": 256, "step": 1}),
"interrogate_clip_dict_limit": OptionInfo(1500, "Interrogate: maximum number of lines in text file (0 = No limit)"),
"sd_model_checkpoint": OptionInfo(None, "Stable Diffusion checkpoint", gr.Radio, lambda: {"choices": [x.title for x in modules.sd_models.checkpoints_list.values()]}),
"js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"),
}

def __init__(self):
Expand Down Expand Up @@ -193,6 +194,10 @@ def onchange(self, key, func):
item = self.data_labels.get(key)
item.onchange = func

def dumpjson(self):
d = {k: self.data.get(k, self.data_labels.get(k).default) for k in self.data_labels.keys()}
return json.dumps(d)


opts = Options()
if os.path.exists(config_filename):
Expand Down
13 changes: 11 additions & 2 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def run_settings(*args):
return 'Settings applied.'

with gr.Blocks(analytics_enabled=False) as settings_interface:
submit = gr.Button(value="Apply settings", variant='primary')
settings_submit = gr.Button(value="Apply settings", variant='primary')
result = gr.HTML()

with gr.Row(elem_id="settings").style(equal_height=False):
Expand All @@ -870,7 +870,7 @@ def run_settings(*args):
if index < len(keys):
components.append(create_setting_component(keys[index]))

submit.click(
settings_submit.click(
fn=run_settings,
inputs=components,
outputs=[result]
Expand All @@ -896,11 +896,20 @@ def run_settings(*args):
css += css_hide_progressbar

with gr.Blocks(css=css, analytics_enabled=False, title="Stable Diffusion") as demo:

with gr.Tabs() as tabs:
for interface, label, ifid in interfaces:
with gr.TabItem(label, id=ifid):
interface.render()

text_settings = gr.Textbox(elem_id="settings_json", value=opts.dumpjson(), visible=False)

settings_submit.click(
fn=lambda: opts.dumpjson(),
inputs=[],
outputs=[text_settings],
)

tabs.change(
fn=lambda x: x,
inputs=[init_img_with_mask],
Expand Down
6 changes: 5 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ function onUiUpdate(callback){

function uiUpdate(root){
uiUpdateCallbacks.forEach(function(x){
x()
try {
x()
} catch (e) {
(console.error || console.log).call(console, e.message, e);
}
})
}

Expand Down

0 comments on commit f3d83fd

Please sign in to comment.