Save map with widget as video/html_video - python

I created a map with a widget. The widget looks as following:
time_slider = widgets.interactive(var_map_interactive, time_sel=widgets.IntSlider(description = "Time", min = 0, max = t_end, step = 5, readout_format = "d"), continous_update = True)
I now wanted to save this as a widget stream using the WidgetStream from ipywebrtc
view_stream = WidgetStream(widget=time_slider)
and then as a VideoRecorder
recorder = VideoRecorder(stream=view_stream)
However, eventhough the map with the widget works on its own in my Jupyter notebook, the "recorder" does not display anything.
Any ideas why this is happening?
Also, how would I be able to create a html_video out from the recording?
Thanks for your help!

Related

How to make text alignment of Visio shapes using Python(Win32 module)

I read the documentation of VBA and couldn't convert this to Python code.
I simply created shape and tried to make its align right.
If I delete alignment line of code, rest code works perfectly.
I don't know, I might be using wrong VBA objects and methods. I'm open to your advices. If you provide me your solution code, I would be very appreciated.
import win32com.client
app = win32com.client.Dispatch("Visio.Application")
app.Visible = True
my_shape = page.DrawRectangle(3, 3, 5, 5)) # Draw rectangle
my_shape.Text = "Hello world!" # Add text to rectangle
my_shape.LineStyle = "None" # Add some styling
my_shape.Characters.ParaProps['visHorzAlign'] = 'visAlignRight' #Tried alignment here
my_shape.SetCenter(4.4281, 3) # Change position of rectangle
Here is the error
Related documentations and forums that I found:
http://www.44342.com/visio-f963-t1206-p1.htm
https://learn.microsoft.com/en-us/office/vba/api/visio.selection.align
Try this code:
import win32com.client as win32
app = win32.Dispatch("Visio.Application")
app.Visible = True
page = app.Documents.AddEx("", 1, 0).Pages(1) # create new document and get 1 page
my_shape = page.DrawRectangle(3, 3, 5, 5) # Draw rectangle
my_shape.Text = "Hello world!" # Add text to rectangle
my_shape.LineStyle = "None" # Add some styling
my_shape.Cells("Para.HorzAlign").FormulaU = "2" # 2 - right alignment
# or use my_shape.CellsSRC(4, 0, 6).FormulaU = "2" #visSectionParagraph=4, visHorzAlign=6
my_shape.SetCenter(4.4281, 3) # Change position of rectangle

Populate window in Maya with icons and dynamically adjust depending on window size

I want to create a window in maya, that gets populated with icons from a specific path. I know how to do that, but I also want the icons to adjust dynamically as I change the size of the window.
For example, let's say I have this:
enter image description here
and I want when I resize to get this:
enter image description here
here is a bit of the code I have :
import maya.cmds as cmds
import os
from os import listdir
def UI(*args):
if cmds.window("Test", exists = True):
cmds.deleteUI("Test")
testwindow = cmds.window("Test", t="Test Window", sizeable = 1)
cmds.scrollLayout('srcoll', p = "Test")
cmds.rowColumnLayout("ColLayout", p = "Test", nc = 3)#I imagine the "nc" command is probably useless here, I am just leaving it for testing purposes
cmds.showWindow("Test")
customPath = "C:\Users\$username$\Desktop"
customPathItems = listdir(customPath)
def popUI(*args):
for item in customPathItems:
if item.endswith("_icon.png"):
cmds.iconTextButton(l = item, p = "ColLayout", i = customPath + "/" + item, w = 128, h = 128)
def buildUI(*args):
UI()
popUI()
buildUI()
Any help would be appreciated
What you need is called a Flow layout, where the items inside the layout automatically adjust themselves when the widget is resized.
Here's an example from Qt's documentation that you can fully convert over to Python:
https://doc.qt.io/qt-4.8/qt-layouts-flowlayout-flowlayout-cpp.html
You can also google pyqt flow layout for ones already written in Python.

WxPython BoxSizer inside Listbook

