From c89bc07e0bc57b73fbb099e7e458b41ecb739cc9 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 7 May 2007 00:18:42 -0400 Subject: [PATCH 1/6] Fix nickname encoding and length issues --- shell/intro/intro.py | 4 +++- sugar/profile.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shell/intro/intro.py b/shell/intro/intro.py index 38c0a7be..2ae097de 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -185,6 +185,7 @@ class EntryBox(hippo.CanvasBox, hippo.CanvasItem): self.append(self._label) self._entry = gtk.Entry() + self._entry.set_max_length(45) entry_item = hippo.CanvasWidget(widget=self._entry) self.append(entry_item) @@ -297,7 +298,8 @@ class IntroWindow(gtk.Window): section = 'Buddy' if not cp.has_section(section): cp.add_section(section) - cp.set(section, 'NickName', name) + # encode nickname to ascii-safe characters + cp.set(section, 'NickName', name.encode("utf-8")) cp.set(section, 'Color', color.to_string()) section = 'Server' diff --git a/sugar/profile.py b/sugar/profile.py index 840e101c..8041a4e1 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -66,7 +66,9 @@ class _Profile(object): parsed = cp.read([config_path]) if cp.has_option('Buddy', 'NickName'): - self.name = cp.get('Buddy', 'NickName') + name = cp.get('Buddy', 'NickName') + # decode nickname from ascii-safe chars to unicode + self.name = name.decode("utf-8") if cp.has_option('Buddy', 'Color'): self.color = XoColor(cp.get('Buddy', 'Color')) From fb019bc9f5a93231d9dc63a2f323db6881a048a3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 7 May 2007 16:24:41 +0200 Subject: [PATCH 2/6] Better spread algorhytm, work in progress --- sugar/graphics/spreadbox.py | 131 ++++++++++++++++++++++++++---------- tests/test-notebook.py | 0 tests/test-snowflake-box.py | 4 ++ 3 files changed, 98 insertions(+), 37 deletions(-) mode change 100644 => 100755 tests/test-notebook.py diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py index ff50f71e..f4cf5ea9 100644 --- a/sugar/graphics/spreadbox.py +++ b/sugar/graphics/spreadbox.py @@ -15,67 +15,124 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import random +from array import array +from random import random import hippo -import gtk -from sugar.graphics import units +_X_TILES = 120 +_NUM_TRIALS = 100 -_WIDTH = gtk.gdk.screen_width() -_HEIGHT = gtk.gdk.screen_height() -_CELL_WIDTH = units.grid_to_pixels(1) -_CELL_HEIGHT = units.grid_to_pixels(1) -_GRID_WIDTH = _WIDTH / _CELL_WIDTH -_GRID_HEIGHT = _HEIGHT / _CELL_HEIGHT +class _Grid(object): + def __init__(self, x_tiles, y_tiles, cell_size): + self._array = array('B') + self.x_tiles = x_tiles + self.y_tiles = y_tiles + self.cell_size = cell_size + + for i in range(self.y_tiles * self.x_tiles): + self._array.append(0) + + def __getitem__(self, (row, col)): + return self._array[col + row * self.x_tiles] + + def __setitem__(self, (row, col), value): + self._array[col + row * self.x_tiles] = value + + def compute_weight_at(self, x, y, width, height): + weight = 0 + + for i in range(x, x + width): + for j in range(y, y + height): + weight += self[j, i] + + return weight + + def add_weight_at(self, x, y, width, height): + for i in range(x, x + width): + for j in range(y, y + height): + self[j, i] += 1 + + def remove_weight_at(self, x, y, width, height): + for i in range(x, x + width): + for j in range(y, y + height): + self[j, i] -= 1 class SpreadBox(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarSpreadBox' def __init__(self, **kwargs): hippo.CanvasBox.__init__(self, **kwargs) - self._grid = [] + self._grid = None self._center = None - - for i in range(0, _GRID_WIDTH * _GRID_HEIGHT): - self._grid.append(None) + self._width = -1 + self._height = -1 def set_center_item(self, item): if self._center: self.remove(self._center) - self._center = item self.append(item, hippo.PACK_FIXED) + self._center = item + + self._layout_center() def add_item(self, item): - start_pos = int(random.random() * len(self._grid)) - - pos = start_pos - while self._grid[pos] != None: - pos = pos + 1 - if pos == len(self._grid): - pos = 0 - elif pos == start_pos: - break - - self._grid[pos] = item - self.append(item, hippo.PACK_FIXED) - - cell_y = int(pos / _GRID_WIDTH) - cell_x = pos - cell_y * _GRID_WIDTH - self.set_position(item, cell_x * _CELL_WIDTH, cell_y * _CELL_HEIGHT) + self._layout_item(item) def remove_item(self, item): - for i in range(0, len(self._grid)): - if self._grid[i] == item: - self._grid[i] = None self.remove(item) + + def _layout_item(self, item): + if not self._grid: + return + + trials = _NUM_TRIALS + placed = False + + while trials > 0 and not placed: + [width, height] = item.get_allocation() + cell_size = self._grid.cell_size + + w = int(width / cell_size) + h = int(height / cell_size) + x = int(random() * (self._grid.x_tiles - w)) + y = int(random() * (self._grid.y_tiles - h)) + + weight = self._grid.compute_weight_at(x, y, w, h) + if weight == 0: + self._grid.add_weight_at(x, y, w, h) + self.set_position(item, cell_size * x, cell_size * y) + placed = True + + trials -= 1 + + def _layout(self): + for item in self.get_children(): + if item != self._center: + self._layout_item(item) + + def _layout_center(self): + if not self._center or not self._grid: + return + [width, height] = self._center.get_allocation() + x = (self._width - width) / 2 + y = (self._height - height) / 2 + self.set_position(self._center, x, y) + def do_allocate(self, width, height, origin_changed): hippo.CanvasBox.do_allocate(self, width, height, origin_changed) - if self._center: - [icon_width, icon_height] = self._center.get_allocation() - self.set_position(self._center, (width - icon_width) / 2, - (height - icon_height) / 2) + if width != self._width or height != self._height: + cell_size = width / _X_TILES + y_tiles = height / cell_size + + self._grid = _Grid(_X_TILES, y_tiles, cell_size) + self._width = width + self._height = height + + self._layout() + + self._layout_center() diff --git a/tests/test-notebook.py b/tests/test-notebook.py old mode 100644 new mode 100755 diff --git a/tests/test-snowflake-box.py b/tests/test-snowflake-box.py index 4164af4f..eb7efb90 100755 --- a/tests/test-snowflake-box.py +++ b/tests/test-snowflake-box.py @@ -54,6 +54,10 @@ canvas = hippo.Canvas() root_box = SpreadBox(background_color=0xe2e2e2ff) canvas.set_root(root_box) +box = SnowflakeBox() +snow_flake = _create_snowflake(box, 0) +root_box.set_center_item(box) + box = SnowflakeBox() snow_flake = _create_snowflake(box, 30) root_box.add_item(box) From 6d5bc75092b0b68042c943cef694fea7999722ea Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 7 May 2007 16:59:28 +0200 Subject: [PATCH 3/6] Tweak the test to use realistic numbers. Some fixes --- sugar/graphics/spreadbox.py | 29 +++++++++++++++++++++-------- tests/test-snowflake-box.py | 29 +++++++---------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py index f4cf5ea9..8614cf6a 100644 --- a/sugar/graphics/spreadbox.py +++ b/sugar/graphics/spreadbox.py @@ -21,7 +21,8 @@ from random import random import hippo _X_TILES = 120 -_NUM_TRIALS = 100 +_NUM_TRIALS = 20 +_MAX_WEIGHT = 255 class _Grid(object): def __init__(self, x_tiles, y_tiles, cell_size): @@ -84,29 +85,41 @@ class SpreadBox(hippo.CanvasBox, hippo.CanvasItem): def remove_item(self, item): self.remove(item) + + def _place_item(self, item, x, y, w, h): + self._grid.add_weight_at(x, y, w, h) + self.set_position(item, + self._grid.cell_size * x, + self._grid.cell_size * y) + def _layout_item(self, item): if not self._grid: return trials = _NUM_TRIALS placed = False + best_weight = _MAX_WEIGHT + + [width, height] = item.get_allocation() + w = int(width / self._grid.cell_size) + h = int(height / self._grid.cell_size) while trials > 0 and not placed: - [width, height] = item.get_allocation() - cell_size = self._grid.cell_size - - w = int(width / cell_size) - h = int(height / cell_size) x = int(random() * (self._grid.x_tiles - w)) y = int(random() * (self._grid.y_tiles - h)) weight = self._grid.compute_weight_at(x, y, w, h) if weight == 0: - self._grid.add_weight_at(x, y, w, h) - self.set_position(item, cell_size * x, cell_size * y) + self._place_item(item, x, y, w, h) placed = True + elif weight < best_weight: + best_x = x + best_y = y trials -= 1 + + if not placed: + self._place_item(item, best_x, best_y, w, h) def _layout(self): for item in self.get_children(): diff --git a/tests/test-snowflake-box.py b/tests/test-snowflake-box.py index eb7efb90..45f3c0ac 100755 --- a/tests/test-snowflake-box.py +++ b/tests/test-snowflake-box.py @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys -import random +from random import random import pygtk pygtk.require('2.0') @@ -33,14 +33,14 @@ from sugar.graphics.canvasicon import CanvasIcon def _create_snowflake(parent, children): color = XoColor() - icon = CanvasIcon(scale=1.0, xo_color=color, + icon = CanvasIcon(scale=0.8, xo_color=color, icon_name='theme:object-link') parent.append(icon, hippo.PACK_FIXED) parent.set_root(icon) for i in range(0, children): color = XoColor() - icon = CanvasIcon(scale=0.5, xo_color=color, + icon = CanvasIcon(scale=0.4, xo_color=color, icon_name='theme:stock-buddy') parent.append(icon, hippo.PACK_FIXED) @@ -58,25 +58,10 @@ box = SnowflakeBox() snow_flake = _create_snowflake(box, 0) root_box.set_center_item(box) -box = SnowflakeBox() -snow_flake = _create_snowflake(box, 30) -root_box.add_item(box) - -box = SnowflakeBox() -snow_flake = _create_snowflake(box, 15) -root_box.add_item(box) - -box = SnowflakeBox() -snow_flake = _create_snowflake(box, 10) -root_box.add_item(box) - -box = SnowflakeBox() -snow_flake = _create_snowflake(box, 5) -root_box.add_item(box) - -box = SnowflakeBox() -snow_flake = _create_snowflake(box, 2) -root_box.add_item(box) +for i in range(0, 30): + box = SnowflakeBox() + snow_flake = _create_snowflake(box, int(2 + random() * 8)) + root_box.add_item(box) canvas.show() window.add(canvas) From 888e44e1514c7a1b3b320b4b0025d49e7017c811 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 7 May 2007 17:59:23 +0200 Subject: [PATCH 4/6] set gabble and SE log file variables --- sugar-emulator | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sugar-emulator b/sugar-emulator index dbbaab9e..912aa679 100755 --- a/sugar-emulator +++ b/sugar-emulator @@ -29,6 +29,8 @@ pygtk.require('2.0') import gtk import gobject +from sugar import env + def _get_display_number(): """Find a free display number trying to connect to 6000+ ports""" log.info( "Attempting to find free port for X11 (Xephyr)" ) @@ -104,6 +106,9 @@ def _setup_env(): os.environ['PYTHONPATH'] = source_dir + ':' + path log.info( 'Set PYTHONPATH=%s', os.environ['PYTHONPATH'] ) + os.environ['GABBLE_LOGFILE'] = os.path.join(env.get_profile_path(), 'logs', 'telepathy-gabble.log') + os.environ['STREAM_ENGINE_LOGFILE'] = os.path.join(env.get_profile_path(), 'logs', 'telepathy-stream-engine.log') + def main(): """Script-level operations""" logging.basicConfig() From d5980979940eac816663fdb2a263e19c316b6c4b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 7 May 2007 14:18:20 -0400 Subject: [PATCH 5/6] Fix retrieval of owner's object path --- services/presence/presenceservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/presence/presenceservice.py b/services/presence/presenceservice.py index 46ac1a28..7f1df8f4 100644 --- a/services/presence/presenceservice.py +++ b/services/presence/presenceservice.py @@ -306,7 +306,7 @@ class PresenceService(DBusGObject): if not self._owner: raise NotFoundError("The owner was not found.") else: - return self._owner.get_object_path() + return self._owner.object_path() @dbus.service.method(_PRESENCE_INTERFACE, in_signature="sssa{sv}", out_signature="o", async_callbacks=('async_cb', 'async_err_cb')) From 60d6dcd6188695add3c7b620c2a3eb61092fcf0a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 8 May 2007 11:49:52 +0100 Subject: [PATCH 6/6] sugar/logger.py: interpolate %x parameters in messages from the logging framework --- sugar/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sugar/logger.py b/sugar/logger.py index 87a9c96c..5cd3d727 100644 --- a/sugar/logger.py +++ b/sugar/logger.py @@ -38,7 +38,7 @@ class LogWriter: self._log_file = open(log_path, 'w') def write_record(self, record): - self.write(record.levelno, record.msg) + self.write(record.levelno, record.getMessage()) def write(self, level, msg): if level == logging.ERROR: