def __init__(self): self.__mWindowWidth = 400 self.__mWindowHeight = 600 self.__mBackgroundColor = '#%02x%02x%02x' % (224, 255, 255) # Init Window self.__mWindow = Tk() self.__mWindow.title("날씨어떄") self.__mWindow.geometry("400x600+100+100") self.__mWindow.resizable(False, False) self.__mWindow.configure(bg=self.__mBackgroundColor) # Whole Frame self.mWholeFrame = Frame(self.__mWindow,bg=self.__mBackgroundColor) self.mWholeFrame.pack() # Init Frame # Menu, Main Frame self.mMenuFrame = Frame(self.mWholeFrame,width = self.__mWindowWidth,height = self.__mWindowHeight*0.9, bg = self.__mBackgroundColor); self.mMenuFrame.pack() self.mMainFrame = Frame(self.mWholeFrame, bg = self.__mBackgroundColor); self.mMainFrame.pack() self.mScrollbar = Scrollbar(self.mMainFrame) self.mScrollbar.pack(side=RIGHT, fill=Y) # Fragment frameRate = 0.4 # Overview Frame 개황프레임 self.mOverviewFrame = Frame(self.mMainFrame,width = self.__mWindowWidth,height = self.__mWindowHeight*frameRate); self.mOverviewFrame.pack() self.mOverview = Overview(self.mOverviewFrame) # TimeToWeather Frame 시간별 날씨 프레임 self.mTimeToWeatherFrame = Frame(self.mMainFrame,width = self.__mWindowWidth,height = self.__mWindowHeight*frameRate, bg = "blue") self.mTimeToWeatherFrame.pack() # DayToWeather Frame 일별 날씨 프레임 self.mDayToWeatherFrame = Frame(self.mMainFrame,width = self.__mWindowWidth,height = self.__mWindowHeight*frameRate, bg = "green") self.mDayToWeatherFrame.pack() # AirFresh Frame 공기청정지수 프레임 self.mAirFreshFrame = Frame(self.mMainFrame,width = self.__mWindowWidth,height = self.__mWindowHeight*frameRate, bg = "yellow") self.mAirFreshFrame.pack() # Button menuButtonwidth = 8 menuButtonheight = 1 Button(self.mMenuFrame,text = "검색",width = menuButtonwidth, height = menuButtonheight, command = self.search).grid(row=0, column=0,padx = 4, pady=4) Button(self.mMenuFrame,text = "즐겨찾기",width = menuButtonwidth, height = menuButtonheight, command = self.bookmark).grid(row=0, column=1,padx = 4, pady=4) Button(self.mMenuFrame,text = "E-Mail",width = menuButtonwidth, height = menuButtonheight, command = self.email).grid(row=0, column=2, padx = 4, pady=4) Button(self.mMenuFrame,text = "Home",width = menuButtonwidth, height = menuButtonheight, command= self.home).grid(row=0, column=3, padx = 4, pady=4) Button(self.mMenuFrame,text = "갱신",width = menuButtonwidth, height = menuButtonheight, command = self.refresh).grid(row=0, column=4,padx = 4, pady=4) Button(self.mMenuFrame,text = "지역",width = menuButtonwidth, height = menuButtonheight, command = self.location).grid(row=1, column=2, pady=10)
def build(self): self.root = Accordion(min_space=30) self.overviewItem = AccordionItem(title=unichr(252) + 'bersicht') self.overview = Overview() self.overviewItem.add_widget(self.overview) #self.closeButton = Button(text = 'Beenden', size=(100, 50), size_hint=(None, None), background_color=[1,0,0,1]) #self.closeButton.bind(on_press=self.closeApp) #self.overviewItem.add_widget(self.closeButton) self.root.add_widget(self.overviewItem) self.scheduleItem = AccordionItem(title='Stundenplan') self.schedule = Schedule() self.scheduleItem.add_widget(self.schedule) self.root.add_widget(self.scheduleItem) self.appointmentsItem = AccordionItem(title='Termine') self.appointments = Appointments() self.appointmentsItem.add_widget(self.appointments) self.root.add_widget(self.appointmentsItem) self.todoListItem = AccordionItem(title='Haushalts-Abenteuer') self.todoList = TodoList() self.todoListItem.add_widget(self.todoList) self.root.add_widget(self.todoListItem) self.newsItem = AccordionItem(title='Nachrichten') self.news = Feeds() self.newsItem.add_widget(self.news) self.root.add_widget(self.newsItem) self.pictureItem = AccordionItem(title='Bilder') self.pictureFrame = PictureFrame() self.pictureItem.add_widget(self.pictureFrame) self.root.add_widget(self.pictureItem) self.scheduleItem.collapse = False self.ledClock = LedMatrix() # initial weather data self.overview.updateWeather() # continuous updates EACH_SECOND = 1 ONE_MINUTE = 60 FOUR_HOURS = 14400 Clock.schedule_interval(self.__updateLedClock, EACH_SECOND) Clock.schedule_interval(self.__updateItems, ONE_MINUTE) Clock.schedule_interval(self.__updateWeather, FOUR_HOURS) return self.root
def _write_overview(self, comment_lines: List[str] = [], **data) -> None: columns = list(data.keys()) measurement_data = dict(data) contacts_string = "" for contact in self._contacts: contacts_string += contact + " " if contacts_string != "": columns.append("Contacts") measurement_data["Contacts"] = contacts_string[:-1] # Omit trailing space columns.sort() overview_file = Overview(self._path, self.__class__.__name__, columns, comment_lines) overview_file.add_measurement(**measurement_data)
def on_new_game(self): if not os.path.exists('save'): os.mkdir('save') game = model.Game() game.json_savefile(os.path.join('save', '%d.json' % game.created)) model.game = game director.push(Overview())
def main(): app = QtGui.QApplication(sys.argv) initialize() # Profiling purpose # with PyCallGraph(output=GraphvizOutput()): print "Loading data..." # start_time1 = time.time() projectname = "qpid" dataModel = pickle.load(open(projectname + ".pickle", "rb")) print "Max data..." MaxElements = pickle.load(open(projectname + "MaxItems.pickle", "rb")) print "Bug data..." BugData = pickle.load(open(projectname + "BugData.pickle", "rb")) # print("Bug data Load --- %f seconds ---" % (time.time() - start_time1)) ex = VizView(dataModel, MaxElements, BugData, projectname) ui2 = loadFiles() OverviewObject = Overview(dataModel, MaxElements, BugData, projectname, ex) SpatialObject = SpatialOverview(dataModel, MaxElements, BugData, projectname, ex) loader = QtUiTools.QUiLoader() ui2 = loader.load('./widgetsforviz.ui') merge = LayoutInit(ex, ui2, OverviewObject, SpatialObject) merge.show() sys.exit(app.exec_())
def __init__(self): # Create carousel - doesn't work so well in .kv Carousel.__init__(self, direction='right', loop='true', scroll_distance=80, scroll_timeout=100) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game)
def main(): if len(sys.argv) != 4: usage() infos = loadFile(sys.argv[2]) if infos == None: sys.exit(-1) lega = Legalization() if sys.argv[1] == "machines": lega = Machines(infos) elif sys.argv[1] == "overview": lega = Overview(infos) lega.generate_file(sys.argv[3]) return
def __init__(self, **kwargs): # Create carousel - doesn't work so well in .kv Carousel.__init__(self, direction='right', loop='true', scroll_distance=80, scroll_timeout=100, **kwargs) self.config = MyConfig() self.backlight = BacklightFactory.Make(self.config) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game) self.idle_clock = Clock.schedule_once( self.on_idle, float(self.config.switch_off_time)) Window.bind(on_motion=self.on_motion)
def __render_ms_dialog(self): central = QFrame() hbox = QHBoxLayout(central) hbox.setContentsMargins(0, 0, 0, 0) # Define components visible in main layout self.params = Overview('ms') self.graph = Canvas(project='ms') # Add splitter for main layout splitter = QSplitter(Qt.Horizontal) splitter.addWidget(self.params) splitter.addWidget(self.graph) splitter.setStretchFactor(1, 10) hbox.addWidget(splitter) self.setCentralWidget(central) self.params.ms_success.connect(self.__plot_results_ms) self.show()
def __render_imob_dialog(self): central = QFrame() hbox = QHBoxLayout(central) hbox.setContentsMargins(0,0,0,0) # Define components visible in main layout self.params = Overview('imob') self.graph = Canvas() # sublayout for results results_area = QFrame() results_area_layout = QHBoxLayout(results_area) results_area_layout.setContentsMargins(0,0,0,0) self.table_area = TableResults() self.table_area.hide() results_splitter = QSplitter(Qt.Horizontal) results_splitter.addWidget(self.graph) results_splitter.addWidget(self.table_area) results_area_layout.addWidget(results_splitter) # Add splitter for main layout splitter = QSplitter(Qt.Horizontal) splitter.addWidget(self.params) splitter.addWidget(results_area) splitter.setStretchFactor(1,10) hbox.addWidget(splitter) self.setCentralWidget(central) self.params.ccs_imob_success.connect(self.__plot_results) self.show()
class CreatorUI(QtGui.QWidget): def __init__(self, filename=""): super(CreatorUI, self).__init__() root = ET.Element('design') self.xml = ET.ElementTree(root) self.default_title = "Model Aircraft Creator" self.wings = [] self.initUI() self.filename = "" self.fileroot = "" self.load(filename) self.clean = True # version checking task self.checkversion = CheckVersion() self.connect(self.checkversion, QtCore.SIGNAL("update(QString)"), self.version_message) self.checkversion.start() def version_message(self, text): reply = QtGui.QMessageBox.question( self, 'Version Check', 'A new version of MAdesigner (v' + text + ') is available.<br><a href="http://mirrors.ibiblio.org/flightgear/ftp/MAdesigner">Click here to download it.</A>', QtGui.QMessageBox.Ok) def onChange(self): #print "parent onChange() called!" result = self.rebuildTabNames() if result: self.rebuildWingLists() self.clean = False def isClean(self): return self.clean def setClean(self): self.clean = True def rebuildTabNames(self): updated = False i = 0 for wing in self.wings: if wing.valid: wing_name = "Wing: " + wing.get_name() tab_name = self.tabs.tabText(i + 1) if wing_name != tab_name: self.tabs.setTabText(i + 1, wing_name) updated = True i += 1 return updated def rebuildWingLists(self): wing_names = [] for wing in self.wings: if wing.valid: wing_names.append(wing.get_name()) for wing in self.wings: if wing.valid: wing.rebuild_wing_list(wing_names) def initUI(self): self.setWindowTitle(self.default_title) layout = QtGui.QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QtGui.QFrame() layout.addWidget(file_group) file_layout = QtGui.QHBoxLayout() file_group.setLayout(file_layout) new = QtGui.QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QtGui.QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QtGui.QPushButton('Open Examples...') open.clicked.connect(self.open_examples) file_layout.addWidget(open) save = QtGui.QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QtGui.QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QtGui.QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QtGui.QTabWidget() layout.addWidget(self.tabs) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab(self.overview.get_widget(), "Overview") # 'Command' button bar cmd_group = QtGui.QFrame() layout.addWidget(cmd_group) cmd_layout = QtGui.QHBoxLayout() cmd_group.setLayout(cmd_layout) cmd_layout.addWidget(QtGui.QLabel("<b>Design Tools:</b> ")) add_wing = QtGui.QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QtGui.QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QtGui.QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QtGui.QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QtGui.QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show() def add_wing(self): self.onChange() valid_wing_count = 0 for wing in self.wings: if wing.valid: valid_wing_count += 1 name = str(valid_wing_count + 1) wing = WingUI(changefunc=self.onChange, name=name) self.wings.append(wing) self.tabs.addTab(wing.get_widget(), "Wing: " + name) #def add_fuse(self): # print "add fuse requested" def build_fast(self): if not self.isClean(): reply = QtGui.QMessageBox.question( self, "The design has been modified.", "You must save before a build.", QtGui.QMessageBox.Save | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=25, \ circle_points=8) QtGui.QApplication.restoreOverrideCursor() def build_detail(self): if not self.isClean(): reply = QtGui.QMessageBox.question( self, "The design has been modified.", "You must save before a build.", QtGui.QMessageBox.Save | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtGui.QApplication.setOverrideCursor( QtGui.QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=1000, \ circle_points=32) QtGui.QApplication.restoreOverrideCursor() def view3d(self): viewer = "osgviewer" # look for viewer in the standard path result = distutils.spawn.find_executable(viewer) if result == None: app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] viewer = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer") viewerexe = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer.exe") print "testing for " + viewer + " or " + viewerexe result = os.path.isfile(viewer) or os.path.isfile(viewerexe) if not result: error = QtGui.QErrorMessage(self) error.showMessage("Cannot find " + viewer + " in path. Perhaps it needs to be installed?") return madfile = self.fileroot + ".mad" if not os.path.exists(madfile): error = QtGui.QErrorMessage(self) error.showMessage( "No '.mad' file ... please save your design with a file name.") return if not self.isClean(): error = QtGui.QErrorMessage(self) error.showMessage( "The design has been modified. You must <b>Build</b> it before viewing the 3d structure." ) return acfile = self.fileroot + ".ac" if not os.path.exists(acfile): error = QtGui.QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue.") #self.build_fast() return madtime = os.path.getmtime(madfile) actime = os.path.getmtime(acfile) if madtime > actime: error = QtGui.QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue.") #self.build_fast() return command = [] command.append(viewer) command.append("--window") command.append("50") command.append("50") command.append("800") command.append("600") command.append(self.fileroot + ".ac") pid = subprocess.Popen(command).pid print "spawned osgviewer with pid = " + str(pid) def wipe_slate(self): self.overview.wipe_clean() for wing in self.wings: wing.delete_self() self.clean = True def load(self, filename): if filename == "": # new empty design return basename = os.path.basename(str(filename)) fileroot, ext = os.path.splitext(basename) if not os.path.exists(filename): # invalid/nonexistent filename return self.wipe_slate() try: self.xml = ET.parse(filename) except: error = QtGui.QErrorMessage(self) error.showMessage(filename + ": xml parse error:\n" + str(sys.exc_info()[1])) return self.setWindowTitle(self.default_title + " - " + fileroot) self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) root = self.xml.getroot() node = root.find('overview') self.overview.parse_xml(node) for wing_node in root.findall('wing'): wing = WingUI(changefunc=self.onChange) wing.parse_xml(wing_node) self.wings.append(wing) self.tabs.addTab(wing.get_widget(), "Wing: " + wing.get_name()) self.rebuildWingLists() def new_design(self): # wipe the current design (by command or before loading a new design) if not self.isClean(): reply = QtGui.QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return self.wipe_slate() def open(self, startdir=None): if not self.isClean(): reply = QtGui.QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return if startdir == None: startdir = os.path.expanduser("~") filename = QtGui.QFileDialog.getOpenFileName(self, "Open File", startdir, "MAdesigner (*.mad)") if (filename == ""): return self.load(str(filename)) def open_home(self): startdir = os.path.expanduser("~") self.open(startdir) def open_examples(self): app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] startdir = os.path.abspath(app_path + "/examples") self.open(startdir) def setFileName(self): startdir = os.path.expanduser("~/newdesign.mad") return QtGui.QFileDialog.getSaveFileName(self, "Save File", startdir, "MAdesigner (*.mad)") def save(self): if self.filename == "": filename = str(self.setFileName()) if filename == "": # print "cancelled save ..." return else: self.filename = filename self.fileroot, ext = os.path.splitext(self.filename) # create a new xml root root = ET.Element('design') self.xml = ET.ElementTree(root) # overview node = ET.SubElement(root, 'overview') self.overview.gen_xml(node) # wings for wing in self.wings: if wing.valid: node = ET.SubElement(root, 'wing') wing.gen_xml(node) try: self.xml.write(self.filename, encoding="us-ascii", xml_declaration=False, pretty_print=True) except: print "error saving file" return self.setWindowTitle(self.default_title + " - " + os.path.basename(str(self.filename))) self.setClean() def saveas(self): filename = self.setFileName() if filename == "": # print "cancelled save as ..." return else: self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) self.save() def quit(self): if not self.isClean(): reply = QtGui.QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtCore.QCoreApplication.instance().quit()
class CreatorUI(QWidget): def __init__(self, filename=""): super(CreatorUI, self).__init__() self.default_title = "Model Aircraft Creator" self.wings = [] self.initUI() self.filename = "" self.fileroot = "" self.load(filename) self.clean = True self.dirname = "." # version checking task (fixme) # self.checkversion = CheckVersion() # self.connect( self.checkversion, QtCore.SIGNAL("update(QString)"), # self.version_message ) # self.checkversion.start() def version_message(self, text): reply = QMessageBox.question(self, 'Version Check', 'A new version of MAdesigner (v' + text + ') is available.<br><a href="http://mirrors.ibiblio.org/flightgear/ftp/MAdesigner">Click here to download it.</A>', QMessageBox.Ok) def onChange(self): #print "parent onChange() called!" result = self.rebuildTabNames() if result: self.rebuildWingLists() self.clean = False def isClean(self): return self.clean def setClean(self): self.clean = True def rebuildTabNames(self): updated = False i = 0 for wing in self.wings: if wing.valid: wing_name = "Wing: " + wing.get_name() tab_name = self.tabs.tabText(i+1) if wing_name != tab_name: self.tabs.setTabText(i+1, wing_name) updated = True i += 1 return updated def rebuildWingLists(self): wing_names = [] for wing in self.wings: if wing.valid: wing_names.append(wing.get_name()) for wing in self.wings: if wing.valid: wing.rebuild_wing_list( wing_names ) def initUI(self): self.setWindowTitle( self.default_title ) layout = QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QFrame() layout.addWidget(file_group) file_layout = QHBoxLayout() file_group.setLayout( file_layout ) new = QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QPushButton('Load Example...') open.clicked.connect(self.load_example) file_layout.addWidget(open) save = QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QTabWidget() layout.addWidget( self.tabs ) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab( self.overview.get_widget(), "Overview" ); # 'Command' button bar cmd_group = QFrame() layout.addWidget(cmd_group) cmd_layout = QHBoxLayout() cmd_group.setLayout( cmd_layout ) cmd_layout.addWidget( QLabel("<b>Design Tools:</b> ") ) add_wing = QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show() def add_wing(self): self.onChange() valid_wing_count = 0 for wing in self.wings: if wing.valid: valid_wing_count += 1 name = str( valid_wing_count + 1 ) wing = WingUI(changefunc=self.onChange, name=name) self.wings.append(wing) self.tabs.addTab( wing.get_widget(), "Wing: " + name ) #def add_fuse(self): # print "add fuse requested" def build_fast(self): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QMessageBox.Save | QMessageBox.Cancel, QMessageBox.Save) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QApplication.setOverrideCursor(QCursor(QtCore.Qt.WaitCursor)) design = self.gen_property_tree() build = Builder(design, dirname="", airfoil_resample=25, circle_points=8, nest_speed="fast") QApplication.restoreOverrideCursor() def build_detail(self): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QMessageBox.Save | QMessageBox.Cancel, QMessageBox.Save) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QApplication.setOverrideCursor(QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=1000, circle_points=32, nest_speed="nice") QApplication.restoreOverrideCursor() def view3d(self): viewer = "osgviewer" # look for viewer in the standard path result = distutils.spawn.find_executable(viewer) if result == None: app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] viewer = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer") viewerexe = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer.exe") print "testing for " + viewer + " or " + viewerexe result = os.path.isfile(viewer) or os.path.isfile(viewerexe) if not result: error = QErrorMessage(self) error.showMessage( "Cannot find " + viewer + " in path. Perhaps it needs to be installed?" ) return madfile = self.fileroot + ".mad" if not os.path.exists(madfile): error = QErrorMessage(self) error.showMessage( "No '.mad' file ... please save your design with a file name." ) return if not self.isClean(): error = QErrorMessage(self) error.showMessage( "The design has been modified. You must <b>Build</b> it before viewing the 3d structure." ) return acfile = self.fileroot + ".ac" if not os.path.exists(acfile): error = QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue." ) #self.build_fast() return madtime = os.path.getmtime(madfile) actime = os.path.getmtime(acfile) if madtime > actime: error = QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue." ) #self.build_fast() return command = [] command.append(viewer) command.append("--window") command.append("50") command.append("50") command.append("800") command.append("600") command.append(self.fileroot + ".ac") pid = subprocess.Popen(command).pid print "spawned osgviewer with pid = " + str(pid) def wipe_slate(self): self.overview.wipe_clean() for wing in self.wings: wing.delete_self() self.setClean() # load from a filename def load(self, filename): if filename == "": # new empty design return self.dirname = os.path.split(os.path.realpath(filename))[0] if not isWritable(self.dirname): QMessageBox.question(self, 'Directory Access Notice', 'The directory <b>' + self.dirname + '</b> is not writable. Using <b>' + os.getcwd() + '</b> to save build files.', QMessageBox.Ok) self.dirname = os.getcwd() basename = os.path.basename(str(filename)) fileroot, ext = os.path.splitext(basename) print filename if not os.path.exists(filename): # invalid/nonexistent filename print "invalid file name" return self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) f = open(filename, 'r') stream = f.read() f.close() self.loads(stream, fileroot) # load from a stream (string) def loads(self, stream, fileroot): self.wipe_slate() design = PropertyNode() if props_json.loads(stream, design, ""): print "json parse successful" else: error = QErrorMessage(self) error.showMessage( "json parse failed" ) return False # design.pretty_print() self.setWindowTitle( self.default_title + " - " + fileroot ) node = design.getChild('overview', True) self.overview.load(node) design.setLen('wing', 1) # force to be enumerated if not already num_wings = design.getLen('wing') for i in range(num_wings): wing_node = design.getChild('wing[%d]' % i) wing = WingUI(changefunc=self.onChange) wing.load(wing_node) self.wings.append(wing) self.tabs.addTab( wing.get_widget(), "Wing: " + wing.get_name() ) self.rebuildWingLists() self.setClean() def new_design(self): # wipe the current design (by command or before loading a new design) if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return self.wipe_slate() def open(self, startdir=None): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return if startdir == None: startdir = os.path.expanduser("~") (filename, mask) = QFileDialog.getOpenFileName(self, "Open File", startdir, "MAdesigner (*.mad)") if ( filename == "" ): return self.load(str(filename)) def open_home(self): startdir = os.path.expanduser("~") self.open(startdir) def load_example(self): basepath = os.path.split(os.path.realpath(__file__))[0] example_path = os.path.join(basepath, "../examples/") (filename, mask) = QFileDialog.getOpenFileName(None, "Open File", example_path, "MAdesigner (*.mad)") if ( filename == "" ): return self.load(filename) def setFileName(self): startdir = os.path.expanduser("~/newdesign.mad") (filename, mask) = QFileDialog.getSaveFileName(self, "Save File", startdir, "MAdesigner (*.mad)") return filename def gen_property_tree(self): # create a new design root design = PropertyNode() # overview node = design.getChild('overview', True) self.overview.save(node) # wings i = 0 for wing in self.wings: if wing.valid: node = design.getChild('wing[%d]' % i, True) wing.save(node) i += 1 return design def save(self): if self.filename == "": filename = str(self.setFileName()) if filename == "": # print "cancelled save ..." return else: self.filename = filename self.fileroot, ext = os.path.splitext(self.filename) # print self.fileroot, ext # create the design as a property tree design = self.gen_property_tree() try: props_json.save(self.filename, design) except: print "error saving file" return self.setWindowTitle( self.default_title + " - " + os.path.basename(str(self.filename)) ) self.setClean() def saveas(self): filename = self.setFileName() if filename == "": # print "cancelled save as ..." return else: self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) self.save() def quit(self): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QtCore.QCoreApplication.instance().quit()
class CreatorUI(QWidget): def __init__(self, filename=""): super(CreatorUI, self).__init__() self.default_title = "Model Aircraft Creator" self.wings = [] self.initUI() self.filename = "" self.fileroot = "" self.load(filename) self.clean = True self.dirname = "." # version checking task (fixme) # self.checkversion = CheckVersion() # self.connect( self.checkversion, QtCore.SIGNAL("update(QString)"), # self.version_message ) # self.checkversion.start() def version_message(self, text): reply = QMessageBox.question( self, 'Version Check', 'A new version of MAdesigner (v' + text + ') is available.<br><a href="http://mirrors.ibiblio.org/flightgear/ftp/MAdesigner">Click here to download it.</A>', QMessageBox.Ok) def onChange(self): #print "parent onChange() called!" result = self.rebuildTabNames() if result: self.rebuildWingLists() self.clean = False def isClean(self): return self.clean def setClean(self): self.clean = True def rebuildTabNames(self): updated = False i = 0 for wing in self.wings: if wing.valid: wing_name = "Wing: " + wing.get_name() tab_name = self.tabs.tabText(i + 1) if wing_name != tab_name: self.tabs.setTabText(i + 1, wing_name) updated = True i += 1 return updated def rebuildWingLists(self): wing_names = [] for wing in self.wings: if wing.valid: wing_names.append(wing.get_name()) for wing in self.wings: if wing.valid: wing.rebuild_wing_list(wing_names) def initUI(self): self.setWindowTitle(self.default_title) layout = QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QFrame() layout.addWidget(file_group) file_layout = QHBoxLayout() file_group.setLayout(file_layout) new = QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QPushButton('Load Example...') open.clicked.connect(self.load_example) file_layout.addWidget(open) save = QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QTabWidget() layout.addWidget(self.tabs) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab(self.overview.get_widget(), "Overview") # 'Command' button bar cmd_group = QFrame() layout.addWidget(cmd_group) cmd_layout = QHBoxLayout() cmd_group.setLayout(cmd_layout) cmd_layout.addWidget(QLabel("<b>Design Tools:</b> ")) add_wing = QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show() def add_wing(self): self.onChange() valid_wing_count = 0 for wing in self.wings: if wing.valid: valid_wing_count += 1 name = str(valid_wing_count + 1) wing = WingUI(changefunc=self.onChange, name=name) self.wings.append(wing) self.tabs.addTab(wing.get_widget(), "Wing: " + name) #def add_fuse(self): # print "add fuse requested" def build_fast(self): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QMessageBox.Save | QMessageBox.Cancel, QMessageBox.Save) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QApplication.setOverrideCursor(QCursor(QtCore.Qt.WaitCursor)) design = self.gen_property_tree() build = Builder(design, dirname="", airfoil_resample=25, circle_points=8, nest_speed="fast") QApplication.restoreOverrideCursor() def build_detail(self): if not self.isClean(): reply = QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QMessageBox.Save | QMessageBox.Cancel, QMessageBox.Save) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QApplication.setOverrideCursor(QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=1000, circle_points=32, nest_speed="nice") QApplication.restoreOverrideCursor() def view3d(self): viewer = "osgviewer" # look for viewer in the standard path result = distutils.spawn.find_executable(viewer) if result == None: app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] viewer = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer") viewerexe = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer.exe") print "testing for " + viewer + " or " + viewerexe result = os.path.isfile(viewer) or os.path.isfile(viewerexe) if not result: error = QErrorMessage(self) error.showMessage("Cannot find " + viewer + " in path. Perhaps it needs to be installed?") return madfile = self.fileroot + ".mad" if not os.path.exists(madfile): error = QErrorMessage(self) error.showMessage( "No '.mad' file ... please save your design with a file name.") return if not self.isClean(): error = QErrorMessage(self) error.showMessage( "The design has been modified. You must <b>Build</b> it before viewing the 3d structure." ) return acfile = self.fileroot + ".ac" if not os.path.exists(acfile): error = QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue.") #self.build_fast() return madtime = os.path.getmtime(madfile) actime = os.path.getmtime(acfile) if madtime > actime: error = QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue.") #self.build_fast() return command = [] command.append(viewer) command.append("--window") command.append("50") command.append("50") command.append("800") command.append("600") command.append(self.fileroot + ".ac") pid = subprocess.Popen(command).pid print "spawned osgviewer with pid = " + str(pid) def wipe_slate(self): self.overview.wipe_clean() for wing in self.wings: wing.delete_self() self.setClean() # load from a filename def load(self, filename): if filename == "": # new empty design return self.dirname = os.path.split(os.path.realpath(filename))[0] if not isWritable(self.dirname): QMessageBox.question( self, 'Directory Access Notice', 'The directory <b>' + self.dirname + '</b> is not writable. Using <b>' + os.getcwd() + '</b> to save build files.', QMessageBox.Ok) self.dirname = os.getcwd() basename = os.path.basename(str(filename)) fileroot, ext = os.path.splitext(basename) print filename if not os.path.exists(filename): # invalid/nonexistent filename print "invalid file name" return self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) f = open(filename, 'r') stream = f.read() f.close() self.loads(stream, fileroot) # load from a stream (string) def loads(self, stream, fileroot): self.wipe_slate() design = PropertyNode() if props_json.loads(stream, design, ""): print "json parse successful" else: error = QErrorMessage(self) error.showMessage("json parse failed") return False # design.pretty_print() self.setWindowTitle(self.default_title + " - " + fileroot) node = design.getChild('overview', True) self.overview.load(node) design.setLen('wing', 1) # force to be enumerated if not already num_wings = design.getLen('wing') for i in range(num_wings): wing_node = design.getChild('wing[%d]' % i) wing = WingUI(changefunc=self.onChange) wing.load(wing_node) self.wings.append(wing) self.tabs.addTab(wing.get_widget(), "Wing: " + wing.get_name()) self.rebuildWingLists() self.setClean() def new_design(self): # wipe the current design (by command or before loading a new design) if not self.isClean(): reply = QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return self.wipe_slate() def open(self, startdir=None): if not self.isClean(): reply = QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return if startdir == None: startdir = os.path.expanduser("~") (filename, mask) = QFileDialog.getOpenFileName(self, "Open File", startdir, "MAdesigner (*.mad)") if (filename == ""): return self.load(str(filename)) def open_home(self): startdir = os.path.expanduser("~") self.open(startdir) def load_example(self): basepath = os.path.split(os.path.realpath(__file__))[0] example_path = os.path.join(basepath, "../examples/") (filename, mask) = QFileDialog.getOpenFileName(None, "Open File", example_path, "MAdesigner (*.mad)") if (filename == ""): return self.load(filename) def setFileName(self): startdir = os.path.expanduser("~/newdesign.mad") (filename, mask) = QFileDialog.getSaveFileName(self, "Save File", startdir, "MAdesigner (*.mad)") return filename def gen_property_tree(self): # create a new design root design = PropertyNode() # overview node = design.getChild('overview', True) self.overview.save(node) # wings i = 0 for wing in self.wings: if wing.valid: node = design.getChild('wing[%d]' % i, True) wing.save(node) i += 1 return design def save(self): if self.filename == "": filename = str(self.setFileName()) if filename == "": # print "cancelled save ..." return else: self.filename = filename self.fileroot, ext = os.path.splitext(self.filename) # print self.fileroot, ext # create the design as a property tree design = self.gen_property_tree() try: props_json.save(self.filename, design) except: print "error saving file" return self.setWindowTitle(self.default_title + " - " + os.path.basename(str(self.filename))) self.setClean() def saveas(self): filename = self.setFileName() if filename == "": # print "cancelled save as ..." return else: self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) self.save() def quit(self): if not self.isClean(): reply = QMessageBox.question( self, "The design has been modified.", "Do you want to save your changes?", QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save) #print "response = " + str(reply) if reply == QMessageBox.Save: self.save() elif reply == QMessageBox.Cancel: return QtCore.QCoreApplication.instance().quit()
def initUI(self): self.setWindowTitle( self.default_title ) layout = QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QFrame() layout.addWidget(file_group) file_layout = QHBoxLayout() file_group.setLayout( file_layout ) new = QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QPushButton('Load Example...') open.clicked.connect(self.load_example) file_layout.addWidget(open) save = QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QTabWidget() layout.addWidget( self.tabs ) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab( self.overview.get_widget(), "Overview" ); # 'Command' button bar cmd_group = QFrame() layout.addWidget(cmd_group) cmd_layout = QHBoxLayout() cmd_group.setLayout( cmd_layout ) cmd_layout.addWidget( QLabel("<b>Design Tools:</b> ") ) add_wing = QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show()
class CreatorUI(QtGui.QWidget): def __init__(self, filename=""): super(CreatorUI, self).__init__() root = ET.Element('design') self.xml = ET.ElementTree(root) self.default_title = "Model Aircraft Creator" self.wings = [] self.initUI() self.filename = "" self.fileroot = "" self.load(filename) self.clean = True # version checking task self.checkversion = CheckVersion() self.connect( self.checkversion, QtCore.SIGNAL("update(QString)"), self.version_message ) self.checkversion.start() def version_message(self, text): reply = QtGui.QMessageBox.question(self, 'Version Check', 'A new version of MAdesigner (v' + text + ') is available.<br><a href="http://mirrors.ibiblio.org/flightgear/ftp/MAdesigner">Click here to download it.</A>', QtGui.QMessageBox.Ok) def onChange(self): #print "parent onChange() called!" result = self.rebuildTabNames() if result: self.rebuildWingLists() self.clean = False def isClean(self): return self.clean def setClean(self): self.clean = True def rebuildTabNames(self): updated = False i = 0 for wing in self.wings: if wing.valid: wing_name = "Wing: " + wing.get_name() tab_name = self.tabs.tabText(i+1) if wing_name != tab_name: self.tabs.setTabText(i+1, wing_name) updated = True i += 1 return updated def rebuildWingLists(self): wing_names = [] for wing in self.wings: if wing.valid: wing_names.append(wing.get_name()) for wing in self.wings: if wing.valid: wing.rebuild_wing_list( wing_names ) def initUI(self): self.setWindowTitle( self.default_title ) layout = QtGui.QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QtGui.QFrame() layout.addWidget(file_group) file_layout = QtGui.QHBoxLayout() file_group.setLayout( file_layout ) new = QtGui.QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QtGui.QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QtGui.QPushButton('Open Examples...') open.clicked.connect(self.open_examples) file_layout.addWidget(open) save = QtGui.QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QtGui.QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QtGui.QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QtGui.QTabWidget() layout.addWidget( self.tabs ) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab( self.overview.get_widget(), "Overview" ); # 'Command' button bar cmd_group = QtGui.QFrame() layout.addWidget(cmd_group) cmd_layout = QtGui.QHBoxLayout() cmd_group.setLayout( cmd_layout ) cmd_layout.addWidget( QtGui.QLabel("<b>Design Tools:</b> ") ) add_wing = QtGui.QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QtGui.QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QtGui.QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QtGui.QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QtGui.QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show() def add_wing(self): self.onChange() valid_wing_count = 0 for wing in self.wings: if wing.valid: valid_wing_count += 1 name = str( valid_wing_count + 1 ) wing = WingUI(changefunc=self.onChange, name=name) self.wings.append(wing) self.tabs.addTab( wing.get_widget(), "Wing: " + name ) #def add_fuse(self): # print "add fuse requested" def build_fast(self): if not self.isClean(): reply = QtGui.QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QtGui.QMessageBox.Save | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=25, \ circle_points=8) QtGui.QApplication.restoreOverrideCursor() def build_detail(self): if not self.isClean(): reply = QtGui.QMessageBox.question(self, "The design has been modified.", "You must save before a build.", QtGui.QMessageBox.Save | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) build = Builder(filename=self.filename, airfoil_resample=1000, \ circle_points=32) QtGui.QApplication.restoreOverrideCursor() def view3d(self): viewer = "osgviewer" # look for viewer in the standard path result = distutils.spawn.find_executable(viewer) if result == None: app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] viewer = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer") viewerexe = os.path.abspath(app_path + "/OpenSceneGraph/bin/osgviewer.exe") print "testing for " + viewer + " or " + viewerexe result = os.path.isfile(viewer) or os.path.isfile(viewerexe) if not result: error = QtGui.QErrorMessage(self) error.showMessage( "Cannot find " + viewer + " in path. Perhaps it needs to be installed?" ) return madfile = self.fileroot + ".mad" if not os.path.exists(madfile): error = QtGui.QErrorMessage(self) error.showMessage( "No '.mad' file ... please save your design with a file name." ) return if not self.isClean(): error = QtGui.QErrorMessage(self) error.showMessage( "The design has been modified. You must <b>Build</b> it before viewing the 3d structure." ) return acfile = self.fileroot + ".ac" if not os.path.exists(acfile): error = QtGui.QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue." ) #self.build_fast() return madtime = os.path.getmtime(madfile) actime = os.path.getmtime(acfile) if madtime > actime: error = QtGui.QErrorMessage(self) error.showMessage( "Design needs to be 'built'; click ok to continue." ) #self.build_fast() return command = [] command.append(viewer) command.append("--window") command.append("50") command.append("50") command.append("800") command.append("600") command.append(self.fileroot + ".ac") pid = subprocess.Popen(command).pid print "spawned osgviewer with pid = " + str(pid) def wipe_slate(self): self.overview.wipe_clean() for wing in self.wings: wing.delete_self() self.clean = True def load(self, filename): if filename == "": # new empty design return basename = os.path.basename(str(filename)) fileroot, ext = os.path.splitext(basename) if not os.path.exists(filename): # invalid/nonexistent filename return self.wipe_slate() try: self.xml = ET.parse(filename) except: error = QtGui.QErrorMessage(self) error.showMessage( filename + ": xml parse error:\n" + str(sys.exc_info()[1]) ) return self.setWindowTitle( self.default_title + " - " + fileroot ) self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) root = self.xml.getroot() node = root.find('overview') self.overview.parse_xml(node) for wing_node in root.findall('wing'): wing = WingUI(changefunc=self.onChange) wing.parse_xml(wing_node) self.wings.append(wing) self.tabs.addTab( wing.get_widget(), "Wing: " + wing.get_name() ) self.rebuildWingLists() def new_design(self): # wipe the current design (by command or before loading a new design) if not self.isClean(): reply = QtGui.QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return self.wipe_slate() def open(self, startdir=None): if not self.isClean(): reply = QtGui.QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return if startdir == None: startdir = os.path.expanduser("~") filename = QtGui.QFileDialog.getOpenFileName(self, "Open File", startdir, "MAdesigner (*.mad)") if ( filename == "" ): return self.load(str(filename)) def open_home(self): startdir = os.path.expanduser("~") self.open(startdir) def open_examples(self): app_path = os.path.split(os.path.abspath(sys.argv[0]))[0] startdir = os.path.abspath(app_path + "/examples") self.open(startdir) def setFileName(self): startdir = os.path.expanduser("~/newdesign.mad") return QtGui.QFileDialog.getSaveFileName(self, "Save File", startdir, "MAdesigner (*.mad)") def save(self): if self.filename == "": filename = str(self.setFileName()) if filename == "": # print "cancelled save ..." return else: self.filename = filename self.fileroot, ext = os.path.splitext(self.filename) # create a new xml root root = ET.Element('design') self.xml = ET.ElementTree(root) # overview node = ET.SubElement(root, 'overview') self.overview.gen_xml(node) # wings for wing in self.wings: if wing.valid: node = ET.SubElement(root, 'wing') wing.gen_xml(node) try: self.xml.write(self.filename, encoding="us-ascii", xml_declaration=False, pretty_print=True) except: print "error saving file" return self.setWindowTitle( self.default_title + " - " + os.path.basename(str(self.filename)) ) self.setClean() def saveas(self): filename = self.setFileName() if filename == "": # print "cancelled save as ..." return else: self.filename = str(filename) self.fileroot, ext = os.path.splitext(self.filename) self.save() def quit(self): if not self.isClean(): reply = QtGui.QMessageBox.question(self, "The design has been modified.", "Do you want to save your changes?", QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) #print "response = " + str(reply) if reply == QtGui.QMessageBox.Save: self.save() elif reply == QtGui.QMessageBox.Cancel: return QtCore.QCoreApplication.instance().quit()
def initUI(self): self.setWindowTitle(self.default_title) layout = QVBoxLayout() self.setLayout(layout) # 'File' button bar file_group = QFrame() layout.addWidget(file_group) file_layout = QHBoxLayout() file_group.setLayout(file_layout) new = QPushButton('New') new.clicked.connect(self.new_design) file_layout.addWidget(new) open = QPushButton('Open...') open.clicked.connect(self.open_home) file_layout.addWidget(open) open = QPushButton('Load Example...') open.clicked.connect(self.load_example) file_layout.addWidget(open) save = QPushButton('Save') save.clicked.connect(self.save) file_layout.addWidget(save) saveas = QPushButton('Save As...') saveas.clicked.connect(self.saveas) file_layout.addWidget(saveas) quit = QPushButton('Quit') quit.clicked.connect(self.quit) file_layout.addWidget(quit) file_layout.addStretch(1) # Main work area self.tabs = QTabWidget() layout.addWidget(self.tabs) self.overview = Overview(changefunc=self.onChange) self.tabs.addTab(self.overview.get_widget(), "Overview") # 'Command' button bar cmd_group = QFrame() layout.addWidget(cmd_group) cmd_layout = QHBoxLayout() cmd_group.setLayout(cmd_layout) cmd_layout.addWidget(QLabel("<b>Design Tools:</b> ")) add_wing = QPushButton('Add Wing...') add_wing.clicked.connect(self.add_wing) cmd_layout.addWidget(add_wing) #add_fuse = QPushButton('Add Fuselage...') #add_fuse.clicked.connect(self.add_fuse) #cmd_layout.addWidget(add_fuse) fast_build = QPushButton('Fast Build...') fast_build.clicked.connect(self.build_fast) cmd_layout.addWidget(fast_build) detail_build = QPushButton('Detail Build...') detail_build.clicked.connect(self.build_detail) cmd_layout.addWidget(detail_build) view3d = QPushButton('View 3D') view3d.clicked.connect(self.view3d) cmd_layout.addWidget(view3d) cmd_layout.addStretch(1) self.resize(800, 700) self.show()
def change2overview(self): self.overview = Overview(root=self.f_screen, village=self.village, row_i=3, column_i=1)
# sleep 3; grim .data/... # show countdown in status'bar # insert the image path in buffer # notifications: # create a layer in the bottom'left corner, to print notifications, using: # python3-cffi + wlroots (layer-shell) + python3-cairocffi # https://cffi.readthedocs.io/en/latest/ # https://cairocffi.readthedocs.io/en/stable/ # at startup scan email boxes of projects, and show notifications # during the runtime add/remove notifications Gtk.init(null) projects = Gtk.Stack() overview = Overview(projects) main_view = Gtk.Overlay() main_view.add(projects) main_view.add_overlay(overview.container) # keybinding to show the overview; win = new Gtk.Window() win.add(main_view) win.set_titlebar(null) win.connect("destroy", gtk.main_quit) win.show_all() win.maximize() gtk.main()
op = EASY prop = pynk.ffi.new("int*", 0) winflags = 0 running = True flags = [ (pynk.lib.NK_WINDOW_BORDER, "Border"), (pynk.lib.NK_WINDOW_MOVABLE, "Movable"), (pynk.lib.NK_WINDOW_SCALABLE, "Scalable"), (pynk.lib.NK_WINDOW_CLOSABLE, "Scrollable"), (pynk.lib.NK_WINDOW_MINIMIZABLE, "Minimizable"), (pynk.lib.NK_WINDOW_TITLE, "Title") ] # Initialise nuklear font = pynk.nkpygame.NkPygameFont(pygame.font.SysFont("Consolas", 14)) with pynk.nkpygame.NkPygame(font) as nkpy: overview = Overview() while running: # Handle input. events = [] for e in pygame.event.get(): if e.type == pygame.QUIT: running = False else: events.append(e) nkpy.handle_events(events) # Show the demo GUI. if pynk.lib.nk_begin(nkpy.ctx, "Demo", pynk.lib.nk_rect(50, 50, 300, 300), winflags): pynk.lib.nk_layout_row_static(nkpy.ctx, 30, 80, 1) if pynk.lib.nk_button_label(nkpy.ctx, "quit"):
def on_select_game(self, filename): game = model.Game.json_loadfile(os.path.join('save', filename)) model.game = game director.push(Overview())
class DashboardApp(App): def build(self): self.root = Accordion(min_space=30) self.overviewItem = AccordionItem(title=unichr(252) + 'bersicht') self.overview = Overview() self.overviewItem.add_widget(self.overview) #self.closeButton = Button(text = 'Beenden', size=(100, 50), size_hint=(None, None), background_color=[1,0,0,1]) #self.closeButton.bind(on_press=self.closeApp) #self.overviewItem.add_widget(self.closeButton) self.root.add_widget(self.overviewItem) self.scheduleItem = AccordionItem(title='Stundenplan') self.schedule = Schedule() self.scheduleItem.add_widget(self.schedule) self.root.add_widget(self.scheduleItem) self.appointmentsItem = AccordionItem(title='Termine') self.appointments = Appointments() self.appointmentsItem.add_widget(self.appointments) self.root.add_widget(self.appointmentsItem) self.todoListItem = AccordionItem(title='Haushalts-Abenteuer') self.todoList = TodoList() self.todoListItem.add_widget(self.todoList) self.root.add_widget(self.todoListItem) self.newsItem = AccordionItem(title='Nachrichten') self.news = Feeds() self.newsItem.add_widget(self.news) self.root.add_widget(self.newsItem) self.pictureItem = AccordionItem(title='Bilder') self.pictureFrame = PictureFrame() self.pictureItem.add_widget(self.pictureFrame) self.root.add_widget(self.pictureItem) self.scheduleItem.collapse = False self.ledClock = LedMatrix() # initial weather data self.overview.updateWeather() # continuous updates EACH_SECOND = 1 ONE_MINUTE = 60 FOUR_HOURS = 14400 Clock.schedule_interval(self.__updateLedClock, EACH_SECOND) Clock.schedule_interval(self.__updateItems, ONE_MINUTE) Clock.schedule_interval(self.__updateWeather, FOUR_HOURS) return self.root def __updateWeather(self, dt): self.overview.updateWeather() def __updateLedClock(self, dt): self.ledClock.updateLedDisplay(time.strftime("%H:%M:%S")) def __updateItems(self, dt): self.overview.updateDateTime() self.news.refreshFeeds() self.pictureFrame.updateRandomPicture() self.schedule.handleScheduleDisplay() dueAppointments = self.appointments.due() if not dueAppointments: self.appointmentsItem.title = 'Termine' else: self.appointmentsItem.title = 'Termin(e) >>heute<<' self.overview.updateAppointmentTile(dueAppointments) dueReminders = self.appointments.remind() if dueReminders: self.overview.updateReminderTile(dueReminders) def closeApp(self, instance): self.stop()
from overview import Overview from interactions import Interactions from reviews import Reviews import shutil name = "ortho micronor" drugOverview = Overview("https://www.drugs.com/mtm/ortho-micronor.html", name) drugOverview.buildOverview() drugInteraction = Interactions( "https://www.drugs.com/drug-interactions/norethindrone,ortho-micronor.html", name) drugInteraction.buildInteractions() drugReviews = Reviews( "https://www.drugs.com/comments/norethindrone/ortho-micronor.html", name) drugReviews.buildReviews() shutil.move(name + '.txt', 'minipills')
def on_continue_game(self): # play the last modified game name = list_saves()[-1][0] game = model.Game.json_loadfile(os.path.join('save', name)) model.game = game director.push(Overview())