I'm trying to use wx.Listbook to implement a settings window with multiple pages. I made the Listbook just fine, but when I started adding items to a page, I ran into a problem. The items are displayed on top of each other, so it's impossible to see everything I'm trying to show.
self.global_settings_frame = wx.Frame(parent=self, title="Global Settings", name="Global Settings")
self.global_settings_listbook = wx.Listbook(parent=self.global_settings_frame, style=wx.LB_LEFT)
self.global_settings_file_window = wx.Panel(parent=self.global_settings_listbook)
self.global_settings_file_box = wx.BoxSizer(orient=wx.VERTICAL)
self.show_full_pathname_checkbox = wx.CheckBox(self.global_settings_file_window, label="Show full pathname")
self.global_settings_file_box.Add(self.show_full_pathname_checkbox, proportion=1)
self.global_default_extension = wx.TextCtrl(self.global_settings_file_window)
self.global_settings_file_box.Add(self.global_default_extension, proportion=1)
self.global_settings_token_window = wx.Panel(parent=self.global_settings_listbook)
self.global_settings_listbook.InsertPage(0, self.global_settings_file_window, "Files")
self.global_settings_listbook.InsertPage(1, self.global_settings_token_window, "Token Defnition")
self.global_settings_frame.Show()
When I comment out the second element, the uncommented part works fine:
self.global_settings_frame = wx.Frame(parent=self, title="Global Settings", name="Global Settings")
self.global_settings_listbook = wx.Listbook(parent=self.global_settings_frame, style=wx.LB_LEFT)
self.global_settings_file_window = wx.Panel(parent=self.global_settings_listbook)
self.global_settings_file_box = wx.BoxSizer(orient=wx.VERTICAL)
self.show_full_pathname_checkbox = wx.CheckBox(self.global_settings_file_window, label="Show full pathname")
self.global_settings_file_box.Add(self.show_full_pathname_checkbox, proportion=1)
self.global_default_extension = wx.TextCtrl(self.global_settings_file_window)
self.global_settings_file_box.Add(self.global_default_extension, proportion=1)
self.global_settings_token_window = wx.Panel(parent=self.global_settings_listbook)
self.global_settings_listbook.InsertPage(0, self.global_settings_file_window, "Files")
self.global_settings_listbook.InsertPage(1, self.global_settings_token_window, "Token Defnition")
self.global_settings_frame.Show()
But I think the BoxSizer isn't working right because when I comment out the previous line (the one adding the CheckBox to the BoxSizer), the display is the same.
I've tried using separate panels for each element and then putting those panels in the BoxSizer, but that also didn't work (I can show you what that looks like if necessary). So it looks like I'm not using the BoxSizer correctly, but I don't understand how I am supposed to use it in this case. What I want is a page of a ListBook that contains a CheckBox and a TextCtrl (for single line text entry). Can you help?
As I can see, you never assign any sizer to your page(s).
You should just do it :
......
self.global_settings_file_box.Add(self.global_default_extension, proportion=1)
self.global_settings_file_window.SetSizer(self.global_settings_file_box)
self.global_settings_token_window = wx.Panel(parent=self.global_settings_listbook)
......
Regards
Xav'

Unclear on how to import and display an .OBJ file with Python (in Maya)

I've been working on a project for a week now trying different ways to solve this. I'm extremely new to python and programming in general and don't know the basics.
The task is to make a window with a button that imports an external .obj file into the scene and rename it. At one point I was able to do that by putting the files in the "HOME" directory aka My Documents but I lost that piece of code.
I've tried tons of ways but I don't understand the correct syntax at all. I've asked classmates for help as well and we couldn't figure out where to store the obj and how to reference it properly.
I see this thread which seems useful but always returns "No files found" Importing OBJ file to maya scene (MEL/Python).
import maya.cmds as mc
import os
ram = mc.window("RenamerWin", t = "Renamer v 1.0", w = 300, h = 300)
if mc.window(ram, exists = True):
mc.deleteUI("RenamerWin")
#icon
logopath = mc.internalVar(upd = True) + "icons/icon.jpg"
mc.columnLayout(adj = True)
mc.image (w = 300, h = 100, image = logopath)
mc.separator (h = 25, style = 'double')
mc.text("Welcome to your Custom Forest Builder!")
rockW = mc.intSliderGrp(l = "width", min = 0, max = 10, field = True)
rockH = mc.intSliderGrp(l = "height", min = 0, max = 10, field = True)
rockD = mc.intSliderGrp(l = "depth", min = 0, max = 10, field = True)
mc.button(l = "Create a Rock", c = "myRock()")
#Name the Rock
rockName = mc.textFieldGrp (l="renamer", editable = True)
mc.button (l = "Name the Rock", c = "myRockRenamer()")
mc.showWindow(ram)
def myRockRenamer():
finalName = mc.textFieldGrp(rockName,q = True, text = True)
mc.rename(finalName)
mc.showWindow(ram)
def myRock():
myRockWidth = mc.intSliderGrp(rockW, q = True, value = True)
myRockHeight = mc.intSliderGrp(rockH, q = True, value = True)
myRockDepth = mc.intSliderGrp(rockD, q = True, value = True)
finalRock = mc.file(os.path.join(os.getenv('E:\2015\2. Tech Art Programming\Forest Builder'), 'rock.obj'), open = True, force = True)
finalRock.scale( myRockWidth, myRockHeight, myRockDepth)
Questions:
Do I store the .obj in the same folder as the .mb file? I want to be able to zip this code.
Do I have to load the file into maya first then use another piece of code to display it?
Can you link me to some references? I've searched google over and over again. maybe I've stumbled across the answer but didn't understand what I was looking at.
How to I store this other than in the maya folder on my PC?
logopath = mc.internalVar(upd = True) + "icons/icon.jpg"
When I get the window to open and try to press the button I don't get an error about the file not being found anymore (I did before).
"# Error: TypeError: file C:\Program Files\Autodesk\Maya2015\bin\python27.zip\ntpath.py line 96: object of type 'NoneType' has no len()"
Thank you SO much for any help.
I'm not sure if your problem is that you can't auto-find the path to your obj, or you can't get it to import/rename afterwards?
I've just made a quick example of how I would do it:
import maya.cmds as cmds
new_name = "Renamed_OBJ"
my_file_path = "C:/Temp/OBJ_Temp.obj"
import_nodes = cmds.file(my_file_path,i=True,type="OBJ",rpr="OBJ_Import",rnn=True)
transform_nodes = cmds.ls(import_nodes,type="transform")
for t_node in transform_nodes:
print(t_node)
cmds.rename(t_node,new_name)
A few things; You can use i=True + type="OBJ" in the file command to import objs and add rnn=True to get it to return all the nodes it just imported.
Then you can sort through them a pick out the transform nodes, and rename and scales those.
This documentation helps me a lot in times like this: https://help.autodesk.com/view/MAYAUL/2020/ENU/?guid=__CommandsPython_index_html
I hope it helps.
You aren't escaping the backslashes in your file path, so maya sees them as special chararacters. Try
finalRock = mc.file(os.path.join(os.getenv('E:\\2015\\2. Tech Art Programming\\Forest Builder'), 'rock.obj'), open = True, force = True)
or
finalRock = mc.file(os.path.join(os.getenv('E:/2015/2. Tech Art Programming/Forest Builder'), 'rock.obj'), open = True, force = True)

