Skip to content

Add support for IPython Jupyter QT Console as a debugging aid #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2019

Conversation

kakaroto
Copy link
Contributor

@kakaroto kakaroto commented Feb 24, 2019

If manuskript is launched with its last argument set to "--console" an
interactive console opens up to help debug the application.
The IPython, qtconsole and matplotlib libraries must be installed for it
to work and they won't get imported unless the argument is passed to the app.

This is such an amazing tool, and it was quite a headache to get it to work, but now I can interactively debug things while the application is open and explore the outlineModel and items and the data and figure out how everything fits together.

Example of my current console log with all my trial/errors removed (I was trying to understand the outlineModelItem data, and how I can find children/siblings of items, and how to access the data in them) to showcase how useful it can be :

In[10]: root = MW.mdlOutline.rootItem

In[30]: root.childItems[1].data(0)
Out[30]: 'Prologue'

In[31]: prologue = root.childItems[1]

In[40]: str(prologue)
Out[40]: '<manuskript.models.outlineItem.outlineItem object at 0x00000267D59CB9E8>'

*** write a __str__ function then instead of restarting manuskript, I just dynamically modify the object in the console ***

In[47]: def __str__(self):
    return "{id}: {folder}{title}{children}".format(
        id=self.ID(),
        folder="*" if self.isFolder() else "",
        title=self.data(self.enum.title),
        children="" if self.isText() else "({})".format(self.childCount())
        )
        

In[48]: outlineItem.__str__ =__str__

In[51]: str(prologue)
Out[51]: '272: *Prologue(5)'

In[52]: root.children()
Out[52]: 
[<manuskript.models.outlineItem.outlineItem at 0x267d59b7630>,
 <manuskript.models.outlineItem.outlineItem at 0x267d59cb9e8>,
 <manuskript.models.outlineItem.outlineItem at 0x267d59cbd68>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a5ce10>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a5c048>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a66f28>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a66f98>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a90e10>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a90ef0>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a90f98>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a905f8>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a90c18>,
 <manuskript.models.outlineItem.outlineItem at 0x267d5a92320>]


In[54]: outlineItem.__repr__ =__str__

In[55]: root.children()
Out[55]: 
[277: Cover Page,
 272: *Prologue(5),
 271: *Part 1(15),
 292: *Interludes(2),
 295: *Part 2(6),
 293: *Interludes(0),
 294: *Part 3(25),
 316: *Interludes(0),
 318: *Part 4(0),
 317: *Interludes(0),
 319: *Part 5(0),
 320: *Epilogue(0)]

In[57]: part1 = root.children()[2]

In[58]: part1.parent()
Out[58]: 0: *Root(13)

In[59]: help(part1)
*** This prints the manual of outlineItem and I found the 'level' function which looks interesting for me ****

In[61]: part1.level()
Out[61]: 0

In[62]: root.level()
Out[62]: -1

In[65]: ch1 = part1.childItems[1]

In[66]: ch1.level()
Out[66]: 1

In[78]: ch1.parent().children().index(ch1)
Out[78]: 1

*** Now I know how to use/navigate the model from an index or from the root item, and I can write the function I wanted to write. I'll also probably test it in the console without restarting the app until bugs are ironed out ***

If manuskript is launched with its last argument set to "--console" an
interactive console opens up to help debug the application.
The IPython, qtconsole and matplotlib libraries must be installed for it
to work and they won't get imported unless the argument is passed to the app.
@gedakc gedakc added this to the 0.9.0 milestone Mar 29, 2019
@gedakc
Copy link
Collaborator

gedakc commented Mar 29, 2019

I regression tested this without specifying --console and without installing the IPython, qtconsole and matplotlib libraries and Manuskript continued to work normally. As such I will rebase and merge this enhancement to help developers of Manuskript.

@gedakc gedakc merged commit 4a947a9 into olivierkes:develop Mar 29, 2019
@kakaroto kakaroto deleted the qtconsole branch March 29, 2019 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants