Skip to content

Commit 2c2e79f

Browse files
Python style check.
1 parent 086f3e4 commit 2c2e79f

File tree

6 files changed

+42
-52
lines changed

6 files changed

+42
-52
lines changed

create-imgs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
from __future__ import print_function
3+
34
import os
45
import sys
56
import subprocess
@@ -46,6 +47,7 @@
4647
IMG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
4748
'pygubudesigner', 'images', 'widgets')
4849

50+
4951
def create_images():
5052
origin = os.path.join(IMG_DIR, 'png', '22x22')
5153
dest = os.path.join(IMG_DIR, '22x22')
@@ -54,7 +56,7 @@ def create_images():
5456
iimage = os.path.join(origin, f)
5557
for output in v:
5658
print('.', end='', flush=True)
57-
oimage = os.path.join(dest,output)
59+
oimage = os.path.join(dest, output)
5860
cmd = 'convert {0} {1}.gif'.format(iimage, oimage)
5961
cmd = shlex.split(cmd)
6062
subprocess.call(cmd)
@@ -76,7 +78,7 @@ def create_images():
7678

7779
def find_source_image_for(widget_name):
7880
found = None
79-
for k, v in gtk_imgs.iteritems():
81+
for k, v in gtk_imgs.items():
8082
if widget_name in v:
8183
found = k
8284
break

pygubu/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import unicode_literals
2+
23
__all__ = ['Builder', 'TkApplication']
34

45
from pygubu.builder import Builder
@@ -51,7 +52,8 @@ def __on_window_close(self):
5152
self.toplevel.destroy()
5253

5354
def on_close_execute(self):
54-
"""Determine if if the application is ready for quit, return boolean."""
55+
"""Determine if if the application is ready for quit,
56+
return boolean."""
5557
return True
5658

5759
def quit(self):

pygubu/builder/__init__.py

+4-19
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
logging.basicConfig(level=logging.WARNING)
3838
logger = logging.getLogger('pygubu.builder')
3939

40-
#
41-
#
42-
#
40+
4341
def data_xmlnode_to_dict(element, translator=None):
4442
data = {}
4543

@@ -48,7 +46,7 @@ def data_xmlnode_to_dict(element, translator=None):
4846

4947
#properties
5048
properties = element.findall('./property')
51-
pdict= {}
49+
pdict = {}
5250
for p in properties:
5351
pvalue = p.text
5452
if translator is not None and p.get('translatable'):
@@ -149,7 +147,7 @@ def data_dict_to_xmlnode(data, translatable_props=None):
149147
pnode.set('name', prop)
150148
pnode.text = pv
151149
layout_node.append(pnode)
152-
keys = {'rows':'row', 'columns':'column'}
150+
keys = {'rows': 'row', 'columns': 'column'}
153151
for key in keys:
154152
if key in layout:
155153
erows = ET.Element(key)
@@ -193,12 +191,10 @@ def __init__(self, translator=None):
193191
self._resource_paths = []
194192
self.translator = translator
195193

196-
197194
def add_resource_path(self, path):
198195
"""Add additional path to the resources paths."""
199196
self._resource_paths.append(path)
200197

201-
202198
def get_image(self, path):
203199
"""Return tk image corresponding to name which is taken form path."""
204200
image = ''
@@ -213,7 +209,6 @@ def get_image(self, path):
213209
pass
214210
return image
215211

216-
217212
def __find_image(self, relpath):
218213
image_path = None
219214
for rp in self._resource_paths:
@@ -223,19 +218,17 @@ def __find_image(self, relpath):
223218
break
224219
return image_path
225220

226-
227221
def get_variable(self, varname):
228222
"""Return a tk variable created with 'create_variable' method."""
229223
return self.tkvariables[varname]
230224

231-
232225
def create_variable(self, varname, vtype=None):
233226
"""Create a tk variable.
234227
If the variable was created previously return that instance.
235228
"""
236229

237230
var = None
238-
type_from_name = 'string' #default type
231+
type_from_name = 'string' # default type
239232
if ':' in varname:
240233
type_from_name, varname = varname.split(':')
241234

@@ -259,7 +252,6 @@ def create_variable(self, varname, vtype=None):
259252
self.tkvariables[varname] = var
260253
return var
261254

262-
263255
def add_from_file(self, fpath):
264256
"""Load ui definition from file."""
265257
if self.tree is None:
@@ -272,7 +264,6 @@ def add_from_file(self, fpath):
272264
#TODO: append to current tree
273265
pass
274266

