1,105,177 Community Members

separating UI from logic

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I implemented whole UI and logic into one py file now I thing it would be good if I separate the UI file from the logic, and to run the UI I shoud run the file that contains logic that inturn loads the UI...

I have RenderUI.py module that contains everything now, I have made another file named Render.pyfrom which I want to launch the UI file
both the above files are in folder Batch that I made package by including __init__.py

the RenderUI.py file contains the class Window,

but since I made a PyQt4 app i have this code in the end outside of Window Class ,

if __name__ =='__main__':
   app = QtGui.QApplication(sys.argv)
   app.setStyle("cleanlooks")
   win = Window()
   win.show()
   sys.exit(app.exec_())

which means in Render.py file I should have from RenderUI.py import * but this isnt working strangely when I try typing from RenderUI i get option like from RenderUI.RenderUI while their is not such sub file with same name..

so how should I call the RenderUI from Render.py ?

Member Avatar
Gribouillis
Posting Maven
3,453 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 883 [?]
Skill Endorsements: 18 [?]
Moderator
 
0
 

The first thing to do is to avoid import *. Import only specific names. What you could do in this case is a function

# file RenderUI.py

def main():
   app = QtGui.QApplication(sys.argv)
   app.setStyle("cleanlooks")
   win = Window()
   win.show()
   sys.exit(app.exec_())

and in the other file

# file Render.py
from RenderUI import main

if __name__ == "__main__":
    main()
Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

how about doing this way ?

import RenderUI,sys
from PyQt4 import QtCore,QtGui



#class Actions():




if __name__ =='__main__':
   app = QtGui.QApplication(sys.argv)
   app.setStyle("cleanlooks")
   win = RenderUI.Window()
   win.show()
   sys.exit(app.exec_())
else:
     win = Window()
     win.show()

and no need of main() function in RenderUI.py

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

i defined a class in Render.py but if i define its constructor __init__ i get error in the RenderUI.py while instantiating this class saying

Message File Name   Line    Position    
Traceback               
    <module> \Render.py  39      
    __init__    \RenderUI.py    26      
TypeError: __init__() takes no arguments (1 given)  

please help out !!

Member Avatar
Gribouillis
Posting Maven
3,453 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 883 [?]
Skill Endorsements: 18 [?]
Moderator
 
0
 

__init__'s minimal signature is def __init__(self):...

Member Avatar
krystosan
Junior Poster
191 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

i shoudl have implemented UI separate from logic now it is such a pain...

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article