Skip to content

Commit

Permalink
#665 use enumerate() construct to simplify code
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@7484 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 29, 2014
1 parent 736dc59 commit 99b6bb7
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 50 deletions.
4 changes: 1 addition & 3 deletions src/xpra/client/gtk_base/client_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ def validate_in_list(x, options):


def get_active_item_index(optionmenu):
i = 0
menu = optionmenu.get_menu()
for x in menu.get_children():
for i, x in enumerate(menu.get_children()):
if hasattr(x, "get_active") and x.get_active():
return i
i += 1
return -1

def set_history_from_active(optionmenu):
Expand Down
4 changes: 1 addition & 3 deletions src/xpra/client/gtk_base/gtk_tray_menu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def populate_encodingsmenu(encodings_submenu, get_current_encoding, set_encoding
encodings_submenu.index_to_encoding = {}
encodings_submenu.encoding_to_index = {}
NAME_TO_ENCODING = {}
i = 0
for encoding in encodings:
for i, encoding in enumerate(encodings):
name = ENCODINGS_TO_NAME.get(encoding, encoding)
descr = ENCODINGS_HELP.get(encoding)
NAME_TO_ENCODING[name] = encoding
Expand All @@ -173,7 +172,6 @@ def encoding_changed(oitem):
encodings_submenu.append(encoding_item)
encodings_submenu.index_to_encoding[i] = encoding
encodings_submenu.encoding_to_index[encoding] = i
i += 1
encodings_submenu.show_all()


Expand Down
8 changes: 2 additions & 6 deletions src/xpra/gtk_common/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ def make_graph_pixmap(data, labels=None, width=320, height=200, title=None,
context.set_line_width(0.0)
context.rectangle(x_offset, y_offset, x_offset+w, y_offset+h)
context.clip()
i = 0
context.set_line_width(1.5)
for line_data in data:
for i, line_data in enumerate(data):
colour = colours[i % len(colours)]
context.set_source_rgb(*colour)
j = 0
Expand Down Expand Up @@ -163,10 +162,8 @@ def make_graph_pixmap(data, labels=None, width=320, height=200, title=None,
last_v = v, x, y
j += 1
context.stroke()
i += 1
context.restore()
i = 0
for line_data in data:
for i, line_data in enumerate(data):
#show label:
if labels and len(labels)>i:
label = labels[i]
Expand All @@ -177,5 +174,4 @@ def make_graph_pixmap(data, labels=None, width=320, height=200, title=None,
context.move_to(x_offset/2+(width-x_offset)*i/len(labels), height-4)
context.show_text(label)
context.stroke()
i += 1
return pixmap
4 changes: 1 addition & 3 deletions src/xpra/net/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,8 @@ def new_tree(append):
if packet is None:
return err("None value")
if type(packet)==list:
i = 0
for x in packet:
for i, x in enumerate(packet):
self.do_verify_packet(new_tree("[%s]" % i), x)
i += 1
elif type(packet)==dict:
for k,v in packet.items():
self.do_verify_packet(new_tree("key for value='%s'" % str(v)), k)
Expand Down
4 changes: 1 addition & 3 deletions src/xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,12 @@ def get_info(self):
info = {"children" : len(d),
"children.dead" : len(self._dead_pids),
"children.ignored" : len(self._ignored_pids)}
i = 0
for pid in sorted(d.keys()):
for i, pid in enumerate(sorted(d.keys())):
proc = d[pid]
info["child[%i].live" % i] = pid not in self._dead_pids
info["child[%i].pid" % i] = pid
info["child[%i].command" % i] = proc.command
info["child[%i].ignored" % i] = pid in self._ignored_pids
i += 1
return info


Expand Down
4 changes: 1 addition & 3 deletions src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,15 +1121,13 @@ def up(prefix, d, suffix=""):
up("client", ss.get_info())
info.update(ss.get_window_info(window_ids))
elif n>1:
i = 0
for ss in server_sources:
for i, ss in enumerate(server_sources):
up("client[%i]" % i, ss.get_info())
wi = ss.get_window_info(window_ids)
up("client[%i]" % i, wi)
#this means that the last source overrides previous ones
#(bad decision was made on the namespace for this..)
info.update(wi)
i += 1
return info

def add_windows_info(self, info, window_ids):
Expand Down
11 changes: 3 additions & 8 deletions src/xpra/server/server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ def get_thread_info(proto=None):
"count" : threading.active_count() - len(info_threads),
"info.count" : len(info_threads)
}
i = 0
#threads used by the "info" client:
for t in info_threads:
for i, t in enumerate(info_threads):
info["info[%s]" % i] = t.getName()
i += 1
i = 0
#all non-info threads:
for t in threading.enumerate():
if t not in info_threads:
info[str(i)] = t.getName()
i += 1
for i, t in enumerate((x for x in threading.enumerate() if x not in info_threads)):
info[str(i)] = t.getName()
#platform specific bits:
try:
from xpra.platform.info import get_sys_info
Expand Down
4 changes: 1 addition & 3 deletions src/xpra/server/video_subregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def get_info(self):
"non_max_wait" : self.non_max_wait}
rr = list(self.refresh_regions)
if rr:
i = 0
for r in rr:
for i, r in enumerate(rr):
info["refresh_region[%s]" % i] = (r.x, r.y, r.width, r.height)
i += 1
return info


Expand Down
4 changes: 1 addition & 3 deletions src/xpra/server/window_video_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ def up(prefix, d):
up("encoding.pipeline_param", self.get_pipeline_info())
lps = self.last_pipeline_scores
if lps:
i = 0
for lp in lps:
for i, lp in enumerate(lps):
up("encoding.pipeline_option[%s]" % i, self.get_pipeline_score_info(*lp))
i += 1
return info

def get_pipeline_info(self):
Expand Down
12 changes: 3 additions & 9 deletions src/xpra/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ def do_log_screen_sizes(root_w, root_h, sizes):
#log position if not (0, 0)
info.append("at %sx%s" % (work_x, work_y))
log.info(" "+" ".join(info))
i = 0
for m in monitors:
i += 1
for i, m in enumerate(monitors, start=1):
if len(m)<7:
log.info(" %s", m)
continue
Expand All @@ -284,8 +282,7 @@ def get_screen_info(screen_sizes):
info = {
"screens" : len(screen_sizes)
}
i = 0
for x in screen_sizes:
for i, x in enumerate(screen_sizes):
if type(x) not in (tuple, list):
#legacy clients:
info["screen[%s]" % i] = str(x)
Expand All @@ -297,19 +294,16 @@ def get_screen_info(screen_sizes):
info["screen[%s].size_mm" % i] = x[3], x[4]
if len(x)>=6:
monitors = x[5]
j = 0
for monitor in monitors:
for j, monitor in enumerate(monitors):
if len(monitor)>=7:
for k,v in {
"name" : monitor[0],
"geometry" : monitor[1:5],
"size_mm" : monitor[5:7],
}.items():
info["screen[%s].monitor[%s].%s" % (i, j, k)] = v
j += 1
if len(x)>=10:
info["screen[%s].workarea" % i] = x[6:10]
i += 1
return info


Expand Down
4 changes: 1 addition & 3 deletions src/xpra/x11/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,10 @@ def do_get_info(self, proto, server_sources, window_ids):
else:
info["cursor.is_default"] = bool(self.default_cursor_data and len(self.default_cursor_data)>=8 and len(cd)>=8 and cd[7]==cd[7])
#all but pixels:
i = 0
for x in ("x", "y", "width", "height", "xhot", "yhot", "serial", None, "name"):
for i, x in enumerate(("x", "y", "width", "height", "xhot", "yhot", "serial", None, "name")):
if x:
v = cd[i] or ""
info["cursor." + x] = v
i += 1
return info

def get_ui_info(self, proto, wids, *args):
Expand Down
4 changes: 1 addition & 3 deletions src/xpra/x11/x11_server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,13 @@ def delfile(msg):
"%s" % len(monitors)]
#the new config (numeric values only)
config = [len(monitors)]
i = 0
for m in monitors:
for i, m in enumerate(monitors):
if len(m)<7:
return delfile("cannot save fake xinerama settings: incomplete monitor data for monitor: %s" % m)
plug_name, x, y, width, height, wmm, hmm = m[:8]
data.append("# %s (%smm x %smm)" % (prettify_plug_name(plug_name, "monitor %s" % i), wmm, hmm))
data.append("%s %s %s %s" % (x, y, width, height))
config.append((x, y, width, height))
i += 1
data.append("")
contents = "\n".join(data)
for filename in xinerama_files:
Expand Down

0 comments on commit 99b6bb7

Please sign in to comment.