~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderlib/utils/qthelpers.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2014-05-29 09:06:26 UTC
  • mfrom: (1.1.21) (18.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140529090626-f58t82g0n5iewaxu
Tags: 2.3.0~rc+dfsg-1~experimental2
* Add spyder-common binary package for all the python2,3 common files
* debian/path
  - 0001-fix-documentation-installation.patch (deleted)
  + 0001-fix-spyderlib-path.patch (new)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
# Local import
23
23
from spyderlib.baseconfig import get_image_path
 
24
from spyderlib.guiconfig import get_shortcut
24
25
from spyderlib.utils import programs
 
26
from spyderlib.py3compat import is_text_string, to_text_string
25
27
 
26
28
# Note: How to redirect a signal from widget *a* to widget *b* ?
27
29
# ----
150
152
    pathlist = []
151
153
    if source.hasUrls():
152
154
        for url in source.urls():
153
 
            path = _process_mime_path(unicode(url.toString()), extlist)
 
155
            path = _process_mime_path(to_text_string(url.toString()), extlist)
154
156
            if path is not None:
155
157
                pathlist.append(path)
156
158
    elif source.hasText():
157
 
        for rawpath in unicode(source.text()).splitlines():
 
159
        for rawpath in to_text_string(source.text()).splitlines():
158
160
            path = _process_mime_path(rawpath, extlist)
159
161
            if path is not None:
160
162
                pathlist.append(path)
194
196
    if text is not None:
195
197
        button.setText(text)
196
198
    if icon is not None:
197
 
        if isinstance(icon, (str, unicode)):
 
199
        if is_text_string(icon):
198
200
            icon = get_icon(icon)
199
201
        button.setIcon(icon)
200
202
    if text is not None or tip is not None:
243
245
        parent.connect(action, SIGNAL("toggled(bool)"), toggled)
244
246
        action.setCheckable(True)
245
247
    if icon is not None:
246
 
        if isinstance(icon, (str, unicode)):
 
248
        if is_text_string(icon):
247
249
            icon = get_icon(icon)
248
250
        action.setIcon(icon)
249
251
    if shortcut is not None:
262
264
    return action
263
265
 
264
266
 
 
267
def add_shortcut_to_tooltip(action, context, name):
 
268
    """Add the shortcut associated with a given action to its tooltip"""
 
269
    action.setToolTip(action.toolTip() + ' (%s)' %
 
270
                      get_shortcut(context=context, name=name))
 
271
 
 
272
 
265
273
def add_actions(target, actions, insert_before=None):
266
274
    """Add actions to a menu"""
267
275
    previous_action = None
291
299
 
292
300
def get_item_user_text(item):
293
301
    """Get QTreeWidgetItem user role string"""
294
 
    return from_qvariant(item.data(0, Qt.UserRole), unicode)
 
302
    return from_qvariant(item.data(0, Qt.UserRole), to_text_string)
295
303
 
296
304
 
297
305
def set_item_user_text(item, text):
301
309
 
302
310
def create_bookmark_action(parent, url, title, icon=None, shortcut=None):
303
311
    """Create bookmark action"""
304
 
    if icon is None:
305
 
        icon = get_icon('browser.png')
306
312
    return create_action( parent, title, shortcut=shortcut, icon=icon,
307
313
                          triggered=lambda u=url: programs.start_file(u) )
308
314
 
313
319
    bookmarks = ((module_name, url, title), ...)
314
320
    """
315
321
    actions = []
316
 
    for key, url, title, icon in bookmarks:
317
 
        if programs.is_module_installed(key):
318
 
            act = create_bookmark_action(parent, url, title, get_icon(icon))
 
322
    for key, url, title in bookmarks:
 
323
        # Create actions for scientific distros only if Spyder is installed
 
324
        # under them
 
325
        create_act = True
 
326
        if key == 'xy' or key == 'winpython':
 
327
            if not programs.is_module_installed(key):
 
328
                create_act = False
 
329
        if create_act:
 
330
            act = create_bookmark_action(parent, url, title)
319
331
            actions.append(act)
320
332
    return actions
321
333
 
322
334
        
323
 
def create_program_action(parent, text, icon, name, nt_name=None):
 
335
def create_program_action(parent, text, name, icon=None, nt_name=None):
324
336
    """Create action to run a program"""
325
 
    if isinstance(icon, basestring):
 
337
    if is_text_string(icon):
326
338
        icon = get_icon(icon)
327
339
    if os.name == 'nt' and nt_name is not None:
328
340
        name = nt_name
334
346
        
335
347
def create_python_script_action(parent, text, icon, package, module, args=[]):
336
348
    """Create action to run a GUI based Python script"""
337
 
    if isinstance(icon, basestring):
 
349
    if is_text_string(icon):
338
350
        icon = get_icon(icon)
339
351
    if programs.python_script_exists(package, module):
340
352
        return create_action(parent, text, icon=icon,
354
366
    def show(self, dialog):
355
367
        """Generic method to show a non-modal dialog and keep reference
356
368
        to the Qt C++ object"""
357
 
        for dlg in self.dialogs.values():
358
 
            if unicode(dlg.windowTitle()) == unicode(dialog.windowTitle()):
 
369
        for dlg in list(self.dialogs.values()):
 
370
            if to_text_string(dlg.windowTitle()) \
 
371
               == to_text_string(dialog.windowTitle()):
359
372
                dlg.show()
360
373
                dlg.raise_()
361
374
                break
373
386
    
374
387
    def close_all(self):
375
388
        """Close all opened dialog boxes"""
376
 
        for dlg in self.dialogs.values():
 
389
        for dlg in list(self.dialogs.values()):
377
390
            dlg.reject()
378
391
 
379
392