275-
276267
def add_from_string(self, strdata):
277268
"""Load ui definition from string."""
278269
if self.tree is None:
@@ -283,7 +274,6 @@ def add_from_string(self, strdata):
283274
#TODO: append to current tree
284275
pass
285276

286-
287277
def add_from_xmlnode(self, element):
288278
"""Load ui definition from xml.etree.Element node."""
289279
if self.tree is None:
@@ -297,7 +287,6 @@ def add_from_xmlnode(self, element):
297287
#TODO: append to current tree
298288
pass
299289

300-
301290
def get_object(self, name, master=None):
302291
"""Find and create the widget named name.
303292
Use master as parent. If widget was already created, return
@@ -317,14 +306,12 @@ def get_object(self, name, master=None):
317306
raise Exception('Widget not defined.')
318307
return widget
319308

320-
321309
def _import_class(self, modulename):
322310
if modulename.startswith('ttk.'):
323311
importlib.import_module('pygubu.builder.ttkstdwidgets')
324312
else:
325313
importlib.import_module(modulename)
326314

327-
328315
def _realize(self, master, element):
329316
"""Builds a widget from xml element using master as parent."""
330317

@@ -355,7 +342,6 @@ def _realize(self, master, element):
355342
else:
356343
raise Exception('Class "{0}" not mapped'.format(cname))
357344

358-
359345
def _check_data(self, data):
360346
cname = data['class']
361347
uniqueid = data['id']
@@ -365,7 +351,6 @@ def _check_data(self, data):
365351
logger.warning('No layout information for: (%s, %s).',
366352
cname, uniqueid)
367353

368-
369354
def connect_callbacks(self, callbacks_bag):
370355
"""Connect callbacks specified in callbacks_bag with callbacks
371356
defined in the ui definition.

pygubu/builder/tkstdwidgets.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import unicode_literals
2-
import types
32

43
try:
54
import tkinter as tk
@@ -8,9 +7,12 @@
87

98
from .builderobject import *
109

10+
1111
#
1212
# tkinter widgets
1313
#
14+
15+
1416
class TKToplevel(BuilderObject):
1517
class_ = tk.Toplevel
1618
container = True
@@ -31,7 +33,7 @@ class TKToplevel(BuilderObject):
3133
'vertically': (False, True),
3234
'none': (False, False)
3335
}
34-
36+
3537
def realize(self, parent):
3638
args = self._get_init_args()
3739
master = parent.get_child_master()
@@ -40,7 +42,7 @@ def realize(self, parent):
4042
else:
4143
self.widget = self.class_(master, **args)
4244
return self.widget
43-
45+
4446
def _set_property(self, target_widget, pname, value):
4547
method_props = ('geometry', 'overrideredirect', 'title')
4648
if pname in method_props:
@@ -63,7 +65,8 @@ def _set_property(self, target_widget, pname, value):
6365
else:
6466
super(TKToplevel, self)._set_property(target_widget, pname, value)
6567

66-
register_widget('tk.Toplevel', TKToplevel, 'Toplevel', ('Containers', 'tk', 'ttk'))
68+
register_widget('tk.Toplevel', TKToplevel,
69+
'Toplevel', ('Containers', 'tk', 'ttk'))
6770

6871

6972
class TKFrame(BuilderObject):
@@ -99,7 +102,8 @@ class TKLabelFrame(BuilderObject):
99102
'text', 'takefocus', 'width']
100103
#TODO: Add helper so the labelwidget can be configured on GUI
101104

102-
register_widget('tk.LabelFrame', TKLabelFrame, 'LabelFrame', ('Containers', 'tk'))
105+
register_widget('tk.LabelFrame', TKLabelFrame,
106+
'LabelFrame', ('Containers', 'tk'))
103107

104108

