We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

separating UI from logic

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 ?

2
Contributors
5
Replies
19 Hours
Discussion Span
5 Months Ago
Last Updated
6
Views
krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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()
Gribouillis
Posting Maven
Moderator
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11

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

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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 !!

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

Gribouillis
Posting Maven
Moderator
3,101 posts since Jul 2008
Reputation Points: 1,130
Solved Threads: 761
Skill Endorsements: 11

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

krystosan
Junior Poster
116 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0781 seconds using 2.77MB