PDA

View Full Version : How to use c4d.gui.HtmlViewerCustomGui in Python


Focus3D
09-24-2010, 02:37 PM
Hi,
If you have tested Ivy Grower plugin for R12, you will see that the help button allows to browse its help in cinema 4d.

In Python Documentation for c4d, I found c4d.gui.HtmlViewerCustomGui but it doesn't show how to use it.
Any example will be appreciated.

Thank you.

donelgreeko
09-24-2010, 04:13 PM
Hi Focus3D,

to use HtmlViewerCustomGui, just create a simple dialog and in GeDialog.CreateLayout use:

viewer = self.AddCustomGui(DIALOG_ID, c4d.CUSTOMGUI_HTMLVIEWER, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0, c4d.BaseContainer())

now you can set the URL by calling:

viewer.SetUrl("http://www.maxon.net/", c4d.URL_ENCODING_UTF16)

Cheers, donelgreeko

Focus3D
09-24-2010, 05:27 PM
Hi Sebastian,

Your answer was very clear and usefull.
Thank you again for your help.

hausgross
09-29-2010, 12:36 PM
Hi Sebastian,

Your answer was very clear and usefull.
Thank you again for your help.

hey Focus3D,

i guess you figured out how to get a dialog with a http-window working?

i m just trying to implement a panel with n url right into my cinema layout, so it would be really keen from you, if you could help me out, maybe some example script or something?

did you write a complete plugin for that, or just a script to pop up with your http viewer?

thanks for the help!

alex

just to clear things out i was using that atm, but thatīs not working:

import c4d
from c4d import gui
#Welcome to the world of Python

DIALOG_ID=1001
def main():

browser=gui.GeDialog()
view=browser.AddCustomGui(DIALOG_ID, c4d.CUSTOMGUI_HTMLVIEWER, "", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0, c4d.BaseContainer())
view.SetUrl("http://www.maxon.net/", c4d.URL_ENCODING_UTF16)
browser.Open(dlgtpye=1)

if __name__=='__main__':
main()

Focus3D
09-29-2010, 02:41 PM
Hi hausgross,

already done, soon a new c4d plugin "Web browser" (no fancy name here as it means what it does) will be available at http://nitro4d.com/ .

This work was done on collaboration with Nitroman as we have got this idea while working on the implementation of AniMidi plugin documentation.
And for avoiding any confusion, AniMidi Plugin is 100% by Nitroman.

Soon, some other suprises are coming.

donelgreeko
09-29-2010, 03:59 PM
Hi hausgross,

in the "examples" folder of the documentation you find some examples how to handle dialogs. There is also an introduction to the GUI of C4D in the c4d.gui section. Unfortunately the Html Viewer cannot be used in modal dialogs. In your case you pass an invalid value to "Open". Here are two of some valid values you can pass to "Open".

DLG_TYPE_MODAL
DLG_TYPE_ASYNC

Please check out the documentation for more information about the constants.

Here is an example, you paste it to the script manager.


import c4d
from c4d import gui
#Welcome to the world of Python

#You need to inherit your type from "GeDialog" and
#override the corresponding methods like "CreateLayout".
class YourDialog(gui.GeDialog):

BUTTON_ID = 1001

def CreateLayout(self):
self.AddButton(self.BUTTON_ID, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")
return True

def Command(self, id, msg):
if id==self.BUTTON_ID:
self.Close()
return True


if __name__=='__main__':
dlg = YourDialog()
#DLG_TYPE_MODAL = > synchronous dialog
#DLG_TYPE_ASYNC = > asynchronous dialogs
dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=400, defaulth=400)



Cheers, donelgreeko

hausgross
09-29-2010, 10:02 PM
hey sebastian, thanks again for the fast and great answer, as always :) i just had a look into the example plugins delivered with the manual, but the only one that pops up n dialog seems to be the CVRss one, or did i miss something?

but i got it right now, the thing that made me write the "dlgtype=1" was the circumstance, that the manual says that it need a bool. thatīs why i testes "0 or 1" and tried "true and false ;)" missed the "dlgtype=c4d.WHATEVER_CONSTANT" thingy ....

but i ll dive into your example right tomorrow morning :)

just one question spinning in my hat now: whats the difference between a modal and a asyncronous dialog? the modal one seems to work for me, the asyncronous version doesnt pop up a dialog. little explanation about modal vs. asyncronous would be great :)