Group Gtk.RadioToolButtons?

I've been trying for days to find a way to group RadioToolButtons in pygobject without success. There is no *.RadioToolButton.join_group(*) method like RadioButtons.
Here is what I've been trying:
## Toolbar
self.mainWindow.mainBox.mainToolbar = Gtk.Toolbar()
self.mainWindow.mainBox.mainToolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
self.mainWindow.mainBox.mainToolbar.set_style(Gtk.ToolbarStyle.BOTH)
self.mainWindow.mainBox.mainToolbar.radioGroup = list() # *.radioGroup = [] Does not work either.
## Left toolbar separator
self.mainWindow.mainBox.mainToolbar.leftSeparator = Gtk.SeparatorToolItem(draw = False)
self.mainWindow.mainBox.mainToolbar.leftSeparator.set_expand(True)
## Overview toggle button
self.mainWindow.mainBox.mainToolbar.overviewRadio = Gtk.RadioToolButton(Gtk.STOCK_HOME)
self.mainWindow.mainBox.mainToolbar.overviewRadio.set_group(self.mainWindow.mainBox.mainToolbar.radioGroup)
self.mainWindow.mainBox.mainToolbar.overviewRadio.set_is_important(True)
self.mainWindow.mainBox.mainToolbar.overviewRadio.set_label("Overview")
self.mainWindow.mainBox.mainToolbar.overviewRadio.connect("clicked", self.on_overviewRadio_clicked)
self.mainWindow.mainBox.mainToolbar.overviewRadio.set_border_width(4)
## Basic settings toggle button
self.mainWindow.mainBox.mainToolbar.basicRadio = RadioToolButton(Gtk.STOCK_PROPERTIES)
self.mainWindow.mainBox.mainToolbar.basicRadio.set_group(self.mainWindow.mainBox.mainToolbar.radioGroup)
self.mainWindow.mainBox.mainToolbar.basicRadio.set_is_important(True)
self.mainWindow.mainBox.mainToolbar.basicRadio.set_label("Basic")
self.mainWindow.mainBox.mainToolbar.basicRadio.connect("clicked", self.on_basicRadio_clicked)
self.mainWindow.mainBox.mainToolbar.basicRadio.set_border_width(4)
## Right toolbar separator
self.mainWindow.mainBox.mainToolbar.rightSeparator = Gtk.SeparatorToolItem(
draw = False)
self.mainWindow.mainBox.mainToolbar.rightSeparator.set_expand(True)
(Not all of my code - *.show_all() is not the issue)
Here is what I get:
What am I doing wrong? How can I group these two buttons?
Create the second radio button so it's in the first radio button's group using:
Gtk.RadioToolButton.new_with_stock_from_widget(first_button, Gtk.STOCK_PROPERTIES)
PS. Looks like the UI task you are trying to accomplish might be better done with a Notebook?

Categories

Resources