gotcha

Author Topic: About add hover information and login using extension  (Read 846 times)

June 13, 2019, 12:58:53 AM
Read 846 times

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hi all, I am a novice developer in Inkscape Extension developing. I am using Windows 10, python 2.7, MySQL and pymysql package to develop a python script to draw circuit diagram.

With the help of the InkscapeMadeEasy extension, I am able to draw svg circuit components and they are so cool! Thanks a lot!

Here is the question, I want to display a text component with extra information hovering above the component. When user move the mouse over the text component, an information window will pop out in the Inkscape.
I notice that there are multiple ways to display it in the web browser(using JS or CSS, etc), but can I display it directly in the Inkscape? I want to display the corresponding values to help user to draw on this diagram with the retrieved information so it has to be in the software rather than in a web browser. Is it possible and can someone give me some ideas? I really appreciate it.

Another question. Can I do the user login function in extension to visit specific information in MySQL database? That is to say, can I keep user login information(like username and password) in one extension and another window pop out for further selection? Thanks a lot!!!
  • 0.92
  • Windows 10

June 13, 2019, 08:29:15 PM
Reply #1

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
Welcome to the forum!

I can't be much help with this.  Writing extensions is beyond my ability.  But we have other members who can probably help.

I was just thinking whether I've seen any current extensions which do what you're describing, but I can't think of any.  There might be some, I just haven't seen it.

The closest thing I've seen is Extensions menu > Visualize Path > Measure Path.  This extension puts a text object on the page, showing the measurement that was requested.  I know it's not hover text, like you described.  It's just the closest thing I've seen.

Typically in Inkscape the status bar is used to give info to the user.  Maybe that would be an option?  In extensions, I've occassionally seen a little window which typically contains Traceback info, but sometimes has an error message.  There might be some way to use that?

Hopefully someone else will be along shortly, who can give you more concrete info.  If not, I would suggest trying the development chat channel https://chat.inkscape.org/channel/team_devel  Or the development mailing list:  https://lists.inkscape.org/postorius/lists/?all-lists
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann                       

June 14, 2019, 12:48:06 AM
Reply #2

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hi brynn,thank you for your suggestion!

I found that the text generated by Measure Path extension is not what I want cause it generates another text component, but I would use it as an alternative if I can't figure this out eventually.

Besides, this Measure Path extension menu has a tab for user to choose different input options, it solves a huge problem for me! I was wondering how to create different input options for different user demands, and it solves this problem perfectly! Many thanks!!

For the little error window suggestion, I saw a function called "inkex.errormsg()" in the source code. However, if this errormsg window is raised, the whole software is not accessible until I close this window, and I can't return to this page again. So it is not desirable for this situation.

Again, thanks a lot for your help! :th: I would keep waiting for others' opinions!
  • 0.92
  • Windows 10

June 14, 2019, 04:42:09 AM
Reply #3

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
but can I display it directly in the Inkscape?

- No, not like a bubble. You can add an inkscape:label, that will then be visible in the 'Objects' dialog.

Can I do the user login function in extension to visit specific information in MySQL database? That is to say, can I keep user login information(like username and password) in one extension and another window pop out for further selection?

- Yes, I think that would be possible. Some people use multiple extensions for this purpose (see gcodetools). Extensions can only access their own preference settings, though, so you may need to save the login data to a file. Or you can write an interactive extension in, say, Tkinter or any other GUI framework of your choice.

June 14, 2019, 05:32:57 PM
Reply #4

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hi Moini,

Thank you for your explanation!

For the text bubble, I decide to communicate with my client and show the objects dialog to them instead of the hover effect and explain this to them.

For the login function, I would start learning the Tkinter GUI now, and thank you so much for the suggestion!

 :ur:
  • 0.92
  • Windows 10

June 20, 2019, 07:08:12 PM
Reply #5

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hello everyone,

I have implemented the login module and save the username in a local file. Now I need to import this username into another extension to complete the SQL query. I want to display this information in the extension window, like "Current login user: XXX". Can I write a dynamic text to show it in the window?

I notice that in most extensions, the .inx files always show some static description text. Can I read the local file and display it directly in the extension window?

Thank you!
  • 0.92
  • Windows 10

June 21, 2019, 04:24:35 AM
Reply #6

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
No. You would have to write your own GUI to display dynamic content. E.g. use tkinter, as mentioned above.

June 21, 2019, 05:14:15 PM
Reply #7

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
  • 0.92
  • Windows 10

July 12, 2019, 02:19:40 AM
Reply #8

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hi, all.

I have a new question about display the result. I have done the query part and get a result for displaying. But I have initialized the program with the Tkinter and I can't write it on the canvas with the Inkex module. I set the button to create the new object like
Code: [Select]
 root = SVGWriting(self, some text )     root.affect()
and I set the SVGWriting class as normal inkscape extension script.  But when I click on this button, nothing happened and sometimes this program will crash.

I search the solution on the Github and saw someone putting the inkex module as the class and set the Tkinter as part of them. Is this necessary for the text drawing on the canvas?

Thank you for your help!
  • 0.92
  • Windows 10

July 12, 2019, 05:59:09 AM
Reply #9

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
I'm not sure what you're trying to do. The extension needs to finish and close before Inkscape will go on, and display any changes. Is that the block you're hitting?

July 12, 2019, 05:20:25 PM
Reply #10

HaroldTang

  • Sr. Newbie

  • Offline
  • **

  • 7
Hi Moini,

I use the Tkinter for the user interface and the button is inside this window. When user clicks on the button, the content will be retrieved from tkinter class and I want to set as a text component in the SVG file with the code
Code: [Select]
inkex.etree.subelement(layer, inkex.addNS('text', 'svg'))

The problem is these two parts are in separate classes and how can I set the button's function to initialize another class's object and when should I call the Effect.affect()? If I write this query part and display part in two extensions, the code is working but I just want to combine them together.
  • 0.92
  • Windows 10

July 13, 2019, 04:21:47 AM
Reply #11

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Mmh. Have a look at InkStitch, maybe, to learn. It uses wxPython, but aside from that, it should work in a similar way as what you intend to do.
https://github.com/inkstitch/inkstitch