Zim

Merge lp:~oliver-joos/zim/quick_fixes into lp:~jaap.karssenberg/zim/pyzim

Proposed by Oliver Joos
Status: Merged
Merged at revision: 397
Proposed branch: lp:~oliver-joos/zim/quick_fixes
Merge into: lp:~jaap.karssenberg/zim/pyzim
Diff against target: 120 lines (+24/-7)
4 files modified
zim/config.py (+6/-1)
zim/gui/__init__.py (+7/-3)
zim/gui/searchdialog.py (+1/-1)
zim/gui/widgets.py (+10/-2)
To merge this branch: bzr merge lp:~oliver-joos/zim/quick_fixes
Reviewer Review Type Date Requested Status
Jaap Karssenberg Needs Fixing
Review via email: mp+60218@code.launchpad.net

Description of the change

Rev 394 of my quick_fixes branch fixes bug 587541 and bug 778542 of zim 0.52 (rev 391). So far I tested this branch sucessfully in Ubuntu 10.04.

To post a comment you must log in.
lp:~oliver-joos/zim/quick_fixes updated
395. By Oliver Joos

Show also image filetypes like *.ico in InsertImageDialog

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Afraid I can not merge it as-is

1/ the dialogs positions are stored in a global parameter, this is a major break of object-oriented programming, should stored as a object attribute in the interface object

2/ the filter for "image/*" needs explanation - in general this is used for dialogs selecting an image in the gtk interface, as the add_pixbuf_formats already adds all supported image formats all this will do is show images that are not supported in the dialog

review: Needs Fixing
lp:~oliver-joos/zim/quick_fixes updated
396. By Oliver Joos

Revised implementation to remember dialog positions

Revision history for this message
Oliver Joos (oliver-joos) wrote :

No problem, I am glad about more eyes looking into this.

1/ Well, the positions are all stored in ONE SINGLETON dict that maps dialog class names to tuples (x, y). I don't see a problem with a global parameter here (testing? multiple zims running?). But I agree that it is not good OO-style. So I reimplemented it using a true Singleton class and added some helpful comments (see rev 396).

2/ My initial problem was a Zim page with some favicon examples. These .ico images are rendered correctly even in Linux, but are hidden by default in the InsertImageDialog. Zims rendering subsystem seems more capable than add_pixbuf_formats pretends! I did not find any reports on GTKs bugzilla (.gnome.org) about this. Anyway I fear it would take >1 year for a fix of add_pixbuf_formats to make it into distros like Ubuntu. So I simply added a fix into Zims wrapper function.
The AttachFileDialog at the end of zim/__init__.py uses a hard-coded list (IMAGE_EXTENSIONS in fs.py) to decide if a file is an image. Instead of add_mime_type('image/*') I could add a filter for each entry in IMAGE_EXTENSIONS, or at least for '.ico', but I prefer my current solution. What do you think?

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

On Tue, May 10, 2011 at 11:06 AM, Oliver Joos <email address hidden>wrote:

> No problem, I am glad about more eyes looking into this.
>
> 1/ Well, the positions are all stored in ONE SINGLETON dict that maps
> dialog class names to tuples (x, y). I don't see a problem with a global
> parameter here (testing? multiple zims running?). But I agree that it is not
> good OO-style. So I reimplemented it using a true Singleton class and added
> some helpful comments (see rev 396).
>

I'm sorry, but my problem was not the use of global as a construct to create
a singleton, but with the usage of a singleton in the first place. We use
singletons in a few places in the code, but only for things that are really
a shared resource (like the filesystem). In this case it is just an
interface setting, so the main ui object should store at as an instance
attribute. Not that using a singleton will immediately break the
application, but I just like to keep the design clean and consistent where
possible.

One option is to just add it in uistate but somehow allow flagging this
setting as something to be ignored when saving. Maybe just prefixing with an
"_" like "_windowpos" and modifying zim.config to ignore any attributes that
have a "_" prefix ?

Or maybe add a config dict in parallel to uistate which is not stored to a
config file for such settings that you want consistent over one instance of
zim only.

First option is most elegant to me, as it will allow you to have "private"
uistate parameters that are not carried over to the next instance, but they
go in the same place as all other ui state parameters, where it conceptually
belongs.

> 2/ My initial problem was a Zim page with some favicon examples. These .ico
> images are rendered correctly even in Linux, but are hidden by default in
> the InsertImageDialog. Zims rendering subsystem seems more capable than
> add_pixbuf_formats pretends! I did not find any reports on GTKs bugzilla (.
> gnome.org) about this. Anyway I fear it would take >1 year for a fix of
> add_pixbuf_formats to make it into distros like Ubuntu. So I simply added a
> fix into Zims wrapper function.
> The AttachFileDialog at the end of zim/__init__.py uses a hard-coded list
> (IMAGE_EXTENSIONS in fs.py) to decide if a file is an image. Instead of
> add_mime_type('image/*') I could add a filter for each entry in
> IMAGE_EXTENSIONS, or at least for '.ico', but I prefer my current solution.
> What do you think?
>

I would expect the add_pixbuf_types to map 1 to 1 with the rendering
backends that are available - this is the whole purpose of that routine, but
if this is not the case we can indeed just go for "image/*".

-- Jaap

lp:~oliver-joos/zim/quick_fixes updated
397. By Oliver Joos

Copy modification dates of images and attachments

398. By Oliver Joos

Even better solution to remember dialog positions

Revision history for this message
Oliver Joos (oliver-joos) wrote :

1/ Ah, now I got you right, and I like your idea of non-persistent uistate values by using names starting with '_'! I pushed another rev and indeed it fits much better than my previous attempts.
See http://bazaar.launchpad.net/~oliver-joos/zim/quick_fixes/revision/398