105109
class TKEntry(EntryBaseBO):
@@ -114,7 +118,7 @@ class TKEntry(EntryBaseBO):
114118
'selectborderwidth', 'selectforeground', 'show', 'state',
115119
'takefocus', 'textvariable', 'validate', 'validatecommand',
116120
'invalidcommand', 'width', 'wraplength', 'xscrollcommand',
117-
'text', # < text is a custom property
121+
'text', # < text is a custom property
118122
'validatecommand_args',
119123
'invalidcommand_args']
120124
command_properties = ('validatecommand', 'invalidcommand',
@@ -156,7 +160,7 @@ class TKCheckbutton(BuilderObject):
156160

157161

158162
class TKListbox(BuilderObject):
159-
class_ = tk.Listbox
163+
class_ = tk.Listbox
160164
container = False
161165
properties = ['activestyle', 'background', 'borderwidth', 'cursor',
162166
'disabledforeground', 'exportselection', 'font',
@@ -167,7 +171,8 @@ class TKListbox(BuilderObject):
167171
'yscrollcommand']
168172
command_properties = ('xscrollcommand', 'yscrollcommand')
169173

170-
register_widget('tk.Listbox', TKListbox, 'Listbox', ('Control & Display', 'tk'))
174+
register_widget('tk.Listbox', TKListbox,
175+
'Listbox', ('Control & Display', 'tk'))
171176

172177

173178
class TKText(BuilderObject):
@@ -182,20 +187,19 @@ class TKText(BuilderObject):
182187
'selectborderwidth', 'selectforeground', 'spacing1',
183188
'spacing2', 'spacing3', 'state', 'tabs', 'takefocus',
184189
'undo', 'width', 'wrap', 'xscrollcommand', 'yscrollcommand',
185-
'text'] #<- text is a custom property.
190+
'text'] # <- text is a custom property.
186191
command_properties = ('xscrollcommand', 'yscrollcommand')
187192

188193
def _set_property(self, target_widget, pname, value):
189194
if pname == 'text':
190195
target_widget.insert('0.0', value)
191196
else:
192-
super(TKText, self)._set_property(target_widget,pname, value)
197+
super(TKText, self)._set_property(target_widget, pname, value)
193198

194199

195200
register_widget('tk.Text', TKText, 'Text', ('Control & Display', 'tk', 'ttk'))
196201

197202

198-
199203
class TKPanedWindow(PanedWindow):
200204
class_ = tk.PanedWindow
201205
allowed_children = ('tk.PanedWindow.Pane',)
@@ -223,7 +227,8 @@ class TKMenubutton(BuilderObject):
223227
def add_child(self, bobject):
224228
self.widget.configure(menu=bobject.widget)
225229

226-
register_widget('tk.Menubutton', TKMenubutton, 'Menubutton', ('Control & Display', 'tk',))
230+
register_widget('tk.Menubutton', TKMenubutton,
231+
'Menubutton', ('Control & Display', 'tk',))
227232

228233

229234
class TKMessage(BuilderObject):
@@ -309,7 +314,8 @@ def configure(self):
309314
self.properties['to'] = str(to)
310315
super(TKSpinbox, self).configure()
311316

312-
register_widget('tk.Spinbox', TKSpinbox, 'Spinbox', ('Control & Display', 'tk'))
317+
register_widget('tk.Spinbox', TKSpinbox,
318+
'Spinbox', ('Control & Display', 'tk'))
313319

314320

315321
class TKMenu(BuilderObject):
@@ -362,7 +368,7 @@ class TKMenuitem(BuilderObject):
362368
'background', 'bitmap', 'columnbreak', 'command', 'compound',
363369
'font', 'foreground', 'hidemargin', 'image', 'label', 'state',
364370
'underline',
365-
'command_id_arg', #<< custom property !!
371+
'command_id_arg', # << custom property !!
366372
]
367373
command_properties = ('command',)
368374
allow_bindings = False
@@ -391,7 +397,6 @@ def configure(self):
391397
def layout(self):
392398
pass
393399

394-
395400
def _create_callback(self, cpname, callback):
396401
command = callback
397402
include_id = self.properties.get('command_id_arg', 'False')
@@ -425,7 +430,6 @@ def realize(self, parent):
425430
master.add(tk.CASCADE, **item_properties)
426431
return self.widget
427432

428-
429433
def configure(self):
430434
pass
431435

@@ -471,7 +475,7 @@ class TKMenuitemSeparator(TKMenuitem):
471475
command_properties = tuple()
472476

473477
register_widget('tk.Menuitem.Separator', TKMenuitemSeparator,
474-
'Menuitem.Separator', ('Pygubu Helpers','tk', 'ttk'))
478+
'Menuitem.Separator', ('Pygubu Helpers', 'tk', 'ttk'))
475479

476480

477481
class TKPanedWindowPane(PanedWindowPane):

0 commit comments

Comments
 (0)