you write the follow line:
self.AddButton(self.BUTTON_ID, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")

because i declared the ID as a variable before.
in py4d for r11.5 it was written like that,right? :
self.AddButton(id=1001, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")

does that work yet, or did the syntax change in any case?

thanks for the reply :)

cheers

alex

Focus3D
09-30-2010, 12:26 AM
hi,

check http://forums.cgsociety.org/showthread.php?f=94&t=923335 I posted the Web browser plugin.

hausgross
09-30-2010, 09:47 AM
hey Focus3D, thanks for the link ... that looks pretty sweet :) and advanced...

i īm looking at a way more basic option, just to get a fixed url displayed ... just for testing purposes.

@donelgreeko:

i got my head around the async and modal dialog types ... modal ones lock the screen till you close that dialogs, async are floating panels, which allow you for accessing the other gialogs aswell, right?

now i come up with this piece of code:
import c4d
from c4d import gui
#Welcome to the world of Python


class YourDialog(gui.GeDialog):

BUTTON_ID = 1001
DIALOG_ID = 1002

def CreateLayout(self):
self.SetTitle("Web Browser")
self.MenuFlushAll()
self.TabGroupBegin(1003, 5)
self.AddButton(self.BUTTON_ID, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")
viewer = self.AddCustomGui(self.DIALOG_ID, c4d.CUSTOMGUI_HTMLVIEWER, "pyBROWSER", c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 1024, 500, c4d.BaseContainer())
viewer.SetUrl("http://192.168.13.162:8080/jobs.cgi", c4d.URL_ENCODING_UTF16)
self.GroupEnd()
self.InitValues()
return True

def Command(self, id, msg):
if id==self.BUTTON_ID:
self.Close()
return True



if __name__=='__main__':
dlg = YourDialog()
#DLG_TYPE_MODAL = > synchronous dialog
#DLG_TYPE_ASYNC = > asynchronous dialogs
dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, pluginid=1006, defaultw=1024, defaulth=576, subid=1005)

i got the browser display working, when i put the TabGroupBegin() method in the code...

but i m missing a menu bar, i want to be able to undock the menu/dialog and be able to get the dialog right into my actual layout :) didnt found anything in the manual about "adding the menubar", any hint?

and last thingy: if i chance the dialog from "c4d.DLG_TYPE_MODAL_RESIZEABLE" to anything with "ASYNC" instead of "MODAL" the dialog pops up for some milliseconds, but than dissapears again automatically. how do i fix that so the async dialog stays opened?

cheers

Alex

donelgreeko
09-30-2010, 12:37 PM
Hi hausgross,

i got my head around the async and modal dialog types ... modal ones lock the screen till you close that dialogs, async are floating panels, which allow you for accessing the other gialogs aswell, right?


Yes. The asynchronous dialogs can just be used in a plugin, e.g. a CommandData.
By the way, in your code you use InitValues(), which is automatically called after your dialog is created.


but i m missing a menu bar, i want to be able to undock the menu/dialog and be able to get the dialog right into my actual layout :) didnt found anything in the manual about "adding the menubar", any hint?


The CVRss example uses a menu bar, take a look at this example. Unfortunately a menu bar is not possible in a modal dialog, so the menu will not appear.


because i declared the ID as a variable before.
in py4d for r11.5 it was written like that,right? :
Code:
self.AddButton(id=1001, c4d.BFH_SCALE|c4d.BFV_SCALE, 100, 25, "Close Dialog")


The syntax is still the same. Argument names are optional. This explanation might help: http://www.faqs.org/docs/diveintopython/apihelper_optional.html

Cheers, donelgreeko

hausgross
09-30-2010, 02:46 PM
thanks sebastian and thanks Focus3D again, got it working right now as i am writing this reply.

i didnt want to build up a whole webbrowser at first glance, i just wanted to integrate the netrender UI into cinema4d, so that our artists/supervisors can have a look at the actual render status right out of c4d.

and its running like a charm now, pretty easy, no input things needed for inhouse use ;) planning to build that up from time to time, adding features maybe :) but for first start, its really working as we planned it to work.

so thanks for the great support again!

cheers

alex

CGTalk Moderation
09-30-2010, 02:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.