2/ Yes, I'd also expect add_pixbuf_types to match .ico, but in my uptodate Ubuntu 10.04, it does not.

Revision history for this message
Oliver Joos (oliver-joos) wrote :

@Jaap: Thanks for merging my branch!
I appreciate your small change (0,0)->(None,None) of my fix of bug 587541. And your fix copy->copy2 of bug 780184 is ok for me too. I did not dare to fix this in fs.py because this module is so central.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'zim/config.py'
2--- zim/config.py 2011-04-14 17:41:49 +0000
3+++ zim/config.py 2011-05-10 13:26:28 +0000
4@@ -485,6 +485,9 @@
5 As a special case we can support sections that repeat under the
6 same section name. To do this assign the section name a list
7 before parsing.
8+
9+ Values with keys starting with '_' are considered as non-persistent and are
10+ only stored during one session of Zim. They will not appear in the INI file.
11 '''
12
13 def __getitem__(self, k):
14@@ -547,12 +550,14 @@
15
16 def dump(self):
17 '''Returns a list of lines with text representation of the
18- dict. Used to write as a config file.
19+ dict. Used to write as a config file. Values with keys starting with '_'
20+ are considered as non-persistent and will be skipped.
21 '''
22 lines = []
23 def dump_section(name, parameters):
24 lines.append('[%s]\n' % section)
25 for param, value in parameters.items():
26+ if not param.startswith('_'):
27 lines.append('%s=%s\n' % (param, self._encode_value(value)))
28 lines.append('\n')
29
30
31=== modified file 'zim/gui/__init__.py'
32--- zim/gui/__init__.py 2011-04-14 20:01:02 +0000
33+++ zim/gui/__init__.py 2011-05-10 13:26:28 +0000
34@@ -1308,6 +1308,7 @@
35 return None # dialog was cancelled
36
37 file.copyto(dest)
38+ os.utime(str(dest), (-1, file.mtime())) # copy modification date
39 return dest
40
41 def show_clean_notebook(self):
42@@ -2084,7 +2085,10 @@
43 self.uistate = ui.uistate['MainWindow']
44
45 if not self._geometry_set:
46- # Ignore this is a explicit geometry was specified to the constructor
47+ # Ignore this if an explicit geometry was specified to the constructor
48+ self.uistate.setdefault('windowpos', (0, 0), check=value_is_coord)
49+ x, y = self.uistate['windowpos']
50+ self.move(x, y)
51 self.uistate.setdefault('windowsize', (600, 450), check=value_is_coord)
52 w, h = self.uistate['windowsize']
53 self.set_default_size(w, h)
54@@ -2175,9 +2179,9 @@
55 #TODO: set toggle_readonly insensitive when page is readonly
56
57 def do_close_page(self, ui, page):
58- w, h = self.get_size()
59 if not self._fullscreen:
60- self.uistate['windowsize'] = (w, h)
61+ self.uistate['windowpos'] = self.get_position()
62+ self.uistate['windowsize'] = self.get_size()
63 self.uistate['sidepane_pos'] = self._zim_window_left_pane.get_position()
64
65 def do_textview_toggle_overwrite(self, view):
66
67=== modified file 'zim/gui/searchdialog.py'
68--- zim/gui/searchdialog.py 2011-02-19 16:27:44 +0000
69+++ zim/gui/searchdialog.py 2011-05-10 13:26:28 +0000
70@@ -116,5 +116,5 @@
71 # Popup find dialog with same query
72 if self.query and self.query.simple_match:
73 string = self.query.simple_match
74- string.strip('*') # support partial matches
75+ string = string.strip('*') # support partial matches
76 self.ui.mainwindow.pageview.show_find(string, highlight=True)
77
78=== modified file 'zim/gui/widgets.py'
79--- zim/gui/widgets.py 2011-05-09 20:08:05 +0000
80+++ zim/gui/widgets.py 2011-05-10 13:26:28 +0000
81@@ -1890,6 +1890,11 @@
82 else:
83 self.uistate = zim.config.ListDict()
84
85+ self.uistate.setdefault('_windowpos', (None, None), check=value_is_coord)
86+ x, y = self.uistate['_windowpos']
87+ if (x, y) != (None, None):
88+ self.move(x, y)
89+
90 self.uistate.setdefault('windowsize', defaultwindowsize, check=value_is_coord)
91 #~ print '>>', self.uistate
92 w, h = self.uistate['windowsize']
93@@ -2023,6 +2028,8 @@
94 destroy = True
95
96 if ui_environment['platform'] != 'maemo':
97+ x, y = self.get_position()
98+ self.uistate['_windowpos'] = (x, y)
99 w, h = self.get_size()
100 self.uistate['windowsize'] = (w, h)
101 self.save_uistate()
102@@ -2349,8 +2356,8 @@
103 return filter
104
105 def add_filter_images(self):
106- '''Wrapper for filechooser.add_filter()
107- using gtk.FileFilter.add_pixbuf_formats(). Returns the filter object.
108+ '''Wrapper for filechooser.add_filter() to add a filter for images.
109+ Returns the filter object.
110 '''
111 if len(self.filechooser.list_filters()) == 0:
112 self._add_filter_all()
113@@ -2358,6 +2365,7 @@
114 filter.set_name(_('Images'))
115 # T: Filter in open file dialog, shows image files only
116 filter.add_pixbuf_formats()
117+ filter.add_mime_type('image/*') # to allow types like .ico
118 self.filechooser.add_filter(filter)
119 self.filechooser.set_filter(filter)
120 return filter