Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorent Pigout <florent.pigout@gmail.com>2011-09-22 00:07:10 (GMT)
committer Florent Pigout <florent.pigout@gmail.com>2011-09-22 00:07:10 (GMT)
commit8c14cc8fc665823e6c14ddccdcfcfe2f46916721 (patch)
treef6c9351eee9ff1c2a1f90f6a838453a78fe3ed2e
parenta44222e5f0bbf4ecfba1bc97fef67d7bc31771b5 (diff)
ensure current sequence focus when creating or removing one then item add becomes implicit
-rw-r--r--atoidejouer/tools/storage.py27
-rw-r--r--atoidejouer/ui/notebook.py53
-rw-r--r--atoidejouer/ui/toolbar.py9
3 files changed, 65 insertions, 24 deletions
diff --git a/atoidejouer/tools/storage.py b/atoidejouer/tools/storage.py
index e96327c..6db569e 100644
--- a/atoidejouer/tools/storage.py
+++ b/atoidejouer/tools/storage.py
@@ -34,6 +34,33 @@ def get_config_path():
return os.path.join(_bundle_path, 'static', 'data', 'config', 'config.ini')
+def list_sequence_names(type_):
+ # init result
+ _names = list()
+ # prepare dir path
+ _seq_dir = os.path.join(activity.get_activity_root(), 'data',
+ 'sequences', type_)
+ # ..
+ for _filename in os.listdir(_seq_dir):
+ # ..
+ _path = os.path.join(_seq_dir, _filename)
+ # little check
+ if os.path.isfile(_path):
+ # check name
+ try:
+ _n, _ext = os.path.splitext(_filename)
+ # check ext
+ if _ext == '.seq':
+ _names.append((_n, _path))
+ else:
+ continue
+ except Exception, e:
+ # TODO log something
+ continue
+ # ..
+ return _names
+
+
def get_sequence_items(sequence_path):
if os.path.exists(sequence_path):
_f = open(sequence_path)
diff --git a/atoidejouer/ui/notebook.py b/atoidejouer/ui/notebook.py
index 5f47872..7f80670 100644
--- a/atoidejouer/ui/notebook.py
+++ b/atoidejouer/ui/notebook.py
@@ -220,6 +220,7 @@ class ResourceNotebook(gtk.Frame):
self.current_sequence = None
# ..
self.library_treeview = None
+ self.sequence_treeview = None
# keep stores
self._store_sequence = None
self._store_graphic = None
@@ -256,6 +257,25 @@ class ResourceNotebook(gtk.Frame):
# return it
return _button, _label
+ def focus_current_seq(self, name=None):
+ # get seq names
+ _seq_names = [_n for _n, _p in storage.list_sequence_names(self._type)]
+ _seq_names.sort()
+ # ..
+ self.current_sequence = name\
+ if len(_seq_names) == 0 or name is not None\
+ else _seq_names[0]
+ if len(_seq_names) == 0:
+ return
+ else:
+ # ..
+ _index = 0 if self.current_sequence is None\
+ or self.current_sequence not in _seq_names\
+ else _seq_names.index(self.current_sequence)
+ # get the current cursor and path
+ self.sequence_treeview.set_cursor(_index)
+
+
def remove_current_row(self):
# get the current cursor and path
_path, _column = self.library_treeview.get_cursor()
@@ -292,31 +312,14 @@ class ResourceNotebook(gtk.Frame):
)
else:
self._store_sequence.clear()
- # prepare dir path
- _seq_dir = os.path.join(activity.get_activity_root(), 'data',
- 'sequences', self._type)
+ # liste seq names
+ _seq_names = storage.list_sequence_names(self._type)
# ..
- for _filename in os.listdir(_seq_dir):
- # ..
- _path = os.path.join(_seq_dir, _filename)
- # little check
- if os.path.isfile(_path):
- # check name
- try:
- _filename, _ext = os.path.splitext(_filename)
- # check ext
- if _ext == '.seq':
- pass
- else:
- continue
- except Exception, e:
- # TODO log something
- continue
- # ...
- _pixbuf = image.get_sequence_first_graphic(self._type,
- _filename)
- # do update
- self._store_sequence.append([_pixbuf, _filename, _path])
+ for _name, _path in _seq_names:
+ # ...
+ _pixbuf = image.get_sequence_first_graphic(self._type, _name)
+ # do update
+ self._store_sequence.append([_pixbuf, _name, _path])
# return the store
return self._store_sequence
@@ -524,6 +527,8 @@ class ResourceNotebook(gtk.Frame):
def _get_notebook(self):
# get list 1
_list1 = self._get_treeview(type_='sequence')
+ # keep sequence treeview
+ self.sequence_treeview = _list1.get_children()[0]
# create a label for the button
_label1 = gtk.Label(_('Sequences'))
# ...
diff --git a/atoidejouer/ui/toolbar.py b/atoidejouer/ui/toolbar.py
index 1d0aa72..140565a 100644
--- a/atoidejouer/ui/toolbar.py
+++ b/atoidejouer/ui/toolbar.py
@@ -90,6 +90,8 @@ def _cb_seq_remove(widget, toolbar):
toolbar._sequence_entry.set_text("")
# update notebook
_screen.notebook._get_store_sequence()
+ # update focus
+ _screen.notebook.focus_current_seq()
# nothing to do
else:
pass
@@ -97,6 +99,13 @@ def _cb_seq_remove(widget, toolbar):
def _cb_seq_save(widget, toolbar, remove=False):
storage.sequence_save(toolbar, remove=remove)
+ # get screen
+ _screen = toolbar.activity.get_current_screen()
+ # get sequence name
+ _name = toolbar._sequence_entry.get_text()
+ # update focus
+ _screen.notebook.focus_current_seq(name=_name)
+
def _show_browser(toolbar, cls):