Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorent <florent.pigout@gmail.com>2011-05-02 01:04:49 (GMT)
committer florent <florent.pigout@gmail.com>2011-05-02 01:04:49 (GMT)
commit808ca8f5f829adb740a686cd9bf727592202ce56 (patch)
tree0fc57ce392abebed94821025c4c1a267cbacc894
parenta1c0b53c5ba4e01a6e7d1e3d693305997dfe5295 (diff)
enhance graphic removal and remove sequence if empty [work in progress]
-rw-r--r--atoidejouer/story/keys.py4
-rw-r--r--atoidejouer/ui/notebook.py75
-rw-r--r--atoidejouer/ui/toolbar.py41
3 files changed, 104 insertions, 16 deletions
diff --git a/atoidejouer/story/keys.py b/atoidejouer/story/keys.py
index 6d09820..60fdd17 100644
--- a/atoidejouer/story/keys.py
+++ b/atoidejouer/story/keys.py
@@ -309,6 +309,10 @@ class StoryKeys(object):
else:
del self._keys[sequence_name][frame][filename]
+ def remove_filename_from_all(self, sequence_name, filename):
+ for _frame in range(self.get_max_frame()):
+ self.remove_filename(sequence_name, _frame, filename)
+
def set_align(self, sequence_name, frame, filename, align):
# .. get the dict
_f_dict = self.get_filename_dict(sequence_name, frame, filename)
diff --git a/atoidejouer/ui/notebook.py b/atoidejouer/ui/notebook.py
index 0b132c8..98fe9d5 100644
--- a/atoidejouer/ui/notebook.py
+++ b/atoidejouer/ui/notebook.py
@@ -38,7 +38,7 @@ def _cb_swicth_page(widget, page, page_num, notebook):
glib.idle_add(partial(_label.modify_fg, gtk.STATE_NORMAL, COLOR_WHITE))
-def _get_sequence_names(sequence_path):
+def _get_seq_filenames(sequence_path):
_f = open(sequence_path)
_seq_names = _f.readlines()
_f.close()
@@ -84,7 +84,7 @@ def _cb_cursor_changed(treeview, notebook, type_):
# get value
_sequence_path = _model.get_value(_iter, 2)
# update sequence ..
- for _g in _get_sequence_names(_sequence_path):
+ for _g in _get_seq_filenames(_sequence_path):
notebook.screen.sequence_preview.add_item(_g.strip())
# get sequence name
_sequence_name = _model.get_value(_iter, 1)
@@ -100,6 +100,48 @@ def _cb_cursor_changed(treeview, notebook, type_):
pass
+def _get_seq_filenames(sequence_path):
+ _f = open(sequence_path)
+ _seq_names = _f.readlines()
+ _f.close()
+ # ..
+ return [_n.strip() for _n in _seq_names]
+
+
+def __remove_filename_from_sequence(type_, sequence, filename):
+ # little check
+ if filename.strip() == '':
+ # do nothing
+ return True
+ else:
+ # get sequence path
+ _seq_path = storage.get_sequence_path(type_, sequence)
+ # get current names
+ _current_filenames = _get_seq_filenames(_seq_path)
+ # has remaining files
+ _remain = False
+ if filename in _current_filenames:
+ _current_filenames.remove(filename)
+ else:
+ return True
+ # ..
+ if len(_current_filenames) == 0:
+ # ..
+ os.remove(_seq_path)
+ # ..
+ return False
+ else:
+ # open file
+ _file = open(_seq_path, 'wb')
+ # update
+ for _fname in _current_filenames:
+ _file.write('%s\n' % _fname)
+ # ..
+ _file.close()
+ # ..
+ return True
+
+
def _on_button_click(button, notebook):
# get file path
if notebook._type == 'graphics':
@@ -111,10 +153,35 @@ def _on_button_click(button, notebook):
return
# remove file
os.remove(_path)
+ # shortcuts
+ _screen = notebook.screen
+ _toolbar = _screen.toolbar
+ _activity = _toolbar.activity
+ # ..
+ _keys = _activity.graphic_keys\
+ if _toolbar.name == 'graphics_add'\
+ else _activity.sound_keys
+ # ..
+ _type = 'graphics' if _toolbar.name == 'graphics_add' else 'sounds'
+ # get sequence names
+ for _seq_name in _keys._names:
+ # remove from file system
+ if __remove_filename_from_sequence(_type, _seq_name,
+ notebook.current_item) is True:
+ # remove from keys
+ _keys.remove_filename_from_all(_seq_name, notebook.current_item)
+ # remove the entire sequence
+ else:
+ # from keys
+ _keys.remove_sequence(_seq_name)
+ # ..
+ notebook._get_store_sequence()
+ # update edit screen
+ # _activity.remove_screen(_type)
# remove item in treview
notebook.remove_current_row()
- # get current sequence
- notebook.screen.sequence_preview.remove_item(notebook.current_item)
+ # remove current sequence
+ _screen.sequence_preview.remove_item(notebook.current_item)
# avoid current
notebook.current_item = None
diff --git a/atoidejouer/ui/toolbar.py b/atoidejouer/ui/toolbar.py
index 42a6efa..04efb49 100644
--- a/atoidejouer/ui/toolbar.py
+++ b/atoidejouer/ui/toolbar.py
@@ -78,10 +78,8 @@ def _cb_seq_remove(widget, toolbar):
# do nothing
pass
else:
- # prepare sequence path
- _name = _name.replace(' ', '_')
# get sequence path
- _seq_path = storage.get_sequence_path(_type, _name.lower())
+ _seq_path = storage.get_sequence_path(_type, _name)
# remove dir
if os.path.exists(_seq_path):
# do clean
@@ -114,16 +112,26 @@ def _cb_seq_save(widget, toolbar):
# do nothing
pass
else:
- # prepare sequence path
- _name = _name.replace(' ', '_')
# get sequence path
- _seq_path = storage.get_sequence_path(_type, _name.lower())
- # open file
- _file = open(_seq_path, 'wb')
- # TODO - copy files
- for _filename in _screen.sequence_preview.items:
- _file.write('%s\n' % _filename)
- _file.close()
+ _seq_path = storage.get_sequence_path(_type, _name)
+ # shortcut
+ _items = _screen.sequence_preview.items
+ if len(_items) == 0:
+ # remove from files
+ os.remove(_seq_path)
+ # ..
+ _keys = toolbar.activity.graphic_keys\
+ if toolbar.name == 'graphics_add'\
+ else toolbar.activity.sound_keys
+ # remove from keys
+ _keys.remove_sequence(_name)
+ else:
+ # open file
+ _file = open(_seq_path, 'wb')
+ # update
+ for _filename in _items:
+ _file.write('%s\n' % _filename)
+ _file.close()
# update notebook
_screen.notebook._get_store_sequence()
@@ -189,6 +197,15 @@ def _cb_remove(widget, toolbar):
_screen = toolbar.activity.get_current_screen()
# udpate sequence preview
_screen.sequence_preview.remove_current()
+ # seq name
+ _seq_name = _screen.notebook.current_sequence
+ # ..
+ _keys = toolbar.activity.graphic_keys\
+ if toolbar.name == 'graphics_add'\
+ else toolbar.activity.sound_keys
+ # remove from keys
+ _keys.remove_filename_from_all(_seq_name,
+ _screen.sequence_preview._current)
# update sequence file
_cb_seq_save(widget, toolbar)
# ..