Lock Windows Screen GUI using python

J

Jaydeep Patil

Dear all,
Can we Lock Windows Screen GUI till program runs & unlock screen GUI when program finishes?



Regards
Jaydeep Paril
 
I

Ian Kelly

Dear all,
Can we Lock Windows Screen GUI till program runs & unlock screen GUI when program finishes?

If you mean can you programmatically bring up the Windows lock screen,
then you can do this:

import ctypes
ctypes.windll.user32.LockWorkStation()

The only way to unlock it is for the user to log in.

If you mean something else, you'll have to be more specific.
 
J

Jaydeep Patil

If you mean can you programmatically bring up the Windows lock screen,

then you can do this:



import ctypes

ctypes.windll.user32.LockWorkStation()



The only way to unlock it is for the user to log in.



If you mean something else, you'll have to be more specific.

Hi Lan,

Currently I am doing some automation in python excel. It read the data & plots number of graphs. It took more than 20 minutes. So while running my python program if user clicks on excel, error came.

So just i want to lock GUI not workstation.

I hope you understand this.

Let me know if you have any idea about it.


Regards
Jaydeep Patil
 
J

Jaydeep Patil

You can set the Application.Interactive property on Excel to block user input:

http://msdn.microsoft.com/en-us/library/office/ff841248(v=office.15).aspx



Example:



excel_app = win32com.client.Dispatch("Excel.Application")

excel_app.Interactive = False

try:

# Do some automation...

finally:

excel_app.Interactive = True


Hi Lan,

Thanks for sharing valuable info.

I have another query.

We can now block user inputs. But in my automation three is copy & paste work going on continuously in Excel before plotting the graphs.

During copy paste of excel data, if user by mistake doing some copy & paste operation outside excel(for e.g. doing copy paste in outlook mails, firefox browser etc), it may be cause for the another error.

How i can control this?


Thanks & Regards
Jaydeep Patil
 
C

Chris Angelico

During copy paste of excel data, if user by mistake doing some copy & paste operation outside excel(for e.g. doing copy paste in outlook mails, firefox browser etc), it may be cause for the another error.

How i can control this?

Suggestion: Don't. If you really need this level of control of the
workstation, you are going about things wrongly. This is a recipe for
fragility and horrific usability problems. There are two simple
solutions:

1) Make it really obvious that you're controlling the computer, by
putting something big across the screen - a splash screen, of sorts -
which is set to Always On Top and gives a message. And then just trust
that the user won't do anything, because you've done everything
reasonable. No further control needed.

2) Automate your code by moving stuff around on the disk, *not* by
actually working through Excel. Twenty minutes of Excel automation
should probably become a proper application that reads in some data
and generates some graphs. And it'd probably be faster, too (even if
Excel's performance is stellar, which I very much doubt, it's always
slower to work through a GUI than to do the work directly). Figure out
what you're really trying to do, and do that directly.

Also, please follow Mark's advice.

ChrisA
 
I

Ian Kelly

I have another query.

We can now block user inputs. But in my automation three is copy & paste
work going on continuously in Excel before plotting the graphs.
During copy paste of excel data, if user by mistake doing some copy &
paste operation outside excel(for e.g. doing copy paste in outlook mails,
firefox browser etc), it may be cause for the another error.
How i can control this?

Do you really need to use the system clipboard for this automation? Why not
just store the data in script variables and write them back from the?
 
J

Jaydeep Patil

Do you really need to use the system clipboard for this automation? Why not just store the data in script variables and write them back from the?


Hi lan,

For plotting one graph, I need to use four to five excel files. Currently Iam reading excel files one by one and copy data of excel files to another single master excel file. This master excel file consists of all data from all input excel files. So this is the reason i am using system clipboard.


Regards
Jay
 
I

Ian Kelly

Hi lan,

For plotting one graph, I need to use four to five excel files. CurrentlyI am reading excel files one by one and copy data of excel files to another single master excel file. This master excel file consists of all data from all input excel files. So this is the reason i am using system clipboard.

I don't currently have Excel around to test with, but I think you
could do something like this:

wb1.Sheets(1).Range("A1:F100").Value = wb2.Sheets(1).Range("A1:F100").Value

Not sure how efficient this is -- I envision it serializing an entire
array of data to send over COM to Python, only to send it right back
again at the other side. But then, the clipboard would be doing more
or less the same thing. It might be more efficient to implement the
above as a macro in Excel and then just call the macro.
 
J

Jaydeep Patil

I don't currently have Excel around to test with, but I think you

could do something like this:



wb1.Sheets(1).Range("A1:F100").Value = wb2.Sheets(1).Range("A1:F100").Value



Not sure how efficient this is -- I envision it serializing an entire

array of data to send over COM to Python, only to send it right back

again at the other side. But then, the clipboard would be doing more

or less the same thing. It might be more efficient to implement the

above as a macro in Excel and then just call the macro.

Hi lan,

Below is the sample function which doing copy paste in my case.
I am copying data directly by column, not reading each & every value.
Data is too big in heavy.

def copyPaste(self,ws):
# todo
self.ws = ws

startRowPaste = self.headerRow
self.col = self.getColToPaste(ws)
rngPaste = ws.Cells( startRowPaste, self.col)

self.datafile.openDataFile()
self.datafile.ws.Activate()
rngCopy = self.datafile.ws.Cells(self.datafile.headerRow,self.colCopy)
rngCopy = self.datafile.ws.Range(rngCopy,rngCopy.End(util.Xl.xlDown))

rngCopy.Copy()

ws.Activate()
ws.Paste(Destination=rngPaste)

self.dataRange = self.getDataRange()
self.datafile.closeDataFile()
pass
 
I

Ian Kelly

Below is the sample function which doing copy paste in my case.
I am copying data directly by column, not reading each & every value.
Data is too big in heavy.

The approach I suggested also operates on ranges, not individual cells.
 
C

Chris Angelico

For plotting one graph, I need to use four to five excel files. CurrentlyI am reading excel files one by one and copy data of excel files to another single master excel file. This master excel file consists of all data from all input excel files. So this is the reason i am using system clipboard.

Strong recommendation: Either avoid using actual Excel and the system
clipboard (and work with files on the disk), or get a dedicated VM
that you can take full control of without interfering with the human
on the workstation. With clipboard sharing disabled and the window
minimized, there'll be very little interaction between the VM and the
host.

Additional strong recommendation: Get off Google Groups, sign up for
the mailing list https://mail.python.org/mailman/listinfo/python-list
instead. Your posts are coming through mis-wrapped and double-spaced.

ChrisA
 
D

Dennis Lee Bieber

For plotting one graph, I need to use four to five excel files. Currently I am reading excel files one by one and copy data of excel files to another single master excel file. This master excel file consists of all data from all input excel files. So this is the reason i am using system clipboard.

If they are similar data (or even if they aren't), I'd probably suggest
writing the data to something like SQLite3, and then generating the final
plot from THAT...

Especially since it sounds very much as if your input Excel files are
just being used as a form of relation (in database theory, a "table" is
called a "relation" as there is typically some column [or combination of
columns] which serves as a key to which the other data columns are
"related"... "relational" does not specify the joins between "tables").
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top