How to put excel window upfront in xlwings? - python

How can I put excel window in front of other apps in terms of visibility? I am not interested in making it visible in visible=True attribute of App, because I can only see the excel window in taskbar. I need to see it in front of me (on top of other apps), so I can use pyautogui.
app = xw.App(add_book=False)
api_wb = app.books.api.Open(file_directory, UpdateLinks=False)
wb = xw.Book(impl=xw._xlwindows.Book(xl=api_wb))
A sample of the code is here. Although any other method of opening file will result in the same excel being wrapped to taskbar.
How can I solve this?
I also wanted to upload an image of the issue, but stackoverflow didn't let me saying: 'An error occurred when uploading the image: Service Unavailable'. The image format is .png

You need to activate the app and steal the focus like this:
app.activate(steal_focus=True)
see: https://docs.xlwings.org/en/stable/api.html#xlwings.App.activate

Related

Openpyxl : Error message at the opening of the .xlsx created from a WorkBook that used wb.remove_sheet(ws)

Situation: I have model.xlsx, I delete 1 page, I save as output.xlsx. The page that I suppress have an image. There is no error raised.
Problem: when I try to open the file output.xlsx I have a first error message:
.
(Sorry: We have found a problem in the file <<output.xlsx>> but we can try to get back the maximum. If the source of the classifier reliable, click On Yes.)
And when I click on yes:
It says that it repaired the recording and it talks about images (so I suppose the images are the problem).
Then I have tricky errors (it delete the page but one other page that I try to duplicate doesn't keep track of the image).
Solution: I stopped using wb.remove_sheet(ws), now I use ws.sheet_state = 'hidden' and it works like a charm ! No problem to duplicate page with image and no error message at the openning of the file.
But it's system D ! (I want to delete the page, not hide it and pretend I did the job).
Am I doing something wrong ? Is this an error coming from the openpyxl library ?
Answer: System D because nobody answer, don't del it, just hide it.

Hide bottom HTML/widget, and remove Drag & Drop from Streamlit file_uploader()

I´ve created an app using Streamlit, which needs to read multiple files at once. I´m using the file_uploader() component with the parameter accept_multiple_files=True.
I got 2 questions:
First is if there´s a way to hide the bottom HTML/Widget that appears after uploading a file/s (see picture below)?
And second, if there´s a way to remove the drag&drop option, just leaving "Browse Files" toggle button?
The best solution currently is using the st.beta_expander() to hide the st.file_uploader() without having to programmatically play with the rerunning script to see if files were added. So for example in my problem it would be something like:
with st.beta_expander("Upload DICOM Files"):
uploaded_files = st.file_uploader("Select DICOM Files:",
accept_multiple_files=True,
type='dcm')
More info about the st.beta_expander() and what can be done with it here.

R Shiny equivalent in Python? Creating a window-based tool

I am trying to transfer an app i build in R Shiny to Python Code.
It's main use is to set the input parameters for a data analysis to be run which should create and output pdf file.
So far I managed to understand that DASH might be the tool to go with. But is there a way to launch a DASH app in an external window (not in a browser window)? Like the following:
After setting the Input values I want to have a button to click "Run" or something similiar to run the underlying code and generate a PDF Report. How would you do that with Python and do you maybe know a good Tutorial how to build a basic app like this?
I'm not exactly sure what you mean in the first part of your question. You may be able to use an IDE with integrated broswer to view your app during developement if you don't want to use a broswer. But the whole point of dash is to be a web based application, so it would be best on a browser.
Alternately, you can save the rendered output from browser to a .html file if you need to share it without having a live server host your application.
For the second part of your question, for a button click to generate a pdf report, refer to the documentation of callback in dash.
The callback function for the Run Analysis button can then be something on the lines of
def generate_report():
#Code to generate required pdf
# Code to download on client
return link_to_pdf
Hope this gives some pointers in the direction.

pptx-python - Powerpoint always opens on master slide page

I have an app that creates powerpoints. Everything goes well except that every time I want to open one of these powerpoints it opens it in the slide master view. This isn't necessarily a problem per se, but just annoying since I open a lot of these powerpoint files. Has anyone else encountered this? Any idea what this is due to?
This happens on both mac and windows.
I create a presentation from a template, generate the slides and then save it more or less like this:
self.prs = Presentation(
self.template_path)
for c, slide in enumerate(self.data):
self.generate_slide(slide)
self.prs.save(save_location)
I had this issue before, it was because the template slide was saved in the slide master view same as what Johnathon said.

Python upload an Image form my hard drive and show it on a canvas wideget.

I am writing a small python program that upload an image from A SPECIFIC location in my computer and then show it on a canvas wideget. I am using Tkinter as a GUI.
Problem: I need to upload the image from any location in my computer. I need to create a window explorer (similar to the one windows has Ctr + O) that let you browse through your folders to find the image you want to upload.
Question: What is the best way or module to create the Open Window explorer.
Thanks
There's a handy module for that: tkFileDialog!
import tkFileDialog
tkFileDialog.askopenfilename()
The function will return the path to the file for you and theres a variety of options you can set here

Categories

Resources