Skip to content

Commit cf3ce94

Browse files
committed
Final set of flake8 code cleanups
1 parent 4e4c5fb commit cf3ce94

23 files changed

+1228
-1136
lines changed

.flake8

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[flake8]
2+
max-line-length = 79
3+
ignore = E402
4+
exclude =
5+
__pycache__,
6+
*.pyc,
7+
.git,
8+
.tox,
9+
.pytest_cache,
10+
build,
11+
dist,
12+
*.egg-info
13+
14+
# E402: module level import not at top of file
15+
# This is ignored because gi.require_version() calls must come before gi imports
16+
# which is a required pattern for GTK/GObject applications
17+
18+
per-file-ignores =
19+
models/factory.py:F401

api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import integrator
2121
from i18n import _
22-
from models import BaseModel
2322
from models.factory import get_default_model, get_model_by_name
2423

2524
PROGRESS_COMPLETE = 1.0
@@ -287,9 +286,9 @@ def _execute_api_call(self, model_input: dict) -> Union[object, str]:
287286

288287
except ModelError as e:
289288
error_msg = _("Model error: {error}").format(error=str(e))
290-
if (hasattr(e, 'prediction') and e.prediction and
291-
hasattr(e.prediction, 'logs') and e.prediction.logs):
292-
error_msg += f"\n{_('Logs')}: {e.prediction.logs}"
289+
if hasattr(e, 'prediction') and e.prediction:
290+
if hasattr(e.prediction, 'logs') and e.prediction.logs:
291+
error_msg += f"\n{_('Logs')}: {e.prediction.logs}"
293292
return error_msg
294293

295294
except ReplicateError as e:

dialog.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def get_api_key_visible(self):
5151

5252
def get_current_mode(self):
5353
"""Get the currently selected mode"""
54-
if self.ui.generate_mode_radio and self.ui.generate_mode_radio.get_active():
54+
generate_radio = self.ui.generate_mode_radio
55+
if generate_radio and generate_radio.get_active():
5556
return "generate"
5657
return "edit"
5758

@@ -60,7 +61,9 @@ def get_prompt(self):
6061
if self.ui.prompt_buffer:
6162
start_iter = self.ui.prompt_buffer.get_start_iter()
6263
end_iter = self.ui.prompt_buffer.get_end_iter()
63-
return self.ui.prompt_buffer.get_text(start_iter, end_iter, False).strip()
64+
return self.ui.prompt_buffer.get_text(
65+
start_iter, end_iter, False
66+
).strip()
6467
return ""
6568

6669
def _initialize(self):

dialog_events.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
Handles all user interactions and UI events
77
"""
88

9-
import threading
10-
119
from gi.repository import Gtk, GLib
1210

1311
from dialog_threads import DreamPrompterThreads
@@ -62,10 +60,14 @@ def connect_all_signals(self):
6260
if self.ui.edit_mode_radio:
6361
self.ui.edit_mode_radio.connect("toggled", self.on_mode_changed)
6462
if self.ui.generate_mode_radio:
65-
self.ui.generate_mode_radio.connect("toggled", self.on_mode_changed)
63+
self.ui.generate_mode_radio.connect(
64+
"toggled", self.on_mode_changed
65+
)
6666

6767
if self.ui.toggle_visibility_btn:
68-
self.ui.toggle_visibility_btn.connect("toggled", self.on_toggle_visibility)
68+
self.ui.toggle_visibility_btn.connect(
69+
"toggled", self.on_toggle_visibility
70+
)
6971

7072
if self.ui.file_chooser_btn:
7173
self.ui.file_chooser_btn.connect("clicked", self.on_select_files)
@@ -111,8 +113,8 @@ def on_generate(self, _button):
111113
self.show_error(_("Please enter a prompt"))
112114
return
113115

114-
edit_active = (self.ui.edit_mode_radio and
115-
self.ui.edit_mode_radio.get_active())
116+
edit_radio = self.ui.edit_mode_radio
117+
edit_active = (edit_radio and edit_radio.get_active())
116118
if edit_active and not self.drawable:
117119
self.show_error(_("Edit mode requires a selected layer"))
118120
return
@@ -128,11 +130,13 @@ def on_generate(self, _button):
128130

129131
if mode == "edit":
130132
self.threads.start_edit_thread(
131-
api_key, prompt_text, self.ui.selected_files, selected_model_name
133+
api_key, prompt_text, self.ui.selected_files,
134+
selected_model_name
132135
)
133136
else:
134137
self.threads.start_generate_thread(
135-
api_key, prompt_text, self.ui.selected_files, selected_model_name
138+
api_key, prompt_text, self.ui.selected_files,
139+
selected_model_name
136140
)
137141

138142
def on_model_changed(self, combo_box):
@@ -154,11 +158,12 @@ def on_mode_changed(self, _radio_button):
154158
if self.ui.edit_mode_radio.get_active():
155159
max_edit_files = self.model.max_reference_images_edit
156160
if len(self.ui.selected_files) > max_edit_files:
157-
self.ui.selected_files = self.ui.selected_files[:max_edit_files]
161+
self.ui.selected_files = (
162+
self.ui.selected_files[:max_edit_files]
163+
)
158164
self.ui.update_files_display()
159-
print(_("Reduced to {max} reference images for edit mode").format(
160-
max=max_edit_files
161-
))
165+
message = _("Reduced to {max} reference images for edit mode")
166+
print(message.format(max=max_edit_files))
162167

163168
if self.ui.generate_btn:
164169
self.ui.generate_btn.set_label(_("Generate Edit"))
@@ -221,16 +226,14 @@ def on_select_files(self, _button):
221226
elif files:
222227
if current_mode == "edit":
223228
max_refs = self.model.max_reference_images_edit
224-
print(_("Cannot add {count} files. Maximum {max} reference "
225-
"images allowed in edit mode.").format(
226-
count=len(files), max=max_refs
227-
))
229+
message = _("Cannot add {count} files. Maximum {max} "
230+
"reference images allowed in edit mode.")
231+
print(message.format(count=len(files), max=max_refs))
228232
else:
229233
max_refs = self.model.max_reference_images
230-
print(_("Cannot add {count} files. Maximum {max} reference "
231-
"images allowed.").format(
232-
count=len(files), max=max_refs
233-
))
234+
message = _("Cannot add {count} files. Maximum {max} "
235+
"reference images allowed.")
236+
print(message.format(count=len(files), max=max_refs))
234237

235238
dialog.destroy()
236239

@@ -300,12 +303,16 @@ def update_ui_limits(self):
300303
if current_mode == "edit":
301304
if self.ui.images_help_label:
302305
max_imgs = self.model.max_reference_images_edit
303-
text = _("Select up to {max} additional images").format(max=max_imgs)
306+
text = _("Select up to {max} additional images").format(
307+
max=max_imgs
308+
)
304309
markup = f'<small>{text}</small>'
305310
self.ui.images_help_label.set_markup(markup)
306311
else:
307312
if self.ui.images_help_label:
308313
max_imgs = self.model.max_reference_images
309-
text = _("Select up to {max} additional images").format(max=max_imgs)
314+
text = _("Select up to {max} additional images").format(
315+
max=max_imgs
316+
)
310317
markup = f'<small>{text}</small>'
311318
self.ui.images_help_label.set_markup(markup)

0 commit comments

Comments
 (0)